Skip to content

Commit 6fbbb76

Browse files
committed
Address review.
1 parent 3f02d35 commit 6fbbb76

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

test/sockets/send_immediately_after_connect.cpp renamed to test/sockets/test_sockets_send_while_connecting.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@
1010

1111
int sock;
1212

13-
EM_BOOL wait_for_recv(double, void *) {
13+
EM_BOOL wait_for_recv(double d, void *u) {
1414
// Poll read from the socket to see what we have received
1515
char buf[1024] = {};
1616
recv(sock, buf, sizeof(buf)-1, 0);
17-
if (strlen(buf) > 0)
18-
{
17+
if (strlen(buf) > 0) {
1918
printf("%s\n", buf);
20-
if (!strcmp(buf, "Hello"))
21-
{
19+
if (!strcmp(buf, "Hello")) {
2220
printf("Got hello, test finished.\n");
2321
#ifdef REPORT_RESULT
2422
REPORT_RESULT(0);
@@ -30,31 +28,28 @@ EM_BOOL wait_for_recv(double, void *) {
3028

3129
int main() {
3230
// Connect socket to a WebSocket echo server
33-
sockaddr_in addr = {
31+
struct sockaddr_in addr = {
3432
.sin_family = AF_INET,
3533
.sin_port = htons(8089)
3634
};
3735
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
3836
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
39-
if (sock < 0)
40-
{
37+
if (sock < 0) {
4138
printf("socket() failed to error %d\n", sock);
4239
return sock;
4340
}
4441

4542
// Connect to echo server.
46-
int error = connect(sock, (sockaddr*)&addr, sizeof(addr));
47-
if (error)
48-
{
43+
int error = connect(sock, (struct sockaddr*)&addr, sizeof(addr));
44+
if (error) {
4945
printf("connect() failed to error %d\n", error);
5046
return error;
5147
}
5248

5349
// Immediately send a message back-to-back from connecting to the socket
5450
const char *msg = "Hello";
5551
ssize_t bytes = send(sock, msg, strlen(msg), 0);
56-
if (bytes != strlen(msg))
57-
{
52+
if (bytes != strlen(msg)) {
5853
printf("send() failed to send %d bytes. Return value: %d\n", (int)strlen(msg), (int)bytes);
5954
return bytes;
6055
}

test/test_sockets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,10 @@ def test_posix_proxy_sockets(self):
350350
# Build and run the TCP echo client program with Emscripten
351351
self.btest_exit('websocket/tcp_echo_client.c', args=['-lwebsocket', '-sPROXY_POSIX_SOCKETS', '-pthread', '-sPROXY_TO_PTHREAD'])
352352

353-
# Test that multiple pthreads calling send() on the same socket produces correct ordering semantics.
354-
def test_sockets_send_immediately_after_connect(self):
353+
# Test that calling send() right after a socket connect() works.
354+
def test_sockets_send_while_connecting(self):
355355
with NodeJsWebSocketEchoServerProcess():
356-
self.btest('sockets/send_immediately_after_connect.cpp', args=['-DSOCKET_DEBUG'], expected='0')
356+
self.btest('sockets/test_sockets_send_while_connecting.c', args=['-DSOCKET_DEBUG'], expected='0')
357357

358358

359359
class sockets64(sockets):

0 commit comments

Comments
 (0)