diff --git a/Makefile b/Makefile index 5b1e78ae..e035068f 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ CXXFLAGS = -std=gnu++0x -g -O0 -I$(LIBUV_PATH)/include -I$(HTTP_PARSER_PATH) -I. -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 OS_NAME=$(shell uname -s) -ifeq (${OS_NAME},Darwin) - RTLIB= +ifeq (MINGW,$(findstring MINGW,$(OS_NAME))) + RTLIB=-lws2_32 -lpsapi -liphlpapi else - RTLIB=-lrt + ifeq (Darwin,$(findstring Darwin,$(OS_NAME))) + RTLIB= + else + RTLIB=-lrt + endif endif all: webclient webserver file_test diff --git a/native/fs.h b/native/fs.h index 62112854..b4897b83 100644 --- a/native/fs.h +++ b/native/fs.h @@ -21,8 +21,12 @@ namespace native static const int create = O_CREAT; static const int excl = O_EXCL; static const int truncate = O_TRUNC; +#ifdef O_NOFOLLOW static const int no_follow = O_NOFOLLOW; +#endif +#ifdef O_DIRECTORY static const int directory = O_DIRECTORY; +#endif #ifdef O_NOATIME static const int no_access_time = O_NOATIME; #endif diff --git a/native/stream.h b/native/stream.h index 54743919..c8ec4382 100644 --- a/native/stream.h +++ b/native/stream.h @@ -6,6 +6,12 @@ #include "handle.h" #include "callback.h" +#if defined(__unix__) || defined(__POSIX__) || defined(__APPLE__) +#define UV_BUF(base, len) {base, len} +#else +#define UV_BUF(base, len) {len, base} +#endif + namespace native { namespace base @@ -45,12 +51,12 @@ namespace native [](uv_handle_t*, size_t suggested_size){ if(!max_alloc_size) { - return uv_buf_t { new char[suggested_size], suggested_size }; + return uv_buf_t UV_BUF( new char[suggested_size], suggested_size ); } else { auto size = max_alloc_size > suggested_size ? suggested_size : max_alloc_size; - return uv_buf_t { new char[size], size }; + return uv_buf_t UV_BUF( new char[size], size ); } }, [](uv_stream_t* s, ssize_t nread, uv_buf_t buf){ @@ -76,7 +82,7 @@ namespace native bool write(const char* buf, int len, std::function callback) { - uv_buf_t bufs[] = { uv_buf_t { const_cast(buf), len } }; + uv_buf_t bufs[] = { uv_buf_t UV_BUF( const_cast(buf), len ) }; callbacks::store(get()->data, native::internal::uv_cid_write, callback); return uv_write(new uv_write_t, get(), bufs, 1, [](uv_write_t* req, int status) { callbacks::invoke(req->handle->data, native::internal::uv_cid_write, status?uv_last_error(req->handle->loop):error()); @@ -86,7 +92,7 @@ namespace native bool write(const std::string& buf, std::function callback) { - uv_buf_t bufs[] = { uv_buf_t { const_cast(buf.c_str()), buf.length()} }; + uv_buf_t bufs[] = { uv_buf_t UV_BUF( const_cast(buf.c_str()), buf.length()) }; callbacks::store(get()->data, native::internal::uv_cid_write, callback); return uv_write(new uv_write_t, get(), bufs, 1, [](uv_write_t* req, int status) { callbacks::invoke(req->handle->data, native::internal::uv_cid_write, status?uv_last_error(req->handle->loop):error()); @@ -96,7 +102,7 @@ namespace native bool write(const std::vector& buf, std::function callback) { - uv_buf_t bufs[] = { uv_buf_t { const_cast(&buf[0]), buf.size() } }; + uv_buf_t bufs[] = { uv_buf_t UV_BUF( const_cast(&buf[0]), buf.size() ) }; callbacks::store(get()->data, native::internal::uv_cid_write, callback); return uv_write(new uv_write_t, get(), bufs, 1, [](uv_write_t* req, int status) { callbacks::invoke(req->handle->data, native::internal::uv_cid_write, status?uv_last_error(req->handle->loop):error());