Skip to content
This repository has been archived by the owner on Apr 5, 2022. It is now read-only.

Commit

Permalink
Handle EMFILE type failures gracefully.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Turner committed Jul 5, 2013
1 parent e656e34 commit aafae76
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
6 changes: 6 additions & 0 deletions src/nitro.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@

nitro_socket_t *nitro_socket_bind(char *location, nitro_sockopt_t *opt) {
nitro_socket_t *s = nitro_socket_new(opt);
if (!s) {
return NULL;
}
char *next;
s->trans = socket_parse_location(location, &next);

Expand All @@ -61,6 +64,9 @@ nitro_socket_t *nitro_socket_bind(char *location, nitro_sockopt_t *opt) {

nitro_socket_t *nitro_socket_connect(char *location, nitro_sockopt_t *opt) {
nitro_socket_t *s = nitro_socket_new(opt);
if (!s) {
return NULL;
}
char *next;
s->trans = socket_parse_location(location, &next);

Expand Down
24 changes: 16 additions & 8 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,23 @@ nitro_socket_t *nitro_socket_new(nitro_sockopt_t *opt) {
#else
int pipes[2];
int r = pipe(pipes);
assert(!r);
us->event_fd = pipes[0];
us->write_pipe = pipes[1];
int flags = fcntl(us->event_fd, F_GETFL, 0);
fcntl(us->event_fd, F_SETFL, flags | O_NONBLOCK);
flags = fcntl(us->write_pipe, F_GETFL, 0);
fcntl(us->write_pipe, F_SETFL, flags | O_NONBLOCK);
if (r) {
us->event_fd = -1;
} else {
us->event_fd = pipes[0];
us->write_pipe = pipes[1];
int flags = fcntl(us->event_fd, F_GETFL, 0);
fcntl(us->event_fd, F_SETFL, flags | O_NONBLOCK);
flags = fcntl(us->write_pipe, F_GETFL, 0);
fcntl(us->write_pipe, F_SETFL, flags | O_NONBLOCK);
}
#endif
assert(us->event_fd >= 0);
if (us->event_fd < 0) {
nitro_set_error(NITRO_ERR_ERRNO);
nitro_sockopt_destroy(opt);
free(sock);
return NULL;
}
}

// XXX add socket to list for diagnostics
Expand Down

0 comments on commit aafae76

Please sign in to comment.