Skip to content

Commit

Permalink
Code review changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rolftimmermans authored and rgbkrk committed Sep 19, 2017
1 parent a1c3307 commit aa08f32
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1026,8 +1026,8 @@ namespace zmq {

class Socket::OutgoingMessage {
public:
inline OutgoingMessage(Local<Object> buf) {
bufref_ = new BufferReference(buf);
inline OutgoingMessage(Local<Object> buf)
: bufref_(new BufferReference(buf)) {
if (zmq_msg_init_data(&msg_, Buffer::Data(buf), Buffer::Length(buf),
BufferReference::FreeCallback, bufref_) < 0) {
delete bufref_;
Expand All @@ -1047,21 +1047,25 @@ namespace zmq {
private:
class BufferReference {
public:
inline BufferReference(Local<Object> buf) {
async = new uv_async_t;
uv_async_init(uv_default_loop(), async, Destroy);
async->data = this;
persistent.Reset(buf);
inline BufferReference(Local<Object> buf)
: persistent_(buf), async_(new uv_async_t) {
if (uv_async_init(uv_default_loop(), async_, Destroy) < 0) {
delete async_;
delete this;
Nan::ThrowError("Async initialization failed");
}
async_->data = this;
}

inline ~BufferReference() {
persistent.Reset();
persistent_.Reset();
}

// Called by zmq when the message has been sent.
// NOTE: May be called from a worker thread. Do not modify V8/Node.
static void FreeCallback(void* data, void* bufref) {
uv_async_send(static_cast<BufferReference*>(bufref)->async);
static void FreeCallback(void*, void* bufref) {
int result = uv_async_send(static_cast<BufferReference*>(bufref)->async_);
assert(result == 0);
}

static void Destroy(uv_async_t* async) {
Expand All @@ -1070,8 +1074,8 @@ namespace zmq {
delete bufref;
}
private:
Nan::Persistent<Object> persistent;
uv_async_t* async;
Nan::Persistent<Object> persistent_;
uv_async_t* async_;
};

zmq_msg_t msg_;
Expand Down

0 comments on commit aa08f32

Please sign in to comment.