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

Remove BH dependency #297

Merged
merged 13 commits into from
Apr 1, 2021
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Authors@R: c(
person("Winston", "Chang", role = c("aut", "cre"), email = "[email protected]"),
person(family = "RStudio, PBC", role = "cph"),
person("Hector", "Corrada Bravo", role = "ctb"),
person("Jeroen", "Ooms", role = "ctb")
person("Jeroen", "Ooms", role = "ctb"),
person("Andrzej", "Krzemienski", role = "cph", comment = "optional.hpp")
)
Copyright: RStudio, PBC; Joyent, Inc.; Nginx Inc.; Igor Sysoev; Niels Provos;
Internet Systems Consortium, Inc.; Alexander Chemeris; Berkeley Software
Expand All @@ -34,9 +35,9 @@ Imports:
R6,
promises,
later (>= 0.8.0)
LinkingTo: Rcpp, BH, later
LinkingTo: Rcpp, later
URL: https://github.com/rstudio/httpuv
SystemRequirements: GNU make
SystemRequirements: GNU make, C++11
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
Suggests:
Expand Down
36 changes: 36 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,39 @@ 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.



optional.h(pp):

Copyright (C) 2011 - 2012 Andrzej Krzemienski.

Use, modification, and distribution is subject to the Boost Software
License, Version 1.0. (See below)

The idea and interface is based on Boost.Optional library
authored by Fernando Luis Cacciola Carballal

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

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, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
httpuv 1.5.5.9000
=================

* Remove BH dependency. httpuv now requires a compiler which supports C++11. (#297)

httpuv 1.5.5
=================

Expand Down
4 changes: 2 additions & 2 deletions src/auto_deleter.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef AUTO_DELETER_HPP
#define AUTO_DELETER_HPP

#include <boost/bind.hpp>
#include <functional>
#include "callbackqueue.h"
#include "thread.h"
#include <later_api.h>
Expand Down Expand Up @@ -38,7 +38,7 @@ void auto_deleter_main(void* obj) {
template <typename T>
void auto_deleter_background(T* obj) {
if (is_main_thread()) {
background_queue->push(boost::bind(auto_deleter_background<T>, obj));
background_queue->push(std::bind(auto_deleter_background<T>, obj));

} else if (is_background_thread()) {
try {
Expand Down
6 changes: 3 additions & 3 deletions src/callback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ void invoke_callback(void* data) {
delete cb;
}

// Schedule a boost::function<void(void)> to be invoked with later().
void invoke_later(boost::function<void(void)> f, double secs) {
BoostFunctionCallback* b_fun = new BoostFunctionCallback(f);
// Schedule a std::function<void(void)> to be invoked with later().
void invoke_later(std::function<void(void)> f, double secs) {
StdFunctionCallback* b_fun = new StdFunctionCallback(f);
later::later(invoke_callback, (void*)b_fun, secs);
}
12 changes: 6 additions & 6 deletions src/callback.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CALLBACK_HPP
#define CALLBACK_HPP

#include <boost/function.hpp>
#include <functional>
#include <later_api.h>

class Callback {
Expand All @@ -15,13 +15,13 @@ class Callback {
void invoke_callback(void* data);


// Wrapper class for boost functions
class BoostFunctionCallback : public Callback {
// Wrapper class for std functions
class StdFunctionCallback : public Callback {
private:
boost::function<void (void)> fun;
std::function<void (void)> fun;

public:
BoostFunctionCallback(boost::function<void (void)> fun)
StdFunctionCallback(std::function<void (void)> fun)
: fun(fun) {
}

Expand All @@ -31,6 +31,6 @@ class BoostFunctionCallback : public Callback {

};

void invoke_later(boost::function<void(void)> f, double secs = 0);
void invoke_later(std::function<void(void)> f, double secs = 0);

#endif
6 changes: 3 additions & 3 deletions src/callbackqueue.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <functional>
#include "callbackqueue.h"
#include "tqueue.h"
#include "thread.h"
#include <boost/function.hpp>
#include "libuv/include/uv.h"


Expand All @@ -20,14 +20,14 @@ CallbackQueue::CallbackQueue(uv_loop_t* loop) {
}


void CallbackQueue::push(boost::function<void (void)> cb) {
void CallbackQueue::push(std::function<void (void)> cb) {
q.push(cb);
uv_async_send(&flush_handle);
}

void CallbackQueue::flush() {
ASSERT_BACKGROUND_THREAD()
boost::function<void (void)> cb;
std::function<void (void)> cb;

while (1) {
// Do queue operations inside this guarded scope, but we'll execute the
Expand Down
6 changes: 3 additions & 3 deletions src/callbackqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#define CALLBACKQUEUE_HPP

#include "tqueue.h"
#include <boost/function.hpp>
#include <functional>
#include "libuv/include/uv.h"

class CallbackQueue {
public:
CallbackQueue(uv_loop_t* loop);
void push(boost::function<void (void)> cb);
void push(std::function<void (void)> cb);
// Needs to be a friend to call .flush()
friend void flush_callback_queue(uv_async_t *handle);

private:
void flush();
uv_async_t flush_handle;
tqueue< boost::function<void (void)> > q;
tqueue< std::function<void (void)> > q;
};


Expand Down
29 changes: 14 additions & 15 deletions src/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
#include <algorithm>
#include <iostream>
#include <sstream>
#include <boost/shared_ptr.hpp>
#include <boost/make_shared.hpp>
#include <memory>


// TODO: Streaming response body (with chunked transfer encoding)
Expand All @@ -26,12 +25,12 @@ void on_request(uv_stream_t* handle, int status) {
}

// Copy the shared_ptr
boost::shared_ptr<Socket> pSocket(*(boost::shared_ptr<Socket>*)handle->data);
std::shared_ptr<Socket> pSocket(*(std::shared_ptr<Socket>*)handle->data);
CallbackQueue* bg_queue = pSocket->background_queue;

// Freed by HttpRequest itself when close() is called, which
// can occur on EOF, error, or when the Socket is destroyed
boost::shared_ptr<HttpRequest> req = createHttpRequest(
std::shared_ptr<HttpRequest> req = createHttpRequest(
handle->loop, pSocket->pWebApplication, pSocket, bg_queue
);

Expand All @@ -49,7 +48,7 @@ uv_stream_t* createPipeServer(
uv_loop_t* pLoop,
const std::string& name,
int mask,
boost::shared_ptr<WebApplication> pWebApplication,
std::shared_ptr<WebApplication> pWebApplication,
bool quiet,
CallbackQueue* background_queue
) {
Expand All @@ -59,7 +58,7 @@ uv_stream_t* createPipeServer(
// the future we have failure cases that stop execution before we get
// that far, we MUST delete pWebApplication ourselves.

boost::shared_ptr<Socket> pSocket = boost::make_shared<Socket>(
std::shared_ptr<Socket> pSocket = std::make_shared<Socket>(
pWebApplication, background_queue
);

Expand All @@ -68,7 +67,7 @@ uv_stream_t* createPipeServer(
pSocket->handle.isTcp = false;
// data is a pointer to the shared_ptr. This is necessary because the
// uv_stream_t.data field is a void*.
pSocket->handle.stream.data = new boost::shared_ptr<Socket>(pSocket);
pSocket->handle.stream.data = new std::shared_ptr<Socket>(pSocket);

mode_t oldMask = 0;
if (mask >= 0)
Expand Down Expand Up @@ -102,11 +101,11 @@ void createPipeServerSync(
uv_loop_t* loop,
const std::string& name,
int mask,
boost::shared_ptr<WebApplication> pWebApplication,
std::shared_ptr<WebApplication> pWebApplication,
bool quiet,
CallbackQueue* background_queue,
uv_stream_t** pServer,
boost::shared_ptr<Barrier> blocker
std::shared_ptr<Barrier> blocker
) {
ASSERT_BACKGROUND_THREAD()

Expand All @@ -120,7 +119,7 @@ uv_stream_t* createTcpServer(
uv_loop_t* pLoop,
const std::string& host,
int port,
boost::shared_ptr<WebApplication> pWebApplication,
std::shared_ptr<WebApplication> pWebApplication,
bool quiet,
CallbackQueue* background_queue
) {
Expand All @@ -130,7 +129,7 @@ uv_stream_t* createTcpServer(
// the future we have failure cases that stop execution before we get
// that far, we MUST delete pWebApplication ourselves.

boost::shared_ptr<Socket> pSocket = boost::make_shared<Socket>(
std::shared_ptr<Socket> pSocket = std::make_shared<Socket>(
pWebApplication, background_queue
);

Expand All @@ -139,7 +138,7 @@ uv_stream_t* createTcpServer(
pSocket->handle.isTcp = true;
// data is a pointer to the shared_ptr. This is necessary because the
// uv_stream_t.data field is a void*.
pSocket->handle.stream.data = new boost::shared_ptr<Socket>(pSocket);
pSocket->handle.stream.data = new std::shared_ptr<Socket>(pSocket);

int r;
// Lifetime of these needs to encompass use of pAddress in uv_tcp_bind()
Expand Down Expand Up @@ -194,11 +193,11 @@ void createTcpServerSync(
uv_loop_t* pLoop,
const std::string& host,
int port,
boost::shared_ptr<WebApplication> pWebApplication,
std::shared_ptr<WebApplication> pWebApplication,
bool quiet,
CallbackQueue* background_queue,
uv_stream_t** pServer,
boost::shared_ptr<Barrier> blocker
std::shared_ptr<Barrier> blocker
) {
ASSERT_BACKGROUND_THREAD()

Expand All @@ -212,7 +211,7 @@ void createTcpServerSync(
void freeServer(uv_stream_t* pHandle) {
ASSERT_BACKGROUND_THREAD()
// TODO: Check if server is still running?
boost::shared_ptr<Socket>* ppSocket = (boost::shared_ptr<Socket>*)pHandle->data;
std::shared_ptr<Socket>* ppSocket = (std::shared_ptr<Socket>*)pHandle->data;
(*ppSocket)->close();
// ppSocket gets deleted in a callback in close()
}
36 changes: 18 additions & 18 deletions src/http.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define HTTP_HPP

#include "libuv/include/uv.h"
#include <boost/shared_ptr.hpp>
#include <boost/bind.hpp>
#include <memory>
#include <functional>
#include "webapplication.h"
#include "websockets.h"
#include "callbackqueue.h"
Expand All @@ -30,20 +30,20 @@ struct Address {
class Socket;

uv_stream_t* createPipeServer(uv_loop_t* loop, const std::string& name, int mask,
boost::shared_ptr<WebApplication> pWebApplication);
std::shared_ptr<WebApplication> pWebApplication);

uv_stream_t* createTcpServer(uv_loop_t* loop, const std::string& host, int port,
boost::shared_ptr<WebApplication> pWebApplication);
std::shared_ptr<WebApplication> pWebApplication);

void createPipeServerSync(uv_loop_t* loop, const std::string& name, int mask,
boost::shared_ptr<WebApplication> pWebApplication, bool quiet,
std::shared_ptr<WebApplication> pWebApplication, bool quiet,
CallbackQueue* background_queue,
uv_stream_t** pServer, boost::shared_ptr<Barrier> blocker);
uv_stream_t** pServer, std::shared_ptr<Barrier> blocker);

void createTcpServerSync(uv_loop_t* loop, const std::string& host, int port,
boost::shared_ptr<WebApplication> pWebApplication, bool quiet,
std::shared_ptr<WebApplication> pWebApplication, bool quiet,
CallbackQueue* background_queue,
uv_stream_t** pServer, boost::shared_ptr<Barrier> blocker);
uv_stream_t** pServer, std::shared_ptr<Barrier> blocker);

void freeServer(uv_stream_t* pServer);
bool runNonBlocking(uv_loop_t* loop);
Expand All @@ -70,32 +70,32 @@ bool runNonBlocking(uv_loop_t* loop);
//
// The reason we need the explicit Xptr type is because we want to set the last
// argument (finalizeOnExit) to true.
inline Rcpp::XPtr<boost::shared_ptr<WebSocketConnection>,
inline Rcpp::XPtr<std::shared_ptr<WebSocketConnection>,
Rcpp::PreserveStorage,
auto_deleter_background<boost::shared_ptr<WebSocketConnection> >,
true> externalize_shared_ptr(boost::shared_ptr<WebSocketConnection> obj)
auto_deleter_background<std::shared_ptr<WebSocketConnection> >,
true> externalize_shared_ptr(std::shared_ptr<WebSocketConnection> obj)
{
ASSERT_MAIN_THREAD()
boost::shared_ptr<WebSocketConnection>* obj_copy = new boost::shared_ptr<WebSocketConnection>(obj);
std::shared_ptr<WebSocketConnection>* obj_copy = new std::shared_ptr<WebSocketConnection>(obj);

Rcpp::XPtr<boost::shared_ptr<WebSocketConnection>,
Rcpp::XPtr<std::shared_ptr<WebSocketConnection>,
Rcpp::PreserveStorage,
auto_deleter_background<boost::shared_ptr<WebSocketConnection> >,
auto_deleter_background<std::shared_ptr<WebSocketConnection> >,
true> obj_xptr(obj_copy, true);

return obj_xptr;
}

// Given an XPtr to a shared_ptr, return a copy of the shared_ptr. This
// increases the shared_ptr's ref count by one.
inline boost::shared_ptr<WebSocketConnection> internalize_shared_ptr(
Rcpp::XPtr<boost::shared_ptr<WebSocketConnection>,
inline std::shared_ptr<WebSocketConnection> internalize_shared_ptr(
Rcpp::XPtr<std::shared_ptr<WebSocketConnection>,
Rcpp::PreserveStorage,
auto_deleter_background<boost::shared_ptr<WebSocketConnection> >,
auto_deleter_background<std::shared_ptr<WebSocketConnection> >,
true> obj_xptr)
{
ASSERT_MAIN_THREAD()
boost::shared_ptr<WebSocketConnection>* obj_copy = obj_xptr.get();
std::shared_ptr<WebSocketConnection>* obj_copy = obj_xptr.get();
// Return a copy of the shared pointer.
return *obj_copy;
}
Expand Down
Loading