Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ Configure and install in the usual way:
$ make
$ sudo make install

Configuration for OS X:

$ ./configure CXXFLAGS='-DMP_UNORDERED_MAP_BOOST -DMP_FUNCTIONAL_BOOST -DMP_MEMORY_BOOST \
-O3 -Wall -I/usr/local/include -g -DCCLOG_LEVEL=10' --with-msgpack=/usr/local

OS X with C++11:

$ ./configure CXXFLAGS='-DMP_UNORDERED_MAP_BOOST -DMP_FUNCTIONAL_BOOST -DMP_MEMORY_BOOST \
-O3 -Wall -I/usr/local/include -g -DCCLOG_LEVEL=10 -std=c++11' --with-msgpack=/usr/local

## Usage

Expand Down
19 changes: 10 additions & 9 deletions src/msgpack/rpc/exception.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ void throw_exception(future_impl* f)
{
object err = f->error();

if(err.type == msgpack::type::RAW &&
err.via.raw.ptr == TIMEOUT_ERROR_PTR) {
throw timeout_error();

} else if(err.type == msgpack::type::RAW &&
err.via.raw.ptr == CONNECT_ERROR_PTR) {
throw connect_error();

} else if(err.type == msgpack::type::POSITIVE_INTEGER &&
// if(err.type == msgpack::type::RAW &&
// err.via.raw.ptr == TIMEOUT_ERROR_PTR) {
// throw timeout_error();
//
// } else if(err.type == msgpack::type::RAW &&
// err.via.raw.ptr == CONNECT_ERROR_PTR) {
// throw connect_error();
//
// } else
if(err.type == msgpack::type::POSITIVE_INTEGER &&
err.via.u64 == NO_METHOD_ERROR) {
throw no_method_error();

Expand Down
2 changes: 1 addition & 1 deletion src/msgpack/rpc/future.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ void future_impl::set_result(object result, object error, auto_zone z)
mp::pthread_scoped_lock lk(m_mutex);
m_result = result;
m_error = error;
m_zone = z;
m_zone = std::move(z);
m_session.reset();

m_cond.broadcast();
Expand Down
4 changes: 2 additions & 2 deletions src/msgpack/rpc/future.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,15 @@ template <typename T>
T future::get(auto_zone* z)
{
msgpack::object obj = get_impl();
*z = zone();
*z = std::move(zone());
return obj.as<T>();
}

template <> inline
void future::get<void>(auto_zone* z)
{
msgpack::object obj = get_impl();
*z = zone();
*z = std::move(zone());
obj.as<msgpack::type::nil>();
}

Expand Down
4 changes: 2 additions & 2 deletions src/msgpack/rpc/message_sendable.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace rpc {


typedef with_shared_zone<vrefbuffer> vreflife;
typedef std::auto_ptr<vreflife> auto_vreflife;
typedef std::unique_ptr<vreflife> auto_vreflife;


class message_sendable {
Expand All @@ -34,7 +34,7 @@ class message_sendable {
virtual ~message_sendable() { }

virtual void send_data(sbuffer* sbuf) = 0;
virtual void send_data(auto_vreflife vbuf) = 0;
virtual void send_data(auto_vreflife vbuf /**/) = 0;
};

typedef mp::shared_ptr<message_sendable> shared_message_sendable;
Expand Down
36 changes: 32 additions & 4 deletions src/msgpack/rpc/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,35 @@ static const message_type_t NOTIFY = 2;
static const error_type_t NO_METHOD_ERROR = 0x01;
static const error_type_t ARGUMENT_ERROR = 0x02;

//The following tuple_type struct are imported from msgpack C++03 adapters (for C++11 compat)
template <typename T>
struct tuple_type {
typedef T type;
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef const T& transparent_reference;
};

template <typename T>
struct tuple_type<T&> {
typedef T type;
typedef T& value_type;
typedef T& reference;
typedef const T& const_reference;
typedef T& transparent_reference;
};

template <typename T>
struct tuple_type<const T&> {
typedef T type;
typedef T& value_type;
typedef T& reference;
typedef const T& const_reference;
typedef const T& transparent_reference;
};


struct msg_rpc {
msg_rpc() { }

Expand All @@ -58,7 +86,7 @@ struct msg_request {

msg_request(
Method method,
typename msgpack::type::tuple_type<Parameter>::transparent_reference param,
typename tuple_type<Parameter>::transparent_reference param,
msgid_t msgid) :
type(REQUEST),
msgid(msgid),
Expand All @@ -80,8 +108,8 @@ struct msg_response {
msgid(0) { }

msg_response(
typename msgpack::type::tuple_type<Result>::transparent_reference result,
typename msgpack::type::tuple_type<Error >::transparent_reference error,
typename tuple_type<Result>::transparent_reference result,
typename tuple_type<Error >::transparent_reference error,
msgid_t msgid) :
type(RESPONSE),
msgid(msgid),
Expand All @@ -103,7 +131,7 @@ struct msg_notify {

msg_notify(
Method method,
typename msgpack::type::tuple_type<Parameter>::transparent_reference param) :
typename tuple_type<Parameter>::transparent_reference param) :
type(NOTIFY),
method(method),
param(param) { }
Expand Down
4 changes: 2 additions & 2 deletions src/msgpack/rpc/request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ void request::send_data(sbuffer* sbuf)
m_pimpl->send_data(sbuf);
}

void request::send_data(std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf)
void request::send_data(std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf /**/)
{
m_pimpl->send_data(vbuf);
m_pimpl->send_data(std::move(vbuf));
}

auto_zone& request::zone()
Expand Down
6 changes: 3 additions & 3 deletions src/msgpack/rpc/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class request {

uint32_t get_msgid() const;
void send_data(sbuffer* sbuf);
void send_data(std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf);
void send_data(std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf /**/);

private:
shared_request m_pimpl;
Expand Down Expand Up @@ -130,12 +130,12 @@ inline void request::call(Result& res, Error& err, shared_zone z)
{
if(is_sent()) { return; }

std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf(
std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf(
new with_shared_zone<vrefbuffer>(z));
msg_response<Result&, Error> msgres(res, err, get_msgid());
msgpack::pack(*vbuf, msgres);

send_data(vbuf);
send_data(std::move(vbuf));
}

template <typename Result>
Expand Down
6 changes: 3 additions & 3 deletions src/msgpack/rpc/request_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class request_impl {
request_impl(shared_message_sendable ms, msgid_t msgid,
object method, object params, auto_zone z) :
m_ms(ms), m_msgid(msgid),
m_method(method), m_params(params), m_zone(z) { }
m_method(method), m_params(params), m_zone(std::move(z)) { }

~request_impl() { }

Expand All @@ -45,11 +45,11 @@ class request_impl {
return !m_ms;
}

void send_data(auto_vreflife vbuf)
void send_data(auto_vreflife vbuf /**/)
{
shared_message_sendable ms = m_ms;
if(!ms) { return; }
ms->send_data(vbuf);
ms->send_data(std::move(vbuf));
m_ms.reset();
}

Expand Down
4 changes: 2 additions & 2 deletions src/msgpack/rpc/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void server_impl::on_request(
{
shared_request sr(new request_impl(
ms, msgid,
method, params, z));
method, params, std::move(z)));
m_dp->dispatch(request(sr));
}

Expand All @@ -65,7 +65,7 @@ void server_impl::on_notify(
{
shared_request sr(new request_impl(
shared_message_sendable(), 0,
method, params, z));
method, params, std::move(z)));
m_dp->dispatch(request(sr));
}

Expand Down
2 changes: 1 addition & 1 deletion src/msgpack/rpc/server_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class server_impl : public session_pool_impl {

private:
dispatcher* m_dp;
std::auto_ptr<server_transport> m_stran;
std::unique_ptr<server_transport> m_stran;

private:
server_impl();
Expand Down
18 changes: 9 additions & 9 deletions src/msgpack/rpc/session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ future session_impl::send_request_impl(msgid_t msgid, sbuffer* sbuf)
return future(f);
}

future session_impl::send_request_impl(msgid_t msgid, auto_vreflife vbuf)
future session_impl::send_request_impl(msgid_t msgid, auto_vreflife vbuf /**/)
{
LOG_DEBUG("sending... msgid=",msgid);
shared_future f(new future_impl(shared_from_this(), m_loop));
m_reqtable.insert(msgid, f);

m_tran->send_data(vbuf);
m_tran->send_data(std::move(vbuf));

return future(f);
}
Expand All @@ -75,9 +75,9 @@ void session_impl::send_notify_impl(sbuffer* sbuf)
m_tran->send_data(sbuf);
}

void session_impl::send_notify_impl(auto_vreflife vbuf)
void session_impl::send_notify_impl(auto_vreflife vbuf /**/)
{
m_tran->send_data(vbuf);
m_tran->send_data(std::move(vbuf));
}

msgid_t session_impl::next_msgid()
Expand Down Expand Up @@ -127,7 +127,7 @@ void session_impl::on_response(msgid_t msgid,
LOG_DEBUG("no entry on request table for msgid=",msgid);
return;
}
f->set_result(result, error, z);
f->set_result(result, error, std::move(z));
}


Expand All @@ -146,17 +146,17 @@ void session::set_timeout(unsigned int sec)
unsigned int session::get_timeout() const
{ return m_pimpl->get_timeout(); }

future session::send_request_impl(msgid_t msgid, std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf)
{ return m_pimpl->send_request_impl(msgid, vbuf); }
future session::send_request_impl(msgid_t msgid, std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf /**/)
{ return m_pimpl->send_request_impl(msgid, std::move(vbuf)); }

future session::send_request_impl(msgid_t msgid, sbuffer* sbuf)
{ return m_pimpl->send_request_impl(msgid, sbuf); }

void session::send_notify_impl(sbuffer* sbuf)
{ return m_pimpl->send_notify_impl(sbuf); }

void session::send_notify_impl(std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf)
{ return m_pimpl->send_notify_impl(vbuf); }
void session::send_notify_impl(std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf /**/)
{ return m_pimpl->send_notify_impl(std::move(vbuf)); }

msgid_t session::next_msgid()
{ return m_pimpl->next_msgid(); }
Expand Down
12 changes: 6 additions & 6 deletions src/msgpack/rpc/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ class session : public caller<session> {
const Parameter& param, shared_zone msglife);

future send_request_impl(msgid_t msgid, sbuffer* sbuf);
future send_request_impl(msgid_t msgid, std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf);
future send_request_impl(msgid_t msgid, std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf /**/);

template <typename Method, typename Parameter>
void send_notify(Method method,
const Parameter& param, shared_zone msglife);

void send_notify_impl(sbuffer* sbuf);
void send_notify_impl(std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf);
void send_notify_impl(std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf /**/);

friend class caller<session>;

Expand All @@ -79,10 +79,10 @@ future session::send_request(Method method,
msg_request<Method, Parameter> msgreq(method, param, msgid);

if(msglife) {
std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf(
std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf(
new with_shared_zone<vrefbuffer>(msglife));
msgpack::pack(*vbuf, msgreq);
return send_request_impl(msgid, vbuf);
return send_request_impl(msgid, std::move(vbuf));

} else {
msgpack::sbuffer sbuf;
Expand All @@ -98,10 +98,10 @@ void session::send_notify(Method method,
msg_notify<Method, Parameter> msgreq(method, param);

if(msglife) {
std::auto_ptr<with_shared_zone<vrefbuffer> > vbuf(
std::unique_ptr<with_shared_zone<vrefbuffer> > vbuf(
new with_shared_zone<vrefbuffer>(msglife));
msgpack::pack(*vbuf, msgreq);
return send_notify_impl(vbuf);
return send_notify_impl(std::move(vbuf));

} else {
msgpack::sbuffer sbuf;
Expand Down
6 changes: 3 additions & 3 deletions src/msgpack/rpc/session_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ class session_impl : public mp::enable_shared_from_this<session_impl> {

public:
future send_request_impl(msgid_t msgid, sbuffer* sbuf);
future send_request_impl(msgid_t msgid, auto_vreflife vbuf);
future send_request_impl(msgid_t msgid, auto_vreflife vbuf /**/);

void send_notify_impl(sbuffer* sbuf);
void send_notify_impl(auto_vreflife vbuf);
void send_notify_impl(auto_vreflife vbuf /**/);

public:
void on_response(msgid_t msgid,
Expand All @@ -83,7 +83,7 @@ class session_impl : public mp::enable_shared_from_this<session_impl> {

loop m_loop;

std::auto_ptr<client_transport> m_tran;
std::unique_ptr<client_transport> m_tran;

msgid_t m_msgid_rr;
reqtable m_reqtable;
Expand Down
2 changes: 1 addition & 1 deletion src/msgpack/rpc/session_pool_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class session_pool_impl : public mp::enable_shared_from_this<session_pool_impl>

loop m_loop;

std::auto_ptr<builder> m_builder;
std::unique_ptr<builder> m_builder;

private:
session_pool_impl(const session_pool_impl&);
Expand Down
Loading