1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-25 09:47:17 +00:00

Check for SOCK_CLOEXEC.

Not available on all platforms.
This commit is contained in:
Calvin Rose 2020-05-06 23:44:01 -05:00
parent bdd64f5656
commit 79c3139748

View File

@ -103,10 +103,19 @@ typedef struct {
#define JPollStruct struct pollfd #define JPollStruct struct pollfd
#define JSock int #define JSock int
#define JReadInt ssize_t #define JReadInt ssize_t
#ifdef SOCK_CLOEXEC
#define JSOCKFLAGS SOCK_CLOEXEC #define JSOCKFLAGS SOCK_CLOEXEC
#else
#define JSOCKFLAGS 0
#endif
static JanetStream *make_stream(int fd, int flags) { static JanetStream *make_stream(int fd, int flags) {
JanetStream *stream = janet_abstract(&StreamAT, sizeof(JanetStream)); JanetStream *stream = janet_abstract(&StreamAT, sizeof(JanetStream));
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); #ifndef SOCK_CLOEXEC
int extra = O_CLOEXEC;
#else
int extra = 0;
#endif
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK | extra);
stream->fd = fd; stream->fd = fd;
stream->flags = flags; stream->flags = flags;
return stream; return stream;