From e211604368a73312240a4972301e564c6d87f605 Mon Sep 17 00:00:00 2001 From: yuqing Date: Sat, 9 Aug 2014 11:15:55 +0800 Subject: [PATCH] support OS Darwin --- make.sh | 11 +++++++---- src/sockopt.c | 20 +++++++++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/make.sh b/make.sh index 54ae3fe..f06c755 100755 --- a/make.sh +++ b/make.sh @@ -5,8 +5,8 @@ cat < $tmp_src_filename #include int main() { - printf("%d\n", sizeof(long)); - printf("%d\n", sizeof(off_t)); + printf("%d\n", (int)sizeof(long)); + printf("%d\n", (int)sizeof(off_t)); return 0; } EOF @@ -69,8 +69,11 @@ LIBS='' uname=`uname` if [ "$uname" = "Linux" ]; then CFLAGS="$CFLAGS -DOS_LINUX -DIOEVENT_USE_EPOLL" -elif [ "$uname" = "FreeBSD"] || [ "$uname" = "Darwin"]; then +elif [ "$uname" = "FreeBSD" ] || [ "$uname" = "Darwin" ]; then CFLAGS="$CFLAGS -DOS_FREEBSD -DIOEVENT_USE_KQUEUE" + if [ "$uname" = "Darwin" ]; then + CFLAGS="$CFLAGS -DDARWIN" + fi elif [ "$uname" = "SunOS" ]; then CFLAGS="$CFLAGS -DOS_SUNOS -D_THREAD_SAFE -DIOEVENT_USE_PORT" LIBS="$LIBS -lsocket -lnsl -lresolv" @@ -84,7 +87,7 @@ fi if [ -f /usr/lib/libpthread.so ] || [ -f /usr/local/lib/libpthread.so ] || [ -f /usr/lib64/libpthread.so ] || [ -f /usr/lib/libpthread.a ] || [ -f /usr/local/lib/libpthread.a ] || [ -f /usr/lib64/libpthread.a ]; then LIBS="$LIBS -lpthread" -else +elif [ -f /usr/lib/libc_r.so ]; then line=`nm -D /usr/lib/libc_r.so | grep pthread_create | grep -w T` if [ -n "$line" ]; then LIBS="$LIBS -lc_r" diff --git a/src/sockopt.c b/src/sockopt.c index f0dea6c..3f4aece 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -1109,6 +1109,9 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ off_t offset; #ifdef OS_LINUX int64_t remain_bytes; + #elif defined(DARWIN) + int64_t remain_bytes; + off_t len; #endif #endif #else @@ -1183,7 +1186,21 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ #else #ifdef OS_FREEBSD offset = file_offset; - if (sendfile(fd, sock, offset, file_bytes, NULL, NULL, 0) != 0) +#if defined(DARWIN) + result = 0; + remain_bytes = file_bytes; + while (remain_bytes > 0) + { + len = remain_bytes; + if (sendfile(fd, sock, offset, &len, NULL, 0) != 0) { + result = errno != 0 ? errno : EIO; + break; + } + remain_bytes -= len; + } + *total_send_bytes = file_bytes - remain_bytes; +#else + if (sendfile(fd, sock, offset, file_offset, NULL, NULL, 0) != 0) { *total_send_bytes = 0; result = errno != 0 ? errno : EIO; @@ -1194,6 +1211,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \ result = 0; } #endif +#endif #endif if (flags & O_NONBLOCK) //restore