Skip to content

Commit

Permalink
Upgrade to libuv 1.8.0
Browse files Browse the repository at this point in the history
Had to resolve numerous non-backwards-compatible changes to libuv API:
http://docs.libuv.org/en/v1.x/migration_010_100.html
  • Loading branch information
jcheng5 committed Feb 8, 2016
1 parent 6aeca57 commit 5a4ba77
Show file tree
Hide file tree
Showing 332 changed files with 36,984 additions and 10,596 deletions.
6 changes: 3 additions & 3 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ifeq ($(UNAME), Darwin)
FRAMEWORK = -framework CoreServices
endif

PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` ./libuv/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o $(FRAMEWORK)
PKG_LIBS = `$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"` ./libuv/.libs/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o $(FRAMEWORK)
ifeq ($(UNAME), SunOS)
PKG_LIBS += -lkstat -lsendfile
endif
Expand All @@ -24,10 +24,10 @@ all: $(SHLIB)
$(SHLIB): libuv.a http-parser.o sha1.o base64.o

libuv.a:
(cd libuv && sh autogen.sh && ./configure)
$(MAKE) --directory=libuv \
CC="$(CC)" CFLAGS="$(CFLAGS) $(CPICFLAGS)" AR="$(AR)" RANLIB="$(RANLIB)" \
HAVE_DTRACE=0 \
libuv.a
HAVE_DTRACE=0

http-parser.o:
$(MAKE) --directory=http-parser \
Expand Down
44 changes: 22 additions & 22 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ void on_response_written(uv_write_t* handle, int status) {
pResponse->onResponseWritten(status);
}

uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
void on_alloc(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) {
// Freed in HttpRequest::_on_request_read
void* result = malloc(suggested_size);
return uv_buf_init((char*)result, suggested_size);
*buf = uv_buf_init((char*)result, suggested_size);
}

void HttpRequest::trace(const std::string& msg) {
Expand Down Expand Up @@ -296,15 +296,15 @@ void HttpRequest::close() {
uv_close(toHandle(&_handle.stream), HttpRequest_on_closed);
}

void HttpRequest::_on_request_read(uv_stream_t*, ssize_t nread, uv_buf_t buf) {
void HttpRequest::_on_request_read(uv_stream_t*, ssize_t nread, const uv_buf_t* buf) {
if (nread > 0) {
//std::cerr << nread << " bytes read\n";
if (_ignoreNewData) {
// Do nothing
} else if (_protocol == HTTP) {
int parsed = http_parser_execute(&_parser, &request_settings(), buf.base, nread);
int parsed = http_parser_execute(&_parser, &request_settings(), buf->base, nread);
if (_parser.upgrade) {
char* pData = buf.base + parsed;
char* pData = buf->base + parsed;
size_t pDataLen = nread - parsed;

if (_pWebSocketConnection->accept(_headers, pData, pDataLen)) {
Expand Down Expand Up @@ -341,28 +341,26 @@ void HttpRequest::_on_request_read(uv_stream_t*, ssize_t nread, uv_buf_t buf) {
}
}
} else if (_protocol == WebSockets) {
_pWebSocketConnection->read(buf.base, nread);
_pWebSocketConnection->read(buf->base, nread);
}
} else if (nread < 0) {
uv_err_t err = uv_last_error(_pLoop);
if (err.code == UV_EOF /*|| err.code == UV_ECONNRESET*/) {
if (nread == UV_EOF /*|| err.code == UV_ECONNRESET*/) {
} else {
fatal_error("on_request_read", uv_strerror(err));
fatal_error("on_request_read", uv_strerror(nread));
}
close();
} else {
// It's normal for nread == 0, it's when uv requests a buffer then
// decides it doesn't need it after all
}

free(buf.base);
free(buf->base);
}

void HttpRequest::handleRequest() {
int r = uv_read_start(handle(), &on_alloc, &HttpRequest_on_request_read);
if (r) {
uv_err_t err = uv_last_error(_pLoop);
fatal_error("read_start", uv_strerror(err));
fatal_error("read_start", uv_strerror(r));
return;
}
}
Expand Down Expand Up @@ -434,8 +432,7 @@ void HttpResponse::writeResponse() {
int r = uv_write(pWriteReq, _pRequest->handle(), &headerBuf, 1,
&on_response_written);
if (r) {
_pRequest->fatal_error("uv_write",
uv_strerror(uv_last_error(_pRequest->handle()->loop)));
_pRequest->fatal_error("uv_write", uv_strerror(r));
delete this;
free(pWriteReq);
}
Expand Down Expand Up @@ -482,7 +479,7 @@ IMPLEMENT_CALLBACK_1(HttpRequest, on_headers_complete, int, http_parser*)
IMPLEMENT_CALLBACK_3(HttpRequest, on_body, int, http_parser*, const char*, size_t)
IMPLEMENT_CALLBACK_1(HttpRequest, on_message_complete, int, http_parser*)
IMPLEMENT_CALLBACK_1(HttpRequest, on_closed, void, uv_handle_t*)
IMPLEMENT_CALLBACK_3(HttpRequest, on_request_read, void, uv_stream_t*, ssize_t, uv_buf_t)
IMPLEMENT_CALLBACK_3(HttpRequest, on_request_read, void, uv_stream_t*, ssize_t, const uv_buf_t*)

void on_Socket_close(uv_handle_t* pHandle);

Expand Down Expand Up @@ -518,9 +515,8 @@ void on_Socket_close(uv_handle_t* pHandle) {
}

void on_request(uv_stream_t* handle, int status) {
if (status == -1) {
uv_err_t err = uv_last_error(handle->loop);
REprintf("connection error: %s\n", uv_strerror(err));
if (status) {
REprintf("connection error: %s\n", uv_strerror(status));
return;
}

Expand All @@ -533,8 +529,7 @@ void on_request(uv_stream_t* handle, int status) {

int r = uv_accept(handle, req->handle());
if (r) {
uv_err_t err = uv_last_error(handle->loop);
REprintf("accept: %s\n", uv_strerror(err));
REprintf("accept: %s\n", uv_strerror(r));
delete req;
return;
}
Expand Down Expand Up @@ -593,8 +588,13 @@ uv_stream_t* createTcpServer(uv_loop_t* pLoop, const std::string& host,
pSocket->handle.stream.data = pSocket;
pSocket->pWebApplication = pWebApplication;

struct sockaddr_in address = uv_ip4_addr(host.c_str(), port);
int r = uv_tcp_bind(&pSocket->handle.tcp, address);
struct sockaddr_in address = {0};
int r = uv_ip4_addr(host.c_str(), port, &address);
if (r) {
pSocket->destroy();
return NULL;
}
r = uv_tcp_bind(&pSocket->handle.tcp, (sockaddr*)&address, 0);
if (r) {
pSocket->destroy();
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions src/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ class HttpRequest : WebSocketConnectionCallbacks {
void fatal_error(const char* method, const char* message);
void _on_closed(uv_handle_t* handle);
void close();
void _on_request_read(uv_stream_t*, ssize_t nread, uv_buf_t buf);
void _on_request_read(uv_stream_t*, ssize_t nread, const uv_buf_t* buf);
void _on_response_write(int status);

};

struct HttpResponse {
class HttpResponse {

HttpRequest* _pRequest;
int _statusCode;
Expand Down Expand Up @@ -202,7 +202,7 @@ DECLARE_CALLBACK_1(HttpRequest, on_headers_complete, int, http_parser*)
DECLARE_CALLBACK_3(HttpRequest, on_body, int, http_parser*, const char*, size_t)
DECLARE_CALLBACK_1(HttpRequest, on_message_complete, int, http_parser*)
DECLARE_CALLBACK_1(HttpRequest, on_closed, void, uv_handle_t*)
DECLARE_CALLBACK_3(HttpRequest, on_request_read, void, uv_stream_t*, ssize_t, uv_buf_t)
DECLARE_CALLBACK_3(HttpRequest, on_request_read, void, uv_stream_t*, ssize_t, const uv_buf_t*)
DECLARE_CALLBACK_2(HttpRequest, on_response_write, void, uv_write_t*, int)

uv_stream_t* createPipeServer(uv_loop_t* loop, const std::string& name,
Expand Down
6 changes: 3 additions & 3 deletions src/httpuv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ void destroyServer(std::string handle) {
void dummy_close_cb(uv_handle_t* handle) {
}

void stop_loop_timer_cb(uv_timer_t* handle, int status) {
void stop_loop_timer_cb(uv_timer_t* handle) {
uv_stop(handle->loop);
}

Expand All @@ -386,7 +386,7 @@ bool run(uint32_t timeoutMillis) {
if (!timer_req.loop) {
r = uv_timer_init(uv_default_loop(), &timer_req);
if (r) {
throwLastError(uv_default_loop(),
throwError(r,
"Failed to initialize libuv timeout timer: ");
}
}
Expand All @@ -395,7 +395,7 @@ bool run(uint32_t timeoutMillis) {
uv_timer_stop(&timer_req);
r = uv_timer_start(&timer_req, &stop_loop_timer_cb, timeoutMillis, 0);
if (r) {
throwLastError(uv_default_loop(),
throwError(r,
"Failed to start libuv timeout timer: ");
}
}
Expand Down
58 changes: 48 additions & 10 deletions src/libuv/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,56 @@
*.l[oa]
*.opensdf
*.orig
*.pyc
*.sdf
*.suo
core
vgcore.*
.buildstamp

/libuv.so
.dirstamp
.deps/
/.libs/
/aclocal.m4
/ar-lib
/autom4te.cache/
/compile
/config.guess
/config.log
/config.status
/config.sub
/configure
/depcomp
/install-sh
/libtool
/libuv.a
/libuv.dylib
/libuv.pc
/libuv.so
/ltmain.sh
/missing
/test-driver
Makefile
Makefile.in

# Generated by dtrace(1) when doing an in-tree build.
/src/unix/uv-dtrace.h
# Generated by gyp for android
*.target.mk

/out/
/build/gyp

/run-tests
/run-tests.exe
/run-tests.dSYM
/run-benchmarks
/run-benchmarks.exe
/run-benchmarks.dSYM
/test/.libs/
/test/run-tests
/test/run-tests.exe
/test/run-tests.dSYM
/test/run-benchmarks
/test/run-benchmarks.exe
/test/run-benchmarks.dSYM

*.sln
*.sln.cache
*.ncb
*.vcproj
*.vcproj*.user
*.vcxproj
*.vcxproj.filters
*.vcxproj.user
Expand All @@ -35,3 +61,15 @@ UpgradeLog*.XML
Debug
Release
ipch

# sphinx generated files
/docs/build/

# Clion / IntelliJ project files
/.idea/

*.xcodeproj
*.xcworkspace

# make dist output
libuv-*.tar.*
22 changes: 22 additions & 0 deletions src/libuv/.mailmap
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
Aaron Bieber <[email protected]> <[email protected]>
Alan Gutierrez <[email protected]> <[email protected]>
Andrius Bentkus <[email protected]> <[email protected]>
Bert Belder <[email protected]> <[email protected]>
Bert Belder <[email protected]> <user@ChrUbuntu.(none)>
Brandon Philips <[email protected]> <[email protected]>
Brian White <[email protected]>
Brian White <[email protected]> <[email protected]>
Caleb James DeLisle <[email protected]> <[email protected]>
Christoph Iserlohn <[email protected]>
Devchandra Meetei Leishangthem <[email protected]>
Fedor Indutny <[email protected]> <[email protected]>
Frank Denis <[email protected]>
Isaac Z. Schlueter <[email protected]>
Jason Williams <[email protected]>
Justin Venus <[email protected]> <[email protected]>
Keno Fischer <[email protected]> <[email protected]>
Keno Fischer <[email protected]> <[email protected]>
Leith Bade <[email protected]> <[email protected]>
Leonard Hecker <[email protected]> <[email protected]>
Maciej Małecki <[email protected]> <[email protected]>
Marc Schlaich <[email protected]> <[email protected]>
Michael <[email protected]>
Michael Neumann <[email protected]> <[email protected]>
Nicholas Vavilov <[email protected]>
Rasmus Christian Pedersen <[email protected]>
Rasmus Christian Pedersen <[email protected]> <[email protected]>
Robert Mustacchi <[email protected]> <[email protected]>
Ryan Dahl <[email protected]> <[email protected]>
Ryan Emery <[email protected]>
Sam Roberts <[email protected]> <[email protected]>
San-Tai Hsu <[email protected]>
Santiago Gimeno <[email protected]> <[email protected]>
Saúl Ibarra Corretgé <[email protected]>
Shigeki Ohtsu <[email protected]> <[email protected]>
Timothy J. Fontaine <[email protected]>
Yasuhiro Matsumoto <[email protected]>
Yazhong Liu <[email protected]>
Yuki Okumura <[email protected]>
Loading

0 comments on commit 5a4ba77

Please sign in to comment.