1 /* Simulates MSG_DONTWAIT using fcntl() and O_NONBLOCK. */
3 static void fd_modify(int fd
, int flags
, int add
, int shouldRemove
)
7 if (flags
& MSG_DONTWAIT
) {
9 int f
= fcntl(fd
, F_GETFL
);
10 fcntl(fd
, F_SETFL
, (f
| add
) & ~shouldRemove
);
15 static void set_nonblock(int fd
, int flags
)
17 fd_modify(fd
, flags
, O_NONBLOCK
, 0);
20 static void clear_nonblock(int fd
, int flags
)
22 fd_modify(fd
, flags
, 0, O_NONBLOCK
);
25 int MLton_recv(int s
, void *buf
, int len
, int flags
)
28 set_nonblock(s
, flags
);
29 ret
= recv(s
, buf
, len
, flags
& ~MSG_DONTWAIT
);
30 clear_nonblock(s
, flags
);
34 int MLton_recvfrom(int s
, void *buf
, int len
, int flags
, void *from
,
38 set_nonblock(s
, flags
);
39 ret
= recvfrom(s
, buf
, len
, flags
& ~MSG_DONTWAIT
, from
, fromlen
);
40 clear_nonblock(s
, flags
);