support OS Darwin
parent
386a5eb485
commit
e211604368
11
make.sh
11
make.sh
|
|
@ -5,8 +5,8 @@ cat <<EOF > $tmp_src_filename
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
printf("%d\n", sizeof(long));
|
printf("%d\n", (int)sizeof(long));
|
||||||
printf("%d\n", sizeof(off_t));
|
printf("%d\n", (int)sizeof(off_t));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
@ -69,8 +69,11 @@ LIBS=''
|
||||||
uname=`uname`
|
uname=`uname`
|
||||||
if [ "$uname" = "Linux" ]; then
|
if [ "$uname" = "Linux" ]; then
|
||||||
CFLAGS="$CFLAGS -DOS_LINUX -DIOEVENT_USE_EPOLL"
|
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"
|
CFLAGS="$CFLAGS -DOS_FREEBSD -DIOEVENT_USE_KQUEUE"
|
||||||
|
if [ "$uname" = "Darwin" ]; then
|
||||||
|
CFLAGS="$CFLAGS -DDARWIN"
|
||||||
|
fi
|
||||||
elif [ "$uname" = "SunOS" ]; then
|
elif [ "$uname" = "SunOS" ]; then
|
||||||
CFLAGS="$CFLAGS -DOS_SUNOS -D_THREAD_SAFE -DIOEVENT_USE_PORT"
|
CFLAGS="$CFLAGS -DOS_SUNOS -D_THREAD_SAFE -DIOEVENT_USE_PORT"
|
||||||
LIBS="$LIBS -lsocket -lnsl -lresolv"
|
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
|
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"
|
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`
|
line=`nm -D /usr/lib/libc_r.so | grep pthread_create | grep -w T`
|
||||||
if [ -n "$line" ]; then
|
if [ -n "$line" ]; then
|
||||||
LIBS="$LIBS -lc_r"
|
LIBS="$LIBS -lc_r"
|
||||||
|
|
|
||||||
|
|
@ -1109,6 +1109,9 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \
|
||||||
off_t offset;
|
off_t offset;
|
||||||
#ifdef OS_LINUX
|
#ifdef OS_LINUX
|
||||||
int64_t remain_bytes;
|
int64_t remain_bytes;
|
||||||
|
#elif defined(DARWIN)
|
||||||
|
int64_t remain_bytes;
|
||||||
|
off_t len;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
|
@ -1183,7 +1186,21 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \
|
||||||
#else
|
#else
|
||||||
#ifdef OS_FREEBSD
|
#ifdef OS_FREEBSD
|
||||||
offset = file_offset;
|
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;
|
*total_send_bytes = 0;
|
||||||
result = errno != 0 ? errno : EIO;
|
result = errno != 0 ? errno : EIO;
|
||||||
|
|
@ -1194,6 +1211,7 @@ int tcpsendfile_ex(int sock, const char *filename, const int64_t file_offset, \
|
||||||
result = 0;
|
result = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (flags & O_NONBLOCK) //restore
|
if (flags & O_NONBLOCK) //restore
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue