Permalink
Browse files

Merge pull request #4 from finaldie/master

Compile error at old kernel
  • Loading branch information...
2 parents 441d276 + 668501c commit 71a1b9abef5f06b0678cdf99d1b92f0d32ebeaf4 @cloudwu committed May 13, 2012
Showing with 17 additions and 1 deletion.
  1. +17 −1 mread.c
View
18 mread.c
@@ -13,6 +13,7 @@
#include <string.h>
#include <assert.h>
#include <stdio.h>
+#include <fcntl.h>
#define BACKLOG 32
#define READQUEUE 32
@@ -80,12 +81,27 @@ _release_rb(struct ringbuffer * rb) {
ringbuffer_delete(rb);
}
+static int
+_set_nonblocking(int fd)
+{
+ int flag = fcntl(fd, F_GETFL, 0);
+ if ( -1 == flag ) {
+ return -1;
+ }
+
+ return fcntl(fd, F_SETFL, flag | O_NONBLOCK);
+}
+
struct mread_pool *
mread_create(int port , int max , int buffer_size) {
- int listen_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
+ int listen_fd = socket(AF_INET, SOCK_STREAM, 0);
if (listen_fd == -1) {
return NULL;
}
+ if ( -1 == _set_nonblocking(listen_fd) ) {
+ return NULL;
+ }
+
int reuse = 1;
setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(int));

0 comments on commit 71a1b9a

Please sign in to comment.