Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/lib/libsockfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ addToLibrary({
}
{{{ makeSetValue('arg', '0', 'bytes', 'i32') }}};
return 0;
case {{{ cDefs.FIONBIO }}}:
var on = {{{ makeGetValue('arg', '0', 'i32') }}};
if (on) {
sock.stream.flags |= {{{ cDefs.O_NONBLOCK }}};
} else {
sock.stream.flags &= ~{{{ cDefs.O_NONBLOCK }}};
}
return 0;
default:
return {{{ cDefs.EINVAL }}};
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/libsyscall.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ var SyscallsLibrary = {
if (!stream.tty) return -{{{ cDefs.ENOTTY }}};
return -{{{ cDefs.EINVAL }}}; // not supported
}
case {{{ cDefs.FIONBIO }}}:
case {{{ cDefs.FIONREAD }}}: {
var argp = syscallGetVarargP();
return FS.ioctl(stream, op, argp);
Expand Down
1 change: 1 addition & 0 deletions src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@
{
"file": "bits/ioctl.h",
"defines": [
"FIONBIO",
"FIONREAD",
"TCGETA",
"TCGETS",
Expand Down
1 change: 1 addition & 0 deletions src/struct_info_generated.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
"EWOULDBLOCK": 6,
"EXDEV": 75,
"EXFULL": 115,
"FIONBIO": 21537,
"FIONREAD": 21531,
"F_DUPFD": 0,
"F_GETFD": 1,
Expand Down
1 change: 1 addition & 0 deletions src/struct_info_generated_wasm64.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@
"EWOULDBLOCK": 6,
"EXDEV": 75,
"EXFULL": 115,
"FIONBIO": 21537,
"FIONREAD": 21531,
"F_DUPFD": 0,
"F_GETFD": 1,
Expand Down
27 changes: 18 additions & 9 deletions test/sockets/test_sockets_echo_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ typedef int socklen_t;
#include <emscripten.h>
#endif

#ifdef _WIN32
typedef u_long ioctlarg_t;
#else
#define INVALID_SOCKET -1
#define SOCKET_ERROR -1
#define ioctlsocket ioctl
typedef int ioctlarg_t;
#endif

#include "test_sockets_msg.h"

typedef enum {
Expand Down Expand Up @@ -193,16 +202,16 @@ int main() {
#else
server.fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
#endif
if (server.fd == -1) {
if (server.fd == INVALID_SOCKET) {
perror("cannot create socket");
exit(EXIT_FAILURE);
}
#ifdef _WIN32
unsigned long nonblocking = 1;
ioctlsocket(server.fd, FIONBIO, &nonblocking);
#else
fcntl(server.fd, F_SETFL, O_NONBLOCK);
#endif

ioctlarg_t on = 1;
if (ioctlsocket(server.fd, FIONBIO, &on) == SOCKET_ERROR) {
perror("ioctlsocket failed");
exit(EXIT_FAILURE);
}

memset(&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
Expand All @@ -213,14 +222,14 @@ int main() {
}

res = bind(server.fd, (struct sockaddr *)&addr, sizeof(addr));
if (res == -1) {
if (res == SOCKET_ERROR) {
perror("bind failed");
exit(EXIT_FAILURE);
}

#if !TEST_DGRAM
res = listen(server.fd, 50);
if (res == -1) {
if (res == SOCKET_ERROR) {
perror("listen failed");
exit(EXIT_FAILURE);
}
Expand Down