Skip to content

Commit

Permalink
Merge pull request #45 from truongminh/master
Browse files Browse the repository at this point in the history
add FCNTL_NONBLOCK macro
  • Loading branch information
Rohana Rezel committed Aug 13, 2014
2 parents d3324e3 + 75d2080 commit 1d67b82
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions nope.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
idx++;\
}

#define FCNTL_ADD(s, fl) fcntl(s, F_SETFL, fcntl(s, F_GETFL, 0) | fl)
#define FCNTL_NONBLOCK(s) FCNTL_ADD(s, O_NONBLOCK)

void new_fd_data(FdData * fd)
{
fd->state = STATE_PRE_REQUEST;
Expand Down Expand Up @@ -387,12 +390,8 @@ void initialize_threads()
//con+=sizeof(pthread_t);
}
socketpair(AF_UNIX, SOCK_STREAM, 0, socketpair_fd);
if (fcntl(socketpair_fd[0], F_SETFL, fcntl(socketpair_fd[0], F_GETFL, 0) | O_NONBLOCK)
< 0)
perror("fcntl");
if (fcntl(socketpair_fd[1], F_SETFL, fcntl(socketpair_fd[1], F_GETFL, 0) | O_NONBLOCK)
< 0)
perror("fcntl");
if (FCNTL_NONBLOCK(socketpair_fd[0]) < 0) perror("fcntl");
if (FCNTL_NONBLOCK(socketpair_fd[1]) < 0) perror("fcntl");
dbgprintf("Socketpair 1 %d and 2 %d \n", socketpair_fd[0], socketpair_fd[1]);
}
#endif
Expand Down Expand Up @@ -518,7 +517,7 @@ void select_loop(int listenfd)
}

/* Make the incoming socket non-blocking and add it to the list of fds to monitor. */
if (fcntl(newfd, F_SETFL, fcntl(newfd, F_GETFL, 0) | O_NONBLOCK) < 0) {
if (FCNTL_NONBLOCK(newfd) < 0) {
perror("fcntl");
return;
}
Expand Down Expand Up @@ -836,7 +835,7 @@ int main(void)
}
}
#else /* Non-blocking if single processes */
if (fcntl(listenfd, F_SETFL, fcntl(listenfd, F_GETFL, 0) | O_NONBLOCK) < 0)
if (FCNTL_NONBLOCK(listenfd) < 0)
perror("fcntl");
#endif

Expand Down

0 comments on commit 1d67b82

Please sign in to comment.