Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
Minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stéphan Kochen committed Sep 25, 2010
1 parent b5266c3 commit 659c093
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions binding.cc
Expand Up @@ -43,6 +43,9 @@ do { \
GetOptions, SetOptions); \
} while (0)


// FIXME: Error checking needs to be implemented on all `zmq_` calls.

namespace zmq {

static Persistent<String> receive_symbol;
Expand All @@ -54,10 +57,13 @@ typedef struct outgoing_message {
void (*freeFxn)(void *);
} outgoing_message;

class Socket;


class Context : public EventEmitter {
friend class Socket;
public:
static void Initialize (v8::Handle<v8::Object> target) {
static void Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(New);
Expand All @@ -70,10 +76,6 @@ class Context : public EventEmitter {
target->Set(String::NewSymbol("Context"), t->GetFunction());
}

void *getCContext() {
return context_;
}

void Close() {
zmq_term(context_);
context_ = NULL;
Expand Down Expand Up @@ -109,14 +111,13 @@ class Context : public EventEmitter {
return Undefined();
}

Context(int io_threads) : EventEmitter () {
Context(int io_threads) : EventEmitter() {
context_ = zmq_init(io_threads);
}

~Context() {
if (context_ != NULL) {
if (context_ != NULL)
Close();
}
assert(context_ == NULL);
}

Expand All @@ -126,9 +127,8 @@ class Context : public EventEmitter {


class Socket : public EventEmitter {
friend class Context;
public:
static void Initialize (v8::Handle<v8::Object> target) {
static void Initialize(v8::Handle<v8::Object> target) {
HandleScope scope;

Local<FunctionTemplate> t = FunctionTemplate::New(New);
Expand Down Expand Up @@ -189,7 +189,7 @@ friend class Context;
return ThrowException(Exception::TypeError(
String::New("Value must be an integer")));
}
int64_t value = (int64_t)wrappedValue->ToInteger()->Value(); // WARNING: int cast to long!
int64_t value = (int64_t) wrappedValue->ToInteger()->Value(); // WARNING: int cast to long!
zmq_setsockopt(socket_, option, &value, sizeof(value));
return Undefined();
}
Expand All @@ -206,7 +206,7 @@ friend class Context;
return ThrowException(Exception::TypeError(
String::New("Value must be an integer")));
}
uint64_t value = (uint64_t)wrappedValue->ToInteger()->Value(); // WARNING: int cast to long!
uint64_t value = (uint64_t) wrappedValue->ToInteger()->Value(); // WARNING: int cast to long!
zmq_setsockopt(socket_, option, &value, sizeof(value));
return Undefined();
}
Expand Down Expand Up @@ -400,13 +400,12 @@ friend class Context;
}

Socket(Context *context, int type) : EventEmitter () {
socket_ = zmq_socket(context->getCContext(), type);
socket_ = zmq_socket(context->context_, type);
events_ = ZMQ_POLLIN;

size_t zmq_fd_size = sizeof(int);
int fd;
zmq_getsockopt(socket_, ZMQ_FD, &fd, &zmq_fd_size);
// FIXME: error check

ev_init(&watcher_, Socket::Callback);
ev_io_set(&watcher_, fd, EV_READ);
Expand All @@ -428,7 +427,6 @@ friend class Context;
size_t zmq_events_size = sizeof(uint32_t);
uint32_t zmq_events;
zmq_getsockopt(s->socket_, ZMQ_EVENTS, &zmq_events, &zmq_events_size);
// FIXME: error check
s->AfterPoll(zmq_events);
}

Expand All @@ -440,7 +438,6 @@ friend class Context;
size_t zmq_events_size = sizeof(uint32_t);
uint32_t zmq_events;
zmq_getsockopt(socket_, ZMQ_EVENTS, &zmq_events, &zmq_events_size);
// FIXME: error check
if (zmq_events & ZMQ_POLLOUT)
AfterPoll(ZMQ_POLLOUT);
}
Expand Down Expand Up @@ -553,7 +550,7 @@ friend class Context;
}

static void FreeStringMessage(void *message) {
String::Utf8Value *js_msg = (String::Utf8Value *)message;
String::Utf8Value *js_msg = (String::Utf8Value *) message;
delete js_msg;
}

Expand Down Expand Up @@ -585,7 +582,7 @@ friend class Context;
}

extern "C" void
init (Handle<Object> target) {
init(Handle<Object> target) {
HandleScope scope;
zmq::Context::Initialize(target);
zmq::Socket::Initialize(target);
Expand Down

0 comments on commit 659c093

Please sign in to comment.