Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to libuv 1.15.0 #91

Merged
merged 3 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/\.dll$
^\.travis\.yml$
^appveyor\.yml$
^src/libuv/.github$
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: httpuv
Type: Package
Title: HTTP and WebSocket Server Library
Version: 1.3.5.9001
Version: 1.3.5.9002
Author: Joe Cheng, Hector Corrada Bravo [ctb], Jeroen Ooms [ctb],
Winston Chang [ctb]
Copyright: RStudio, Inc.; Joyent, Inc.; Nginx Inc.; Igor Sysoev; Niels Provos;
Expand Down
45 changes: 41 additions & 4 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,32 @@ libraries used by httpuv. All other code in httpuv is copyright RStudio, Inc.



libuv is part of the Node project: http://nodejs.org/
libuv may be distributed alone under Node's license:
libuv is licensed for use as follows:

====
Copyright (c) 2015-present libuv project contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
====

This license applies to parts of libuv originating from the
https://github.com/joyent/libuv repository:

====

Expand All @@ -23,6 +47,14 @@ furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.

====

This license applies to all parts of libuv that are not externally
Expand All @@ -32,15 +64,20 @@ The externally maintained libraries used by libuv are:

- tree.h (from FreeBSD), copyright Niels Provos. Two clause BSD license.

- ngx_queue.h (from Nginx), copyright Igor Sysoev. Two clause BSD license.

- inet_pton and inet_ntop implementations, contained in src/inet.c, are
copyright the Internet Systems Consortium, Inc., and licensed under the ISC
license.

- stdint-msvc2008.h (from msinttypes), copyright Alexander Chemeris. Three
clause BSD license.

- pthread-fixes.c, copyright Google Inc. and Sony Mobile Communications AB.
Three clause BSD license.

- android-ifaddrs.h, android-ifaddrs.c, copyright Berkeley Software Design
Inc, Kenneth MacKay and Emergya (Cloud4all, FP7/2007-2013, grant agreement
n° 289016). Three clause BSD license.




Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
httpuv 1.3.5.9001
httpuv 1.3.5.9002
=================

* Upgraded to libuv 1.15.0. ([#91](https://github.com/rstudio/httpuv/pull/91))

* httpuv can now handle request callbacks asynchronously. ([#80](https://github.com/rstudio/httpuv/pull/80))

* Let Rcpp handle symbol registration. ([#85](https://github.com/rstudio/httpuv/pull/85))
Expand Down
12 changes: 7 additions & 5 deletions src/Makevars
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ifeq ($(UNAME), Darwin)
FRAMEWORK = -framework CoreServices
endif

PKG_LIBS = ./libuv/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o $(FRAMEWORK)
PKG_LIBS = ./libuv/.libs/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o $(FRAMEWORK)
ifeq ($(UNAME), SunOS)
PKG_LIBS += -lkstat -lsendfile -lsocket
endif
Expand All @@ -22,10 +22,12 @@ endif

PKG_CPPFLAGS = -I./libuv/include -I./http-parser -I./sha1 -I./base64 $(C_VISIBILITY)

$(SHLIB): libuv/libuv.a http-parser/http_parser.o sha1/sha1.o base64/base64.o
$(SHLIB): libuv/.libs/libuv.a http-parser/http_parser.o sha1/sha1.o base64/base64.o

libuv/libuv.a:
libuv/Makefile:
(cd libuv && sh autogen.sh && ./configure)

libuv/.libs/libuv.a: libuv/Makefile
$(MAKE) --directory=libuv \
CC="$(CC)" CFLAGS="$(CFLAGS) $(CPICFLAGS) $(C_VISIBILITY)" AR="$(AR)" RANLIB="$(RANLIB)" \
HAVE_DTRACE=0 \
libuv.a
HAVE_DTRACE=0
24 changes: 7 additions & 17 deletions src/Makevars.win
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
# Use C++11 if available
CXX_STD=CXX11

## Use the R_HOME indirection to support installations of multiple R version
PKG_LIBS = ./libuv/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o -lWs2_32 -lkernel32 -lpsapi -liphlpapi
PKG_LIBS = ./libuv/libuv.a ./http-parser/http_parser.o ./sha1/sha1.o ./base64/base64.o \
-lpthread -lws2_32 -lkernel32 -lpsapi -liphlpapi -lshell32 -luserenv

PKG_CPPFLAGS += -I./libuv/include -I./http-parser -I./sha1 -I./base64 -D_WIN32_WINNT=0x0600
CFLAGS += -D_WIN32_WINNT=0x0600

.PHONY: all libuv/libuv.a http-parser/http_parser.o
# Additional flags for libuv borrowed from libuv/Makefile.mingw
LIBUV_CFLAGS = -Iinclude -Isrc -Isrc/win -DWIN32_LEAN_AND_MEAN

all: $(SHLIB) libuv/libuv.a http-parser/http_parser.o sha1/sha1.o base64/base64.o
$(SHLIB): libuv/libuv.a http-parser/http_parser.o sha1/sha1.o base64/base64.o

libuv/libuv.a:
make --directory=libuv \
CC="$(CC)" AR="$(AR)" RANLIB="$(RANLIB)" SRCDIR=. PLATFORM=mingw libuv.a

http-parser/http_parser.o:
make --directory=http-parser \
CC="$(CC)" CFLAGS="$(ALL_CFLAGS)" \
SRCDIR=. http_parser.o

sha1/sha1.o: sha1/sha1.c sha1/sha1.h
(cd sha1 && $(CC) $(CFLAGS) $(CPICFLAGS) -c sha1.c -o sha1.o)

base64/base64.o: base64/base64.cpp base64/base64.hpp
(cd base64 && $(CXX) $(ALL_CPPFLAGS) $(ALL_CXXFLAGS) -c base64.cpp -o base64.o)
$(MAKE) --directory=libuv -f Makefile.mingw \
CC="$(CC)" CFLAGS="$(CFLAGS) $(LIBUV_CFLAGS) $(CPICFLAGS) $(C_VISIBILITY)" \
AR="$(AR)" RANLIB="$(RANLIB)" HAVE_DTRACE=0
44 changes: 22 additions & 22 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,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 @@ -303,15 +303,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 @@ -348,28 +348,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 @@ -441,8 +439,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 @@ -489,7 +486,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 @@ -525,9 +522,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 @@ -540,8 +536,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 @@ -600,8 +595,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 @@ -154,12 +154,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 @@ -201,7 +201,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 @@ -389,7 +389,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 @@ -403,7 +403,7 @@ bool run(int 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 @@ -412,7 +412,7 @@ bool run(int 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
10 changes: 10 additions & 0 deletions src/libuv/.github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
If you want to report a bug, you are in the right place!

If you need help or have a question, go here:
https://github.com/libuv/help/issues/new

Please include code that demonstrates the bug and keep it short and simple.
-->
* **Version**: <!-- libuv version -->
* **Platform**: <!-- `uname -a` (UNIX), or Windows version and machine type -->
Loading