Skip to content

Commit

Permalink
Address review.
Browse files Browse the repository at this point in the history
  • Loading branch information
juj committed Sep 27, 2024
1 parent 3f02d35 commit 6fbbb76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@

int sock;

EM_BOOL wait_for_recv(double, void *) {
EM_BOOL wait_for_recv(double d, void *u) {
// Poll read from the socket to see what we have received
char buf[1024] = {};
recv(sock, buf, sizeof(buf)-1, 0);
if (strlen(buf) > 0)
{
if (strlen(buf) > 0) {
printf("%s\n", buf);
if (!strcmp(buf, "Hello"))
{
if (!strcmp(buf, "Hello")) {
printf("Got hello, test finished.\n");
#ifdef REPORT_RESULT
REPORT_RESULT(0);
Expand All @@ -30,31 +28,28 @@ EM_BOOL wait_for_recv(double, void *) {

int main() {
// Connect socket to a WebSocket echo server
sockaddr_in addr = {
struct sockaddr_in addr = {
.sin_family = AF_INET,
.sin_port = htons(8089)
};
inet_pton(AF_INET, "127.0.0.1", &addr.sin_addr);
sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sock < 0)
{
if (sock < 0) {
printf("socket() failed to error %d\n", sock);
return sock;
}

// Connect to echo server.
int error = connect(sock, (sockaddr*)&addr, sizeof(addr));
if (error)
{
int error = connect(sock, (struct sockaddr*)&addr, sizeof(addr));
if (error) {
printf("connect() failed to error %d\n", error);
return error;
}

// Immediately send a message back-to-back from connecting to the socket
const char *msg = "Hello";
ssize_t bytes = send(sock, msg, strlen(msg), 0);
if (bytes != strlen(msg))
{
if (bytes != strlen(msg)) {
printf("send() failed to send %d bytes. Return value: %d\n", (int)strlen(msg), (int)bytes);
return bytes;
}
Expand Down
6 changes: 3 additions & 3 deletions test/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ def test_posix_proxy_sockets(self):
# Build and run the TCP echo client program with Emscripten
self.btest_exit('websocket/tcp_echo_client.c', args=['-lwebsocket', '-sPROXY_POSIX_SOCKETS', '-pthread', '-sPROXY_TO_PTHREAD'])

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


class sockets64(sockets):
Expand Down

0 comments on commit 6fbbb76

Please sign in to comment.