Skip to content
Browse files

Renamed ezmq to erlzmq2

  • Loading branch information...
1 parent e3b1d9f commit baa8345302960acc423231f38d4ba5cd00947147 @yrashk yrashk committed Mar 9, 2011
View
2 Makefile
@@ -27,7 +27,7 @@ compile: dependencies
@./rebar compile
perf: compile
- @cd perf && erlc ezmq_perf.erl
+ @cd perf && erlc erlzmq_perf.erl
test: compile
@./rebar eunit
View
14 README.md
@@ -1,4 +1,4 @@
-ezmq
+erlzmq2
====
NIF based Erlang bindings for the ZeroMQ messaging library.
@@ -7,23 +7,23 @@ Copyright (c) 2011 Yurii Rashkovskii and Evax Sofware
Overview
========
-The ezmq application provides high-performance NIF based Erlang bindings
+The erlzmq2 application provides high-performance NIF based Erlang bindings
for the ZeroMQ messaging library.
Downloading
===========
-The ezmq source code can be found on [GitHub](https://github.com/yrashk/ezmq)
+The erlzmq2 source code can be found on [GitHub](https://github.com/yrashk/erlzmq2)
- $ git clone http://github.com/yrashk/ezmq.git
+ $ git clone http://github.com/yrashk/erlzmq2.git
It is also available on [Agner](http://erlagner.org/):
- $ agner build ezmq
+ $ agner build erlzmq
-In order to build ezmq against a specific version of ZeroMQ (not `master`), use this:
+In order to build erlzmq2 against a specific version of ZeroMQ (not `master`), use this:
- $ ZEROMQ_VERSION=v<VERSION> agner build ezmq
+ $ ZEROMQ_VERSION=v<VERSION> agner build erlzmq
Building
========
View
192 c_src/ezmq_nif.c → c_src/erlzmq_nif.c
@@ -4,94 +4,94 @@
#include <sys/queue.h>
#include <stdio.h>
-static ErlNifResourceType* ezmq_nif_resource_context;
-static ErlNifResourceType* ezmq_nif_resource_socket;
+static ErlNifResourceType* erlzmq_nif_resource_context;
+static ErlNifResourceType* erlzmq_nif_resource_socket;
-typedef struct _ezmq_context {
+typedef struct _erlzmq_context {
void * context;
void * ipc_socket;
char * ipc_socket_name;
int running;
ErlNifCond * cond;
ErlNifMutex * mutex;
ErlNifTid polling_tid;
-} ezmq_context;
+} erlzmq_context;
-typedef struct _ezmq_socket {
+typedef struct _erlzmq_socket {
void * socket;
- ezmq_context * context;
-} ezmq_socket;
+ erlzmq_context * context;
+} erlzmq_socket;
-#define EZMQ_TERM 1211981
+#define erlzmq_TERM 1211981
-typedef struct _ezmq_recv {
+typedef struct _erlzmq_recv {
ErlNifEnv * env;
ERL_NIF_TERM ref;
int flags;
ErlNifPid pid;
void * socket;
- TAILQ_ENTRY(_ezmq_recv) recvs;
-} ezmq_recv;
-TAILQ_HEAD(recvs_head, _ezmq_recv);
+ TAILQ_ENTRY(_erlzmq_recv) recvs;
+} erlzmq_recv;
+TAILQ_HEAD(recvs_head, _erlzmq_recv);
// Prototypes
#define NIF(name) ERL_NIF_TERM name(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
-NIF(ezmq_nif_context);
-NIF(ezmq_nif_socket);
-NIF(ezmq_nif_bind);
-NIF(ezmq_nif_connect);
-NIF(ezmq_nif_setsockopt);
-NIF(ezmq_nif_getsockopt);
-NIF(ezmq_nif_send);
-NIF(ezmq_nif_brecv);
-NIF(ezmq_nif_recv);
-NIF(ezmq_nif_close);
-NIF(ezmq_nif_term);
+NIF(erlzmq_nif_context);
+NIF(erlzmq_nif_socket);
+NIF(erlzmq_nif_bind);
+NIF(erlzmq_nif_connect);
+NIF(erlzmq_nif_setsockopt);
+NIF(erlzmq_nif_getsockopt);
+NIF(erlzmq_nif_send);
+NIF(erlzmq_nif_brecv);
+NIF(erlzmq_nif_recv);
+NIF(erlzmq_nif_close);
+NIF(erlzmq_nif_term);
static ErlNifFunc nif_funcs[] =
{
- {"context", 1, ezmq_nif_context},
- {"socket", 2, ezmq_nif_socket},
- {"bind", 2, ezmq_nif_bind},
- {"connect", 2, ezmq_nif_connect},
- {"setsockopt", 3, ezmq_nif_setsockopt},
- {"getsockopt", 2, ezmq_nif_getsockopt},
- {"send", 3, ezmq_nif_send},
- {"brecv", 2, ezmq_nif_brecv},
- {"recv", 2, ezmq_nif_recv},
- {"close", 1, ezmq_nif_close},
- {"term", 1, ezmq_nif_term}
+ {"context", 1, erlzmq_nif_context},
+ {"socket", 2, erlzmq_nif_socket},
+ {"bind", 2, erlzmq_nif_bind},
+ {"connect", 2, erlzmq_nif_connect},
+ {"setsockopt", 3, erlzmq_nif_setsockopt},
+ {"getsockopt", 2, erlzmq_nif_getsockopt},
+ {"send", 3, erlzmq_nif_send},
+ {"brecv", 2, erlzmq_nif_brecv},
+ {"recv", 2, erlzmq_nif_recv},
+ {"close", 1, erlzmq_nif_close},
+ {"term", 1, erlzmq_nif_term}
};
void * polling_thread(void * handle);
-NIF(ezmq_nif_context)
+NIF(erlzmq_nif_context)
{
int _threads;
if (!enif_get_int(env, argv[0], &_threads)) {
return enif_make_badarg(env);
}
- ezmq_context * handle = enif_alloc_resource(ezmq_nif_resource_context,
- sizeof(ezmq_context));
+ erlzmq_context * handle = enif_alloc_resource(erlzmq_nif_resource_context,
+ sizeof(erlzmq_context));
handle->context = zmq_init(_threads);
char socket_id[64];
- sprintf(socket_id, "inproc://ezmq-%ld", (long int) handle);
+ sprintf(socket_id, "inproc://erlzmq-%ld", (long int) handle);
handle->ipc_socket_name = strdup(socket_id);
handle->ipc_socket = zmq_socket(handle->context, ZMQ_PUSH);
zmq_bind(handle->ipc_socket,socket_id);
handle->running = 0;
- handle->mutex = enif_mutex_create("ezmq_context_mutex");
- handle->cond = enif_cond_create("ezmq_context_cond");
+ handle->mutex = enif_mutex_create("erlzmq_context_mutex");
+ handle->cond = enif_cond_create("erlzmq_context_cond");
enif_mutex_lock(handle->mutex);
int err;
- if ((err = enif_thread_create("ezmq_polling_thread", &handle->polling_tid,
+ if ((err = enif_thread_create("erlzmq_polling_thread", &handle->polling_tid,
polling_thread, handle, NULL))) {
enif_mutex_unlock(handle->mutex);
enif_mutex_destroy(handle->mutex);
@@ -114,12 +114,12 @@ NIF(ezmq_nif_context)
return enif_make_tuple2(env, enif_make_atom(env, "ok"), result);
}
-NIF(ezmq_nif_socket)
+NIF(erlzmq_nif_socket)
{
- ezmq_context * ctx;
+ erlzmq_context * ctx;
int _type;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_context, (void **) &ctx)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_context, (void **) &ctx)) {
return enif_make_badarg(env);
}
@@ -131,8 +131,8 @@ NIF(ezmq_nif_socket)
return enif_make_badarg(env);
}
- ezmq_socket * handle = enif_alloc_resource(ezmq_nif_resource_socket,
- sizeof(ezmq_socket));
+ erlzmq_socket * handle = enif_alloc_resource(erlzmq_nif_resource_socket,
+ sizeof(erlzmq_socket));
handle->context = ctx;
handle->socket = zmq_socket(ctx->context, _type);
@@ -143,13 +143,13 @@ NIF(ezmq_nif_socket)
return enif_make_tuple2(env, enif_make_atom(env, "ok"), result);
}
-NIF(ezmq_nif_bind)
+NIF(erlzmq_nif_bind)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
unsigned _endpoint_length;
char * _endpoint;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket, (void **) &socket)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket, (void **) &socket)) {
return enif_make_badarg(env);
}
@@ -174,13 +174,13 @@ NIF(ezmq_nif_bind)
}
}
-NIF(ezmq_nif_connect)
+NIF(erlzmq_nif_connect)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
unsigned _endpoint_length;
char * _endpoint;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket, (void **) &socket)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket, (void **) &socket)) {
return enif_make_badarg(env);
}
@@ -205,9 +205,9 @@ NIF(ezmq_nif_connect)
}
}
-NIF(ezmq_nif_setsockopt)
+NIF(erlzmq_nif_setsockopt)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
int _option_name;
ErlNifUInt64 _uint64;
ErlNifSInt64 _int64;
@@ -216,7 +216,7 @@ NIF(ezmq_nif_setsockopt)
void *_option_value;
size_t _option_len = 8; // 64 bit
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket,
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket,
(void **) &socket)) {
return enif_make_badarg(env);
}
@@ -277,9 +277,9 @@ NIF(ezmq_nif_setsockopt)
return enif_make_badarg(env);
}
-NIF(ezmq_nif_getsockopt)
+NIF(erlzmq_nif_getsockopt)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
int _option_name;
ErlNifBinary _bin;
int64_t _option_value_64;
@@ -288,7 +288,7 @@ NIF(ezmq_nif_getsockopt)
int _option_value_int;
size_t _option_len = 8; // 64 bit
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket,
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket,
(void **) &socket)) {
return enif_make_badarg(env);
}
@@ -349,13 +349,13 @@ NIF(ezmq_nif_getsockopt)
enif_make_int(env, zmq_errno()));
}
-NIF(ezmq_nif_send)
+NIF(erlzmq_nif_send)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
int _flags;
ErlNifBinary _bin;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket, (void **) &socket)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket, (void **) &socket)) {
return enif_make_badarg(env);
}
@@ -386,7 +386,7 @@ NIF(ezmq_nif_send)
}
-int brecv(zmq_msg_t * msg, ezmq_socket * socket, int flags) {
+int brecv(zmq_msg_t * msg, erlzmq_socket * socket, int flags) {
int error;
if ((error = zmq_msg_init(msg))) {
return zmq_errno();
@@ -399,12 +399,12 @@ int brecv(zmq_msg_t * msg, ezmq_socket * socket, int flags) {
return 0;
}
-NIF(ezmq_nif_brecv)
+NIF(erlzmq_nif_brecv)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
int _flags;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket, (void **) &socket)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket, (void **) &socket)) {
return enif_make_badarg(env);
}
@@ -428,13 +428,13 @@ NIF(ezmq_nif_brecv)
return enif_make_tuple2(env, enif_make_atom(env, "ok"), enif_make_binary(env, &bin));
}
-NIF(ezmq_nif_recv)
+NIF(erlzmq_nif_recv)
{
- ezmq_recv recv;
- ezmq_socket * socket;
+ erlzmq_recv recv;
+ erlzmq_socket * socket;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket,
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket,
(void **) &socket)) {
return enif_make_badarg(env);
}
@@ -460,11 +460,11 @@ NIF(ezmq_nif_recv)
recv.ref = enif_make_ref(recv.env);
recv.socket = socket->socket;
- if ((error = zmq_msg_init_size(&msg, sizeof(ezmq_recv)))) {
+ if ((error = zmq_msg_init_size(&msg, sizeof(erlzmq_recv)))) {
goto q_err;
}
- memcpy(zmq_msg_data(&msg), &recv, sizeof(ezmq_recv));
+ memcpy(zmq_msg_data(&msg), &recv, sizeof(erlzmq_recv));
if ((error = zmq_send(socket->context->ipc_socket, &msg, 0))) {
goto q_err;
@@ -494,7 +494,7 @@ NIF(ezmq_nif_recv)
void * polling_thread(void * handle)
{
- ezmq_context * ctx = (ezmq_context *) handle;
+ erlzmq_context * ctx = (erlzmq_context *) handle;
ErlNifEnv * final_env = enif_alloc_env();
ERL_NIF_TERM final_ref;
ERL_NIF_TERM final_pid;
@@ -515,7 +515,7 @@ void * polling_thread(void * handle)
while (ctx->running) {
int i;
zmq_msg_t msg;
- ezmq_recv *r, *rtmp;
+ erlzmq_recv *r, *rtmp;
zmq_pollitem_t *items = calloc(nreaders, sizeof(zmq_pollitem_t));
items[0].socket = ipc_socket;
@@ -555,8 +555,8 @@ void * polling_thread(void * handle)
if (items[0].revents & ZMQ_POLLIN) {
zmq_msg_init(&msg);
if (!zmq_recv(items[0].socket, &msg, 0)) {
- ezmq_recv * recv = (ezmq_recv *) zmq_msg_data(&msg);
- if (recv->flags & EZMQ_TERM) {
+ erlzmq_recv * recv = (erlzmq_recv *) zmq_msg_data(&msg);
+ if (recv->flags & erlzmq_TERM) {
final_ref = enif_make_copy(final_env, recv->ref);
final_pid = enif_make_pid(final_env, &recv->pid);
@@ -566,8 +566,8 @@ void * polling_thread(void * handle)
goto out;
}
nreaders++;
- ezmq_recv * r = malloc(sizeof(ezmq_recv));
- memcpy(r, recv, sizeof(ezmq_recv));
+ erlzmq_recv * r = malloc(sizeof(erlzmq_recv));
+ memcpy(r, recv, sizeof(erlzmq_recv));
TAILQ_INSERT_TAIL(recvs_queue, r, recvs);
}
out:
@@ -576,7 +576,7 @@ void * polling_thread(void * handle)
free(items);
}
// cleanup reader's queue
- ezmq_recv * r;
+ erlzmq_recv * r;
while ((r = recvs_queue->tqh_first) != NULL) {
TAILQ_REMOVE(recvs_queue, recvs_queue->tqh_first, recvs);
free(r);
@@ -592,7 +592,7 @@ void * polling_thread(void * handle)
zmq_term(ctx->context);
- // signal ezmq:term/2 that the context has been finally terminated
+ // signal erlzmq:term/2 that the context has been finally terminated
ErlNifPid pid;
enif_get_local_pid(final_env, final_pid, &pid);
@@ -605,12 +605,12 @@ void * polling_thread(void * handle)
return NULL;
}
-NIF(ezmq_nif_close)
+NIF(erlzmq_nif_close)
{
- ezmq_socket * socket;
+ erlzmq_socket * socket;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_socket, (void **) &socket)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_socket, (void **) &socket)) {
return enif_make_badarg(env);
}
@@ -621,24 +621,24 @@ NIF(ezmq_nif_close)
}
}
-NIF(ezmq_nif_term)
+NIF(erlzmq_nif_term)
{
- ezmq_context * ctx;
+ erlzmq_context * ctx;
- if (!enif_get_resource(env, argv[0], ezmq_nif_resource_context, (void **) &ctx)) {
+ if (!enif_get_resource(env, argv[0], erlzmq_nif_resource_context, (void **) &ctx)) {
return enif_make_badarg(env);
}
zmq_msg_t msg;
- ezmq_recv recv;
+ erlzmq_recv recv;
- recv.flags = EZMQ_TERM;
+ recv.flags = erlzmq_TERM;
recv.env = enif_alloc_env();
recv.ref = enif_make_ref(recv.env);
enif_self(env, &recv.pid);
- zmq_msg_init_size(&msg, sizeof(ezmq_recv));
- memcpy(zmq_msg_data(&msg), &recv, sizeof(ezmq_recv));
+ zmq_msg_init_size(&msg, sizeof(erlzmq_recv));
+ memcpy(zmq_msg_data(&msg), &recv, sizeof(erlzmq_recv));
zmq_send(ctx->ipc_socket, &msg, ZMQ_NOBLOCK);
zmq_msg_close(&msg);
@@ -647,15 +647,15 @@ NIF(ezmq_nif_term)
static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
{
- ezmq_nif_resource_context =
- enif_open_resource_type(env, "ezmq_nif",
- "ezmq_nif_resource_context",
+ erlzmq_nif_resource_context =
+ enif_open_resource_type(env, "erlzmq_nif",
+ "erlzmq_nif_resource_context",
NULL,
ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER,
0);
- ezmq_nif_resource_socket =
- enif_open_resource_type(env, "ezmq_nif",
- "ezmq_nif_resource_socket",
+ erlzmq_nif_resource_socket =
+ enif_open_resource_type(env, "erlzmq_nif",
+ "erlzmq_nif_resource_socket",
NULL,
ERL_NIF_RT_CREATE | ERL_NIF_RT_TAKEOVER,
0);
@@ -665,5 +665,5 @@ static int on_load(ErlNifEnv* env, void** priv_data, ERL_NIF_TERM load_info)
static void on_unload(ErlNifEnv* env, void* priv_data) {
}
-ERL_NIF_INIT(ezmq_nif, nif_funcs, &on_load, NULL, NULL, &on_unload);
+ERL_NIF_INIT(erlzmq_nif, nif_funcs, &on_load, NULL, NULL, &on_unload);
View
12 doc/overview.edoc
@@ -13,27 +13,27 @@
== Overview ==
-The ezmq application provides high-performance NIF based Erlang bindings
+The erlzmq2 application provides high-performance NIF based Erlang bindings
for the ZeroMQ messaging library.
== Downloading ==
-The ezmq source code can be found on [http://github.com/yrashk/ezmq GitHub]
+The erlzmq2 source code can be found on [http://github.com/zeromq/erlzmq2 GitHub]
```
- $ git clone http://github.com/yrashk/ezmq.git
+ $ git clone http://github.com/zeromq/erlzmq2.git
'''
It is also available on [http://erlagner.org/ Agner]:
```
- $ agner build ezmq
+ $ agner build erlzmq
'''
-In order to build ezmq against a specific version of ZeroMQ (not 'master'), use this:
+In order to build erlzmq2 against a specific version of ZeroMQ (not 'master'), use this:
```
- $ ZEROMQ_VERSION=v<VERSION> agner build ezmq
+ $ ZEROMQ_VERSION=v<VERSION> agner build erlzmq
'''
== Building ==
View
66 include/ezmq.hrl → include/erlzmq.hrl
@@ -38,15 +38,15 @@
%% Types
-%% @type ezmq_socket_type() = pair | pub | sub | req | rep | xreq | xrep |
+%% @type erlzmq_socket_type() = pair | pub | sub | req | rep | xreq | xrep |
%% pull | push | xpub | xsub.
-%% Possible types for an ezmq socket.<br />
+%% Possible types for an erlzmq socket.<br />
%% <i>For more information see
%% <a href="http://api.zeromq.org/master:zmq_socket">zmq_socket</a></i>
--type ezmq_socket_type() :: pair | pub | sub | req | rep | xreq | xrep |
+-type erlzmq_socket_type() :: pair | pub | sub | req | rep | xreq | xrep |
pull | push | xpub | xsub.
-%% @type ezmq_endpoint() = string().
+%% @type erlzmq_endpoint() = string().
%% The endpoint argument is a string consisting of two parts:
%% <b>transport://address</b><br />
%% The following transports are defined:
@@ -55,7 +55,7 @@
%% <i>For more information see
%% <a href="http://api.zeromq.org/master:zmq_bind">zmq_bind</a> or
%% <a href="http://api.zeromq.org/master:zmq_connect">zmq_connect</a></i>
--type ezmq_endpoint() :: string().
+-type erlzmq_endpoint() :: string().
%% @type errno() = eperm | enoent | srch | eintr | eio | enxio | ebad |
%% echild | edeadlk | enomem | eacces | efault | enotblk | ebusy | eexist |
@@ -81,62 +81,62 @@
enotconn | eshutdown | etoomanyrefs |
etimedout | econnrefused | eloop | enametoolong.
-%% @type ezmq_error_type() = enotsup | eprotonosupport | enobufs |
+%% @type erlzmq_error_type() = enotsup | eprotonosupport | enobufs |
%% enetdown | eaddrinuse | eaddnotavail | econnrefused | einprogress |
%% efsm | enocompatproto | eterm | emthread | errno() |
%% {unknown, integer()}.
%% Possible error types.
--type ezmq_error_type() :: enotsup | eprotonosupport | enobufs | enetdown |
+-type erlzmq_error_type() :: enotsup | eprotonosupport | enobufs | enetdown |
eaddrinuse | eaddnotavail | econnrefused |
einprogress | efsm | enocompatproto | eterm |
emthread | errno() | {unknown, integer()}.
-%% @type ezmq_error() = {error, ezmq_error_type()}.
+%% @type erlzmq_error() = {error, erlzmq_error_type()}.
%% Error tuples returned by most API functions.
--type ezmq_error() :: {error, ezmq_error_type()}.
+-type erlzmq_error() :: {error, erlzmq_error_type()}.
-%% @type ezmq_data() = iolist().
-%% Data to be sent with {@link ezmq:send/3. send/3} or received with
-%% {@link ezmq:recv/2. recv/2}
--type ezmq_data() :: iolist().
+%% @type erlzmq_data() = iolist().
+%% Data to be sent with {@link erlzmq:send/3. send/3} or received with
+%% {@link erlzmq:recv/2. recv/2}
+-type erlzmq_data() :: iolist().
-%% @type ezmq_context() = binary().
-%% An opaque handle to an ezmq context.
--opaque ezmq_context() :: binary().
+%% @type erlzmq_context() = binary().
+%% An opaque handle to an erlzmq context.
+-opaque erlzmq_context() :: binary().
-%% @type ezmq_socket() = binary().
-%% An opaque handle to an ezmq socket.
--opaque ezmq_socket() :: binary().
+%% @type erlzmq_socket() = binary().
+%% An opaque handle to an erlzmq socket.
+-opaque erlzmq_socket() :: binary().
-%% @type ezmq_send_recv_flag() = noblock | sndmore | recvmore | {timeout, timeout()}.
-%% The individual flags to use with {@link ezmq:send/3. send/3}
-%% and {@link ezmq:recv/2. recv/2}.<br />
+%% @type erlzmq_send_recv_flag() = noblock | sndmore | recvmore | {timeout, timeout()}.
+%% The individual flags to use with {@link erlzmq:send/3. send/3}
+%% and {@link erlzmq:recv/2. recv/2}.<br />
%% <i>For more information see
%% <a href="http://api.zeromq.org/master:zmq_send">zmq_send</a> or
%% <a href="http://api.zeromq.org/master:zmq_recv">zmq_recv</a></i>
--type ezmq_send_recv_flag() :: noblock | sndmore | recvmore | {timeout, timeout()}.
+-type erlzmq_send_recv_flag() :: noblock | sndmore | recvmore | {timeout, timeout()}.
-%% @type ezmq_send_recv_flags() = list(ezmq_send_recv_flag()).
+%% @type erlzmq_send_recv_flags() = list(erlzmq_send_recv_flag()).
%% A list of flags to use with {@link ezqm:send/3. send/3} and
-%% {@link ezmq:recv/2. recv/2}
--type ezmq_send_recv_flags() :: list(ezmq_send_recv_flag()).
+%% {@link erlzmq:recv/2. recv/2}
+-type erlzmq_send_recv_flags() :: list(erlzmq_send_recv_flag()).
-%% @type ezmq_sockopt() = hwm | swap | affinity | identity | subscribe |
+%% @type erlzmq_sockopt() = hwm | swap | affinity | identity | subscribe |
%% unsubscribe | rate | recovery_ivl | mcast_loop | sndbuf | rcvbuf |
%% rcvmore | fd | events | linger | reconnect_ivl | backlog |
%% recovery_ivl_msec | reconnect_ivl_max.
-%% Available options for {@link ezmq:setsockopt/3. setsockopt/3}
-%% and {@link ezmq:getsockopt/2. getsockopt/2}.<br />
+%% Available options for {@link erlzmq:setsockopt/3. setsockopt/3}
+%% and {@link erlzmq:getsockopt/2. getsockopt/2}.<br />
%% <i>For more information see
%% <a href="http://api.zeromq.org/master:zmq_setsockopt">zmq_setsockopt</a>
%% and <a href="http://api.zeromq.org/master:zmq_getsockopt">zmq_getsockopt</a></i>
--type ezmq_sockopt() :: hwm | swap | affinity | identity | subscribe |
+-type erlzmq_sockopt() :: hwm | swap | affinity | identity | subscribe |
unsubscribe | rate | recovery_ivl | mcast_loop |
sndbuf | rcvbuf | rcvmore | fd | events | linger |
reconnect_ivl | backlog | recovery_ivl_msec |
reconnect_ivl_max.
-%% @type ezmq_sockopt_value() = integer() | iolist().
-%% Possible option values for {@link ezmq:setsockopt/3. setsockopt/3}.
--type ezmq_sockopt_value() :: integer() | iolist().
+%% @type erlzmq_sockopt_value() = integer() | iolist().
+%% Possible option values for {@link erlzmq:setsockopt/3. setsockopt/3}.
+-type erlzmq_sockopt_value() :: integer() | iolist().
View
6 perf/ezmq_perf.erl → perf/erlzmq_perf.erl
@@ -1,15 +1,15 @@
--module(ezmq_perf).
+-module(erlzmq_perf).
-export([recv_loop/2, send_loop/3]).
recv_loop(0, _) ->
ok;
recv_loop(N, S) ->
- ezmq:recv(S),
+ erlzmq:recv(S),
recv_loop(N-1, S).
send_loop(0, _, _) ->
ok;
send_loop(N, S, M) ->
- ezmq:send(S, M),
+ erlzmq:send(S, M),
send_loop(N-1, S, M).
View
14 perf/local_lat.erl
@@ -4,16 +4,16 @@
main([BindTo,MessageSizeStr,RoundtripCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{RoundtripCount, _} = string:to_integer(RoundtripCountStr),
- {ok, Context} = ezmq:context(),
- {ok, Socket} = ezmq:socket(Context, rep),
- ok = ezmq:bind(Socket, BindTo),
+ {ok, Context} = erlzmq:context(),
+ {ok, Socket} = erlzmq:socket(Context, rep),
+ ok = erlzmq:bind(Socket, BindTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
Do = fun() ->
- {ok, RMsg} = ezmq:brecv(Socket),
+ {ok, RMsg} = erlzmq:brecv(Socket),
RMsg = Msg,
- ezmq:send(Socket, Msg)
+ erlzmq:send(Socket, Msg)
end,
[ Do() || _I <- lists:seq(1,RoundtripCount) ],
- ezmq:close(Socket),
- ezmq:term(Context).
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
View
16 perf/local_thr.erl
@@ -5,13 +5,13 @@
main([BindTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{MessageCount, _} = string:to_integer(MessageCountStr),
- {ok, Context} = ezmq:context(),
- {ok, Socket} = ezmq:socket(Context, sub),
- ok = ezmq:setsockopt(Socket,subscribe, <<>>),
- ok = ezmq:bind(Socket, BindTo),
- ezmq:recv(Socket),
+ {ok, Context} = erlzmq:context(),
+ {ok, Socket} = erlzmq:socket(Context, sub),
+ ok = erlzmq:setsockopt(Socket,subscribe, <<>>),
+ ok = erlzmq:bind(Socket, BindTo),
+ erlzmq:recv(Socket),
Start = now(),
- ezmq_perf:recv_loop(MessageCount-1, Socket),
+ erlzmq_perf:recv_loop(MessageCount-1, Socket),
Elapsed = timer:now_diff(now(), Start),
Throughput = MessageCount / Elapsed * 1000000,
@@ -23,6 +23,6 @@ main([BindTo,MessageSizeStr,MessageCountStr]) ->
"mean throughput: ~p [Mb/s]~n",
[MessageSize, MessageCount, Throughput, Megabits]),
- ezmq:close(Socket),
- ezmq:term(Context).
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
View
14 perf/remote_lat.erl
@@ -4,13 +4,13 @@
main([ConnectTo,MessageSizeStr,RoundtripCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{RoundtripCount, _} = string:to_integer(RoundtripCountStr),
- {ok, Context} = ezmq:context(),
- {ok, Socket} = ezmq:socket(Context, req),
- ok = ezmq:connect(Socket, ConnectTo),
+ {ok, Context} = erlzmq:context(),
+ {ok, Socket} = erlzmq:socket(Context, req),
+ ok = erlzmq:connect(Socket, ConnectTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
Do = fun() ->
- ezmq:send(Socket, Msg),
- {ok, Msg} = ezmq:brecv(Socket)
+ erlzmq:send(Socket, Msg),
+ {ok, Msg} = erlzmq:brecv(Socket)
end,
{Elapsed, _} = timer:tc(fun () ->
@@ -23,5 +23,5 @@ main([ConnectTo,MessageSizeStr,RoundtripCountStr]) ->
"roundtrip count: ~p~n"
"average latency: ~p [us]~n",
[MessageSize, RoundtripCount, Latency]),
- ezmq:close(Socket),
- ezmq:term(Context).
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
View
12 perf/remote_thr.erl
@@ -4,10 +4,10 @@
main([ConnectTo,MessageSizeStr,MessageCountStr]) ->
{MessageSize, _} = string:to_integer(MessageSizeStr),
{MessageCount, _} = string:to_integer(MessageCountStr),
- {ok, Context} = ezmq:context(1),
- {ok, Socket} = ezmq:socket(Context,pub),
- ezmq:connect(Socket, ConnectTo),
+ {ok, Context} = erlzmq:context(1),
+ {ok, Socket} = erlzmq:socket(Context,pub),
+ erlzmq:connect(Socket, ConnectTo),
Msg = list_to_binary(lists:duplicate(MessageSize, 0)),
- ezmq_perf:send_loop(MessageCount, Socket, Msg),
- ezmq:close(Socket),
- ezmq:term(Context).
+ erlzmq_perf:send_loop(MessageCount, Socket, Msg),
+ erlzmq:close(Socket),
+ erlzmq:term(Context).
View
6 src/ezmq.app.src → src/erlzmq.app.src
@@ -1,12 +1,12 @@
-{application, ezmq,
+{application, erlzmq,
[
{description, ""},
- {vsn, "1"},
+ {vsn, "2.0"},
{registered, []},
{applications, [
kernel,
stdlib
]},
- {mod, { ezmq_app, []}},
+ {mod, { erlzmq_app, []}},
{env, []}
]}.
View
447 src/erlzmq.erl
@@ -0,0 +1,447 @@
+-module(erlzmq).
+%% @headerfile "erlzmq.hrl"
+-include_lib("erlzmq.hrl").
+-export([context/0, context/1, socket/2, bind/2, connect/2, send/2, send/3,
+ brecv/1, brecv/2, recv/1, recv/2, setsockopt/3, getsockopt/2,
+ close/1, term/1, term/2]).
+-export_type([erlzmq_socket/0, erlzmq_context/0]).
+
+%% @equiv context(1)
+%% @spec context() -> {ok, erlzmq_context()} | erlzmq_error()
+-spec context() -> {ok, erlzmq_context()} | erlzmq_error().
+context() ->
+ context(1).
+
+%% @doc Create a new erlzmq context with the specified number of io threads.
+%% <br />
+%% If the context can be created an 'ok' tuple containing an
+%% {@type erlzmq_context()} handle to the created context is returned;
+%% if not, it returns an 'error' tuple with an {@type erlzmq_type_error()}
+%% describing the error.
+%% <br />
+%% The context must be later cleaned up calling {@link erlzmq:term/1. term/1}
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq-init">zmq_init</a></i>
+%% @end
+%% @spec context(pos_integer()) -> {ok, erlzmq_context()} | erlzmq_error()
+-spec context(Threads :: pos_integer()) -> {ok, erlzmq_context()} | erlzmq_error().
+
+context(Threads) when is_integer(Threads) ->
+ erlzmq_nif:context(Threads).
+
+
+%% @doc Create a socket.
+%% <br />
+%% This functions creates a socket of the given
+%% {@link erlzmq_socket_type(). type} and associates it with the given
+%% {@link erlzmq_context(). context}.
+%% <br />
+%% If the socket can be created an 'ok' tuple containing a
+%% {@type erlzmq_socket()} handle to the created socket is returned;
+%% if not, it returns an {@type erlzmq_error()} describing the error.<br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_socket">zmq_socket</a>.</i>
+%% @end
+%% @spec socket(erlzmq_context(), erlzmq_socket_type()) -> {ok, erlzmq_socket()} | erlzmq_error()
+-spec socket(Context :: erlzmq_context(), Type :: erlzmq_socket_type()) -> {ok, erlzmq_socket()} | erlzmq_error().
+
+socket(Context, Type) ->
+ erlzmq_nif:socket(Context, socket_type(Type)).
+
+%% @doc Accept connections on a socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_bind">zmq_bind</a>.</i>
+%% @end
+%% @spec bind(erlzmq_socket(), erlzmq_endpoint()) -> ok | erlzmq_error()
+-spec bind(Socket :: erlzmq_socket(), Endpoint :: erlzmq_endpoint()) -> ok | erlzmq_error().
+
+bind(Socket, Endpoint) ->
+ erlzmq_result(erlzmq_nif:bind(Socket, Endpoint)).
+
+%% @doc Connect a socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_connect">zmq_connect</a>.</i>
+%% @end
+%% @spec connect(erlzmq_socket(), erlzmq_endpoint()) -> ok | erlzmq_error()
+-spec connect(Socket :: erlzmq_socket(), Endpoint :: erlzmq_endpoint()) -> ok | erlzmq_error().
+
+connect(Socket, Endpoint) ->
+ erlzmq_result(erlzmq_nif:connect(Socket, Endpoint)).
+
+%% @equiv send(Socket, Msg, [])
+%% @spec send(erlzmq_socket(), erlzmq_data()) -> ok | erlzmq_error()
+-spec send(Socket :: erlzmq_socket(), Data :: erlzmq_data()) -> ok | erlzmq_error().
+
+send(Socket, Binary) ->
+ send(Socket, Binary, []).
+
+%% @doc Send a message on a socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_send">zmq_send</a>.</i>
+%% @end
+%% @spec send(ezma_socket(), erlzmq_data(), erlzmq_send_recv_flags()) -> ok | erlzmq_error()
+-spec send(Socket :: erlzmq_socket(), Data :: erlzmq_data(), Flags :: erlzmq_send_recv_flags()) -> ok | erlzmq_error().
+
+send(Socket, Binary, Flags) when is_list(Flags) ->
+ erlzmq_result(erlzmq_nif:send(Socket, Binary, sendrecv_flags(Flags))).
+
+%% @equiv brecv(Socket, 0)
+%% @spec brecv(erlzmq_socket()) -> {ok, erlzmq_data()} | erlzmq_error()
+-spec brecv(Socket :: erlzmq_socket()) -> {ok, erlzmq_data()} | erlzmq_error().
+
+brecv(Socket) ->
+ erlzmq_result(brecv(Socket, [])).
+
+%% @doc Receive a message from a socket in a blocking way.
+%% This function can block the current VM scheduler. <b>DO NOT USE IT UNLESS YOU REALLY KNOW WHAT YOU ARE DOING</b>.
+%% @end
+%% @spec brecv(erlzmq_socket(), erlzmq_send_recv_flags()) -> {ok, erlzmq_data()} | erlzmq_error()
+-spec brecv(Socket :: erlzmq_socket(), Flags :: erlzmq_send_recv_flags()) -> {ok, erlzmq_data()} | erlzmq_error().
+
+brecv(Socket, Flags) when is_list(Flags) ->
+ erlzmq_result( erlzmq_nif:brecv(Socket, sendrecv_flags(Flags))).
+
+
+%% @equiv recv(Socket, 0)
+%% @spec recv(erlzmq_socket()) -> {ok, erlzmq_data()} | erlzmq_error()
+-spec recv(Socket :: erlzmq_socket()) -> {ok, erlzmq_data()} | erlzmq_error().
+
+recv(Socket) ->
+ recv(Socket, []).
+
+%% @doc Receive a message from a socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_recv">zmq_recv</a>.</i>
+%% @end
+%% @spec recv(erlzmq_socket(), erlzmq_send_recv_flags()) -> {ok, erlzmq_data()} | erlzmq_error()
+-spec recv(Socket :: erlzmq_socket(), Flags :: erlzmq_send_recv_flags()) -> {ok, erlzmq_data()} | erlzmq_error() | {error, timeout, reference()}.
+
+recv(Socket, Flags) when is_list(Flags) ->
+ case erlzmq_nif:recv(Socket, sendrecv_flags(Flags)) of
+ Ref when is_reference(Ref) ->
+ Timeout = proplists:get_value(timeout, Flags, infinity),
+ receive
+ {Ref, Result} ->
+ {ok, Result}
+ after Timeout ->
+ {error, timeout, Ref}
+ end;
+ Result ->
+ erlzmq_result(Result)
+ end.
+
+%% @doc Set an {@link erlzmq_sockopt(). option} associated with a socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_setsockopt">zmq_setsockopt</a>.</i>
+%% @end
+%% @spec setsockopt(erlzmq_socket(), erlzmq_sockopt(), erlzmq_sockopt_value()) -> ok | erlzmq_error()
+-spec setsockopt(Socket :: erlzmq_socket(), Name :: erlzmq_sockopt(), erlzmq_sockopt_value()) -> ok | erlzmq_error().
+
+setsockopt(Socket, Name, Value) ->
+ erlzmq_result(erlzmq_nif:setsockopt(Socket, option_name(Name), Value)).
+
+%% @doc Get an {@link erlzmq_sockopt(). option} associated with a socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_getsockopt">zmq_getsockopt</a>.</i>
+%% @end
+%% @spec getsockopt(erlzmq_socket(), erlzmq_sockopt()) -> {ok, erlzmq_sockopt_value()} | erlzmq_error()
+-spec getsockopt(Socket :: erlzmq_socket(), Name :: erlzmq_sockopt()) -> {ok, erlzmq_sockopt_value()} | erlzmq_error().
+
+getsockopt(Socket, Name) ->
+ erlzmq_result(erlzmq_nif:getsockopt(Socket, option_name(Name))).
+
+
+%% @doc Close the given socket.
+%% <br />
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_close">zmq_close</a>.</i>
+%% @end
+%% @spec close(erlzmq_socket()) -> ok | erlzmq_error()
+-spec close(Socket :: erlzmq_socket()) -> ok | erlzmq_error().
+
+close(Socket) ->
+ erlzmq_result(erlzmq_nif:close(Socket)).
+
+%% @equiv term(Context, infinity)
+%% @spec term(erlzmq_context()) -> ok | erlzmq_error()
+-spec term(Context :: erlzmq_context()) -> ok | erlzmq_error().
+
+term(Context) ->
+ term(Context, infinity).
+
+
+%% @doc Terminate the given context waiting up to Timeout ms.
+%% <br />
+%% This function should be called after all sockets associated with
+%% the given context have been closed.<br />
+%% If not it will block the given Timeout amount of time.
+%% <i>For more information see
+%% <a href="http://api.zeromq.org/master:zmq_term">zmq_term</a>.</i>
+%% @end
+%% @spec term(erlzmq_context(), timeout()) -> ok | erlzmq_error()
+-spec term(Context :: erlzmq_context(), Timeout :: timeout()) -> ok | erlzmq_error() | {error, timeout, reference()}.
+
+term(Context, Timeout) ->
+ case erlzmq_nif:term(Context) of
+ Ref when is_reference(Ref) ->
+ receive
+ {Ref, Result} ->
+ Result
+ after Timeout ->
+ {error, timeout, Ref}
+ end;
+ Result ->
+ erlzmq_result(Result)
+ end.
+
+
+%% Private
+
+-spec socket_type(Type :: erlzmq_socket_type()) -> integer().
+
+socket_type(pair) ->
+ ?'ZMQ_PAIR';
+socket_type(pub) ->
+ ?'ZMQ_PUB';
+socket_type(sub) ->
+ ?'ZMQ_SUB';
+socket_type(req) ->
+ ?'ZMQ_REQ';
+socket_type(rep) ->
+ ?'ZMQ_REP';
+socket_type(xreq) ->
+ ?'ZMQ_XREQ';
+socket_type(xrep) ->
+ ?'ZMQ_XREP';
+socket_type(pull) ->
+ ?'ZMQ_PULL';
+socket_type(push) ->
+ ?'ZMQ_PUSH';
+socket_type(xpub) ->
+ ?'ZMQ_XPUB';
+socket_type(xsub) ->
+ ?'ZMQ_XSUB'.
+
+-spec sendrecv_flags(Flags :: erlzmq_send_recv_flags()) -> integer().
+
+sendrecv_flags([]) ->
+ 0;
+sendrecv_flags([{timeout,_}]) ->
+ 0;
+sendrecv_flags([noblock|Rest]) ->
+ ?'ZMQ_NOBLOCK' bor sendrecv_flags(Rest);
+sendrecv_flags([sndmore|Rest]) ->
+ ?'ZMQ_SNDMORE' bor sendrecv_flags(Rest).
+
+-spec option_name(Name :: erlzmq_sockopt()) -> integer().
+
+option_name(hwm) ->
+ ?'ZMQ_HWM';
+option_name(swap) ->
+ ?'ZMQ_SWAP';
+option_name(affinity) ->
+ ?'ZMQ_AFFINITY';
+option_name(identity) ->
+ ?'ZMQ_IDENTITY';
+option_name(subscribe) ->
+ ?'ZMQ_SUBSCRIBE';
+option_name(unsubscribe) ->
+ ?'ZMQ_UNSUBSCRIBE';
+option_name(rate) ->
+ ?'ZMQ_RATE';
+option_name(recovery_ivl) ->
+ ?'ZMQ_RECOVERY_IVL';
+option_name(mcast_loop) ->
+ ?'ZMQ_MCAST_LOOP';
+option_name(sndbuf) ->
+ ?'ZMQ_SNDBUF';
+option_name(rcvbuf) ->
+ ?'ZMQ_RCVBUF';
+option_name(rcvmore) ->
+ ?'ZMQ_RCVMORE';
+option_name(fd) ->
+ ?'ZMQ_FD';
+option_name(events) ->
+ ?'ZMQ_EVENTS';
+option_name(linger) ->
+ ?'ZMQ_LINGER';
+option_name(reconnect_ivl) ->
+ ?'ZMQ_RECONNECT_IVL';
+option_name(backlog) ->
+ ?'ZMQ_BACKLOG';
+option_name(recovery_ivl_msec) ->
+ ?'ZMQ_RECOVERY_IVL_MSEC';
+option_name(reconnect_ivl_max) ->
+ ?'ZMQ_RECONNECT_IVL_MAX'.
+
+
+-spec erlzmq_result(ok) -> ok;
+ ({ok, Value :: term()}) -> Value :: term();
+ ({error, Value :: atom()}) -> Value :: atom();
+ ({error, integer()}) -> {error, erlzmq_error_type()};
+ ({error, erlzmq, integer()}) -> {error, erlzmq_error_type()}.
+
+erlzmq_result(ok) ->
+ ok;
+erlzmq_result({ok, _} = Result) ->
+ Result;
+erlzmq_result({error, Code} = Error) when is_atom(Code) ->
+ Error;
+erlzmq_result({error, Code}) when is_integer(Code) andalso Code > 156384712 ->
+ erlzmq_result({error, erlzmq, Code - 156384712});
+erlzmq_result({error, erlzmq, 1}) ->
+ {error, enotsup};
+erlzmq_result({error, erlzmq, 2}) ->
+ {error, eprotonosupport};
+erlzmq_result({error, erlzmq, 3}) ->
+ {error, enobufs};
+erlzmq_result({error, erlzmq, 4}) ->
+ {error, enetdown};
+erlzmq_result({error, erlzmq, 5}) ->
+ {error, eaddrinuse};
+erlzmq_result({error, erlzmq, 6}) ->
+ {error, eaddrnotavail};
+erlzmq_result({error, erlzmq, 7}) ->
+ {error, econnrefused};
+erlzmq_result({error, erlzmq, 8}) ->
+ {error, einprogress};
+erlzmq_result({error, erlzmq, 51}) ->
+ {error, efsm};
+erlzmq_result({error, erlzmq, 52}) ->
+ {error, enocompatproto};
+erlzmq_result({error, erlzmq, 53}) ->
+ {error, eterm};
+erlzmq_result({error, erlzmq, 54}) ->
+ {error, emthread};
+
+%% errno
+erlzmq_result({error, 1}) ->
+ {error, eperm};
+erlzmq_result({error, 2}) ->
+ {error, enoent};
+erlzmq_result({error, 3}) ->
+ {error, esrch};
+erlzmq_result({error, 4}) ->
+ {error, eintr};
+erlzmq_result({error, 5}) ->
+ {error, eio};
+erlzmq_result({error, 7}) ->
+ {error, enxio};
+erlzmq_result({error, 8}) ->
+ {error, eperm};
+erlzmq_result({error, 9}) ->
+ {error, ebadf};
+erlzmq_result({error, 10}) ->
+ {error, echild};
+erlzmq_result({error, 11}) ->
+ {error, edeadlk};
+erlzmq_result({error, 12}) ->
+ {error, enomem};
+erlzmq_result({error, 13}) ->
+ {error, eacces};
+erlzmq_result({error, 14}) ->
+ {error, efault};
+erlzmq_result({error, 15}) ->
+ {error, enotblk};
+erlzmq_result({error, 16}) ->
+ {error, ebusy};
+erlzmq_result({error, 17}) ->
+ {error, eexist};
+erlzmq_result({error, 18}) ->
+ {error, exdev};
+erlzmq_result({error, 19}) ->
+ {error, enodev};
+erlzmq_result({error, 20}) ->
+ {error, enotdir};
+erlzmq_result({error, 21}) ->
+ {error, eisdir};
+erlzmq_result({error, 22}) ->
+ {error, einval};
+erlzmq_result({error, 23}) ->
+ {error, enfile};
+erlzmq_result({error, 24}) ->
+ {error, emfile};
+erlzmq_result({error, 25}) ->
+ {error, enotty};
+erlzmq_result({error, 26}) ->
+ {error, etxtbsy};
+erlzmq_result({error, 27}) ->
+ {error, efbig};
+erlzmq_result({error, 28}) ->
+ {error, enospc};
+erlzmq_result({error, 29}) ->
+ {error, espipe};
+erlzmq_result({error, 30}) ->
+ {error, erofs};
+erlzmq_result({error, 31}) ->
+ {error, emlink};
+erlzmq_result({error, 32}) ->
+ {error, epipe};
+erlzmq_result({error, 35}) ->
+ {error, eagain};
+erlzmq_result({error, 36}) ->
+ {error, einprogress};
+erlzmq_result({error, 37}) ->
+ {error, ealready};
+erlzmq_result({error, 38}) ->
+ {error, enotsock};
+erlzmq_result({error, 39}) ->
+ {error, edestaddrreq};
+erlzmq_result({error, 40}) ->
+ {error, emsgsize};
+erlzmq_result({error, 41}) ->
+ {error, eprototype};
+erlzmq_result({error, 42}) ->
+ {error, enoprotoopt};
+erlzmq_result({error, 43}) ->
+ {error, eprotonosupport};
+erlzmq_result({error, 44}) ->
+ {error, esocktnosupport};
+erlzmq_result({error, 45}) ->
+ {error, enotsup};
+erlzmq_result({error, 46}) ->
+ {error, epfnosupport};
+erlzmq_result({error, 47}) ->
+ {error, eafnosupport};
+erlzmq_result({error, 48}) ->
+ {error, eaddrinuse};
+erlzmq_result({error, 49}) ->
+ {error, eaddrnotavail};
+erlzmq_result({error, 50}) ->
+ {error, enetdown};
+erlzmq_result({error, 51}) ->
+ {error, enetunreach};
+erlzmq_result({error, 52}) ->
+ {error, enetreset};
+erlzmq_result({error, 53}) ->
+ {error, econnaborted};
+erlzmq_result({error, 54}) ->
+ {error, econnreset};
+erlzmq_result({error, 55}) ->
+ {error, enobufs};
+erlzmq_result({error, 56}) ->
+ {error, eisconn};
+erlzmq_result({error, 57}) ->
+ {error, enotconn};
+erlzmq_result({error, 58}) ->
+ {error, eshutdown};
+erlzmq_result({error, 59}) ->
+ {error, etoomanyrefs};
+erlzmq_result({error, 60}) ->
+ {error, etimedout};
+erlzmq_result({error, 61}) ->
+ {error, econnrefused};
+erlzmq_result({error, 62}) ->
+ {error, eloop};
+erlzmq_result({error, 63}) ->
+ {error, enametoolong};
+
+erlzmq_result({error, N}) ->
+ {error, {unknown, N}}.
View
6 src/ezmq_nif.erl → src/erlzmq_nif.erl
@@ -1,5 +1,5 @@
%% @hidden
--module(ezmq_nif).
+-module(erlzmq_nif).
-export([context/1, socket/2, bind/2, connect/2, send/3, brecv/2, recv/2, setsockopt/3, getsockopt/2, close/1, term/1]).
@@ -10,9 +10,9 @@
-endif.
init() ->
- case code:which(ezmq_nif) of
+ case code:which(erlzmq_nif) of
Filename when is_list(Filename) ->
- erlang:load_nif(filename:join([filename:dirname(Filename),"../priv/ezmq_drv"]), []);
+ erlang:load_nif(filename:join([filename:dirname(Filename),"../priv/erlzmq_drv"]), []);
Err ->
Err
end.
View
447 src/ezmq.erl
@@ -1,447 +0,0 @@
--module(ezmq).
-%% @headerfile "ezmq.hrl"
--include_lib("ezmq.hrl").
--export([context/0, context/1, socket/2, bind/2, connect/2, send/2, send/3,
- brecv/1, brecv/2, recv/1, recv/2, setsockopt/3, getsockopt/2,
- close/1, term/1, term/2]).
--export_type([ezmq_socket/0, ezmq_context/0]).
-
-%% @equiv context(1)
-%% @spec context() -> {ok, ezmq_context()} | ezmq_error()
--spec context() -> {ok, ezmq_context()} | ezmq_error().
-context() ->
- context(1).
-
-%% @doc Create a new ezmq context with the specified number of io threads.
-%% <br />
-%% If the context can be created an 'ok' tuple containing an
-%% {@type ezmq_context()} handle to the created context is returned;
-%% if not, it returns an 'error' tuple with an {@type ezmq_type_error()}
-%% describing the error.
-%% <br />
-%% The context must be later cleaned up calling {@link ezmq:term/1. term/1}
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq-init">zmq_init</a></i>
-%% @end
-%% @spec context(pos_integer()) -> {ok, ezmq_context()} | ezmq_error()
--spec context(Threads :: pos_integer()) -> {ok, ezmq_context()} | ezmq_error().
-
-context(Threads) when is_integer(Threads) ->
- ezmq_nif:context(Threads).
-
-
-%% @doc Create a socket.
-%% <br />
-%% This functions creates a socket of the given
-%% {@link ezmq_socket_type(). type} and associates it with the given
-%% {@link ezmq_context(). context}.
-%% <br />
-%% If the socket can be created an 'ok' tuple containing a
-%% {@type ezmq_socket()} handle to the created socket is returned;
-%% if not, it returns an {@type ezmq_error()} describing the error.<br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_socket">zmq_socket</a>.</i>
-%% @end
-%% @spec socket(ezmq_context(), ezmq_socket_type()) -> {ok, ezmq_socket()} | ezmq_error()
--spec socket(Context :: ezmq_context(), Type :: ezmq_socket_type()) -> {ok, ezmq_socket()} | ezmq_error().
-
-socket(Context, Type) ->
- ezmq_nif:socket(Context, socket_type(Type)).
-
-%% @doc Accept connections on a socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_bind">zmq_bind</a>.</i>
-%% @end
-%% @spec bind(ezmq_socket(), ezmq_endpoint()) -> ok | ezmq_error()
--spec bind(Socket :: ezmq_socket(), Endpoint :: ezmq_endpoint()) -> ok | ezmq_error().
-
-bind(Socket, Endpoint) ->
- ezmq_result(ezmq_nif:bind(Socket, Endpoint)).
-
-%% @doc Connect a socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_connect">zmq_connect</a>.</i>
-%% @end
-%% @spec connect(ezmq_socket(), ezmq_endpoint()) -> ok | ezmq_error()
--spec connect(Socket :: ezmq_socket(), Endpoint :: ezmq_endpoint()) -> ok | ezmq_error().
-
-connect(Socket, Endpoint) ->
- ezmq_result(ezmq_nif:connect(Socket, Endpoint)).
-
-%% @equiv send(Socket, Msg, [])
-%% @spec send(ezmq_socket(), ezmq_data()) -> ok | ezmq_error()
--spec send(Socket :: ezmq_socket(), Data :: ezmq_data()) -> ok | ezmq_error().
-
-send(Socket, Binary) ->
- send(Socket, Binary, []).
-
-%% @doc Send a message on a socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_send">zmq_send</a>.</i>
-%% @end
-%% @spec send(ezma_socket(), ezmq_data(), ezmq_send_recv_flags()) -> ok | ezmq_error()
--spec send(Socket :: ezmq_socket(), Data :: ezmq_data(), Flags :: ezmq_send_recv_flags()) -> ok | ezmq_error().
-
-send(Socket, Binary, Flags) when is_list(Flags) ->
- ezmq_result(ezmq_nif:send(Socket, Binary, sendrecv_flags(Flags))).
-
-%% @equiv brecv(Socket, 0)
-%% @spec brecv(ezmq_socket()) -> {ok, ezmq_data()} | ezmq_error()
--spec brecv(Socket :: ezmq_socket()) -> {ok, ezmq_data()} | ezmq_error().
-
-brecv(Socket) ->
- ezmq_result(brecv(Socket, [])).
-
-%% @doc Receive a message from a socket in a blocking way.
-%% This function can block the current VM scheduler. <b>DO NOT USE IT UNLESS YOU REALLY KNOW WHAT YOU ARE DOING</b>.
-%% @end
-%% @spec brecv(ezmq_socket(), ezmq_send_recv_flags()) -> {ok, ezmq_data()} | ezmq_error()
--spec brecv(Socket :: ezmq_socket(), Flags :: ezmq_send_recv_flags()) -> {ok, ezmq_data()} | ezmq_error().
-
-brecv(Socket, Flags) when is_list(Flags) ->
- ezmq_result( ezmq_nif:brecv(Socket, sendrecv_flags(Flags))).
-
-
-%% @equiv recv(Socket, 0)
-%% @spec recv(ezmq_socket()) -> {ok, ezmq_data()} | ezmq_error()
--spec recv(Socket :: ezmq_socket()) -> {ok, ezmq_data()} | ezmq_error().
-
-recv(Socket) ->
- recv(Socket, []).
-
-%% @doc Receive a message from a socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_recv">zmq_recv</a>.</i>
-%% @end
-%% @spec recv(ezmq_socket(), ezmq_send_recv_flags()) -> {ok, ezmq_data()} | ezmq_error()
--spec recv(Socket :: ezmq_socket(), Flags :: ezmq_send_recv_flags()) -> {ok, ezmq_data()} | ezmq_error() | {error, timeout, reference()}.
-
-recv(Socket, Flags) when is_list(Flags) ->
- case ezmq_nif:recv(Socket, sendrecv_flags(Flags)) of
- Ref when is_reference(Ref) ->
- Timeout = proplists:get_value(timeout, Flags, infinity),
- receive
- {Ref, Result} ->
- {ok, Result}
- after Timeout ->
- {error, timeout, Ref}
- end;
- Result ->
- ezmq_result(Result)
- end.
-
-%% @doc Set an {@link ezmq_sockopt(). option} associated with a socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_setsockopt">zmq_setsockopt</a>.</i>
-%% @end
-%% @spec setsockopt(ezmq_socket(), ezmq_sockopt(), ezmq_sockopt_value()) -> ok | ezmq_error()
--spec setsockopt(Socket :: ezmq_socket(), Name :: ezmq_sockopt(), ezmq_sockopt_value()) -> ok | ezmq_error().
-
-setsockopt(Socket, Name, Value) ->
- ezmq_result(ezmq_nif:setsockopt(Socket, option_name(Name), Value)).
-
-%% @doc Get an {@link ezmq_sockopt(). option} associated with a socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_getsockopt">zmq_getsockopt</a>.</i>
-%% @end
-%% @spec getsockopt(ezmq_socket(), ezmq_sockopt()) -> {ok, ezmq_sockopt_value()} | ezmq_error()
--spec getsockopt(Socket :: ezmq_socket(), Name :: ezmq_sockopt()) -> {ok, ezmq_sockopt_value()} | ezmq_error().
-
-getsockopt(Socket, Name) ->
- ezmq_result(ezmq_nif:getsockopt(Socket, option_name(Name))).
-
-
-%% @doc Close the given socket.
-%% <br />
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_close">zmq_close</a>.</i>
-%% @end
-%% @spec close(ezmq_socket()) -> ok | ezmq_error()
--spec close(Socket :: ezmq_socket()) -> ok | ezmq_error().
-
-close(Socket) ->
- ezmq_result(ezmq_nif:close(Socket)).
-
-%% @equiv term(Context, infinity)
-%% @spec term(ezmq_context()) -> ok | ezmq_error()
--spec term(Context :: ezmq_context()) -> ok | ezmq_error().
-
-term(Context) ->
- term(Context, infinity).
-
-
-%% @doc Terminate the given context waiting up to Timeout ms.
-%% <br />
-%% This function should be called after all sockets associated with
-%% the given context have been closed.<br />
-%% If not it will block the given Timeout amount of time.
-%% <i>For more information see
-%% <a href="http://api.zeromq.org/master:zmq_term">zmq_term</a>.</i>
-%% @end
-%% @spec term(ezmq_context(), timeout()) -> ok | ezmq_error()
--spec term(Context :: ezmq_context(), Timeout :: timeout()) -> ok | ezmq_error() | {error, timeout, reference()}.
-
-term(Context, Timeout) ->
- case ezmq_nif:term(Context) of
- Ref when is_reference(Ref) ->
- receive
- {Ref, Result} ->
- Result
- after Timeout ->
- {error, timeout, Ref}
- end;
- Result ->
- ezmq_result(Result)
- end.
-
-
-%% Private
-
--spec socket_type(Type :: ezmq_socket_type()) -> integer().
-
-socket_type(pair) ->
- ?'ZMQ_PAIR';
-socket_type(pub) ->
- ?'ZMQ_PUB';
-socket_type(sub) ->
- ?'ZMQ_SUB';
-socket_type(req) ->
- ?'ZMQ_REQ';
-socket_type(rep) ->
- ?'ZMQ_REP';
-socket_type(xreq) ->
- ?'ZMQ_XREQ';
-socket_type(xrep) ->
- ?'ZMQ_XREP';
-socket_type(pull) ->
- ?'ZMQ_PULL';
-socket_type(push) ->
- ?'ZMQ_PUSH';
-socket_type(xpub) ->
- ?'ZMQ_XPUB';
-socket_type(xsub) ->
- ?'ZMQ_XSUB'.
-
--spec sendrecv_flags(Flags :: ezmq_send_recv_flags()) -> integer().
-
-sendrecv_flags([]) ->
- 0;
-sendrecv_flags([{timeout,_}]) ->
- 0;
-sendrecv_flags([noblock|Rest]) ->
- ?'ZMQ_NOBLOCK' bor sendrecv_flags(Rest);
-sendrecv_flags([sndmore|Rest]) ->
- ?'ZMQ_SNDMORE' bor sendrecv_flags(Rest).
-
--spec option_name(Name :: ezmq_sockopt()) -> integer().
-
-option_name(hwm) ->
- ?'ZMQ_HWM';
-option_name(swap) ->
- ?'ZMQ_SWAP';
-option_name(affinity) ->
- ?'ZMQ_AFFINITY';
-option_name(identity) ->
- ?'ZMQ_IDENTITY';
-option_name(subscribe) ->
- ?'ZMQ_SUBSCRIBE';
-option_name(unsubscribe) ->
- ?'ZMQ_UNSUBSCRIBE';
-option_name(rate) ->
- ?'ZMQ_RATE';
-option_name(recovery_ivl) ->
- ?'ZMQ_RECOVERY_IVL';
-option_name(mcast_loop) ->
- ?'ZMQ_MCAST_LOOP';
-option_name(sndbuf) ->
- ?'ZMQ_SNDBUF';
-option_name(rcvbuf) ->
- ?'ZMQ_RCVBUF';
-option_name(rcvmore) ->
- ?'ZMQ_RCVMORE';
-option_name(fd) ->
- ?'ZMQ_FD';
-option_name(events) ->
- ?'ZMQ_EVENTS';
-option_name(linger) ->
- ?'ZMQ_LINGER';
-option_name(reconnect_ivl) ->
- ?'ZMQ_RECONNECT_IVL';
-option_name(backlog) ->
- ?'ZMQ_BACKLOG';
-option_name(recovery_ivl_msec) ->
- ?'ZMQ_RECOVERY_IVL_MSEC';
-option_name(reconnect_ivl_max) ->
- ?'ZMQ_RECONNECT_IVL_MAX'.
-
-
--spec ezmq_result(ok) -> ok;
- ({ok, Value :: term()}) -> Value :: term();
- ({error, Value :: atom()}) -> Value :: atom();
- ({error, integer()}) -> {error, ezmq_error_type()};
- ({error, ezmq, integer()}) -> {error, ezmq_error_type()}.
-
-ezmq_result(ok) ->
- ok;
-ezmq_result({ok, _} = Result) ->
- Result;
-ezmq_result({error, Code} = Error) when is_atom(Code) ->
- Error;
-ezmq_result({error, Code}) when is_integer(Code) andalso Code > 156384712 ->
- ezmq_result({error, ezmq, Code - 156384712});
-ezmq_result({error, ezmq, 1}) ->
- {error, enotsup};
-ezmq_result({error, ezmq, 2}) ->
- {error, eprotonosupport};
-ezmq_result({error, ezmq, 3}) ->
- {error, enobufs};
-ezmq_result({error, ezmq, 4}) ->
- {error, enetdown};
-ezmq_result({error, ezmq, 5}) ->
- {error, eaddrinuse};
-ezmq_result({error, ezmq, 6}) ->
- {error, eaddrnotavail};
-ezmq_result({error, ezmq, 7}) ->
- {error, econnrefused};
-ezmq_result({error, ezmq, 8}) ->
- {error, einprogress};
-ezmq_result({error, ezmq, 51}) ->
- {error, efsm};
-ezmq_result({error, ezmq, 52}) ->
- {error, enocompatproto};
-ezmq_result({error, ezmq, 53}) ->
- {error, eterm};
-ezmq_result({error, ezmq, 54}) ->
- {error, emthread};
-
-%% errno
-ezmq_result({error, 1}) ->
- {error, eperm};
-ezmq_result({error, 2}) ->
- {error, enoent};
-ezmq_result({error, 3}) ->
- {error, esrch};
-ezmq_result({error, 4}) ->
- {error, eintr};
-ezmq_result({error, 5}) ->
- {error, eio};
-ezmq_result({error, 7}) ->
- {error, enxio};
-ezmq_result({error, 8}) ->
- {error, eperm};
-ezmq_result({error, 9}) ->
- {error, ebadf};
-ezmq_result({error, 10}) ->
- {error, echild};
-ezmq_result({error, 11}) ->
- {error, edeadlk};
-ezmq_result({error, 12}) ->
- {error, enomem};
-ezmq_result({error, 13}) ->
- {error, eacces};
-ezmq_result({error, 14}) ->
- {error, efault};
-ezmq_result({error, 15}) ->
- {error, enotblk};
-ezmq_result({error, 16}) ->
- {error, ebusy};
-ezmq_result({error, 17}) ->
- {error, eexist};
-ezmq_result({error, 18}) ->
- {error, exdev};
-ezmq_result({error, 19}) ->
- {error, enodev};
-ezmq_result({error, 20}) ->
- {error, enotdir};
-ezmq_result({error, 21}) ->
- {error, eisdir};
-ezmq_result({error, 22}) ->
- {error, einval};
-ezmq_result({error, 23}) ->
- {error, enfile};
-ezmq_result({error, 24}) ->
- {error, emfile};
-ezmq_result({error, 25}) ->
- {error, enotty};
-ezmq_result({error, 26}) ->
- {error, etxtbsy};
-ezmq_result({error, 27}) ->
- {error, efbig};
-ezmq_result({error, 28}) ->
- {error, enospc};
-ezmq_result({error, 29}) ->
- {error, espipe};
-ezmq_result({error, 30}) ->
- {error, erofs};
-ezmq_result({error, 31}) ->
- {error, emlink};
-ezmq_result({error, 32}) ->
- {error, epipe};
-ezmq_result({error, 35}) ->
- {error, eagain};
-ezmq_result({error, 36}) ->
- {error, einprogress};
-ezmq_result({error, 37}) ->
- {error, ealready};
-ezmq_result({error, 38}) ->
- {error, enotsock};
-ezmq_result({error, 39}) ->
- {error, edestaddrreq};
-ezmq_result({error, 40}) ->
- {error, emsgsize};
-ezmq_result({error, 41}) ->
- {error, eprototype};
-ezmq_result({error, 42}) ->
- {error, enoprotoopt};
-ezmq_result({error, 43}) ->
- {error, eprotonosupport};
-ezmq_result({error, 44}) ->
- {error, esocktnosupport};
-ezmq_result({error, 45}) ->
- {error, enotsup};
-ezmq_result({error, 46}) ->
- {error, epfnosupport};
-ezmq_result({error, 47}) ->
- {error, eafnosupport};
-ezmq_result({error, 48}) ->
- {error, eaddrinuse};
-ezmq_result({error, 49}) ->
- {error, eaddrnotavail};
-ezmq_result({error, 50}) ->
- {error, enetdown};
-ezmq_result({error, 51}) ->
- {error, enetunreach};
-ezmq_result({error, 52}) ->
- {error, enetreset};
-ezmq_result({error, 53}) ->
- {error, econnaborted};
-ezmq_result({error, 54}) ->
- {error, econnreset};
-ezmq_result({error, 55}) ->
- {error, enobufs};
-ezmq_result({error, 56}) ->
- {error, eisconn};
-ezmq_result({error, 57}) ->
- {error, enotconn};
-ezmq_result({error, 58}) ->
- {error, eshutdown};
-ezmq_result({error, 59}) ->
- {error, etoomanyrefs};
-ezmq_result({error, 60}) ->
- {error, etimedout};
-ezmq_result({error, 61}) ->
- {error, econnrefused};
-ezmq_result({error, 62}) ->
- {error, eloop};
-ezmq_result({error, 63}) ->
- {error, enametoolong};
-
-ezmq_result({error, N}) ->
- {error, {unknown, N}}.
View
17 src/ezmq_app.erl
@@ -1,17 +0,0 @@
-%% @hidden
--module(ezmq_app).
-
--behaviour(application).
-
-%% Application callbacks
--export([start/2, stop/1]).
-
-%% ===================================================================
-%% Application callbacks
-%% ===================================================================
-
-start(_StartType, _StartArgs) ->
- ezmq_sup:start_link().
-
-stop(_State) ->
- ok.
View
28 src/ezmq_sup.erl
@@ -1,28 +0,0 @@
-%% @hidden
--module(ezmq_sup).
-
--behaviour(supervisor).
-
-%% API
--export([start_link/0]).
-
-%% Supervisor callbacks
--export([init/1]).
-
-%% Helper macro for declaring children of supervisor
--define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}).
-
-%% ===================================================================
-%% API functions
-%% ===================================================================
-
-start_link() ->
- supervisor:start_link({local, ?MODULE}, ?MODULE, []).
-
-%% ===================================================================
-%% Supervisor callbacks
-%% ===================================================================
-
-init([]) ->
- {ok, { {one_for_one, 5, 10}, []} }.
-
View
76 test/ezmq_test.erl → test/erlzmq_test.erl
@@ -1,30 +1,30 @@
--module(ezmq_test).
+-module(erlzmq_test).
-include_lib("eunit/include/eunit.hrl").
-export([worker/2]).
hwm_test() ->
- {ok, C} = ezmq:context(),
- {ok, S1} = ezmq:socket(C, pull),
- {ok, S2} = ezmq:socket(C, push),
+ {ok, C} = erlzmq:context(),
+ {ok, S1} = erlzmq:socket(C, pull),
+ {ok, S2} = erlzmq:socket(C, push),
- ok = ezmq:setsockopt(S2, linger, 0),
- ok = ezmq:setsockopt(S2, hwm, 5),
+ ok = erlzmq:setsockopt(S2, linger, 0),
+ ok = erlzmq:setsockopt(S2, hwm, 5),
- ok = ezmq:bind(S1, "tcp://127.0.0.1:5858"),
- ok = ezmq:connect(S2, "tcp://127.0.0.1:5858"),
+ ok = erlzmq:bind(S1, "tcp://127.0.0.1:5858"),
+ ok = erlzmq:connect(S2, "tcp://127.0.0.1:5858"),
ok = hwm_loop(10, S2),
- ?assertMatch({ok, <<"test">>}, ezmq:recv(S1)),
- ?assertMatch(ok, ezmq:send(S2, <<"test">>)).
+ ?assertMatch({ok, <<"test">>}, erlzmq:recv(S1)),
+ ?assertMatch(ok, erlzmq:send(S2, <<"test">>)).
hwm_loop(0, _S) ->
ok;
hwm_loop(N, S) when N > 5 ->
- ?assertMatch(ok, ezmq:send(S, <<"test">>, [noblock])),
+ ?assertMatch(ok, erlzmq:send(S, <<"test">>, [noblock])),
hwm_loop(N-1, S);
hwm_loop(N, S) ->
- ?assertMatch({error, _} ,ezmq:send(S, <<"test">>, [noblock])),
+ ?assertMatch({error, _} ,erlzmq:send(S, <<"test">>, [noblock])),
hwm_loop(N-1, S).
@@ -52,32 +52,32 @@ shutdown_stress_test() ->
shutdown_stress_loop(0) ->
ok;
shutdown_stress_loop(N) ->
- {ok, C} = ezmq:context(7),
- {ok, S1} = ezmq:socket(C, rep),
+ {ok, C} = erlzmq:context(7),
+ {ok, S1} = erlzmq:socket(C, rep),
?assertMatch(ok, shutdown_stress_worker_loop(100, C)),
?assertMatch(ok, join_procs(100)),
- ?assertMatch(ok, ezmq:close(S1)),
- ?assertMatch(ok, ezmq:term(C)),
+ ?assertMatch(ok, erlzmq:close(S1)),
+ ?assertMatch(ok, erlzmq:term(C)),
shutdown_stress_loop(N-1).
shutdown_no_blocking_test() ->
- {ok, C} = ezmq:context(),
- {ok, S} = ezmq:socket(C, pub),
- ezmq:close(S),
- ?assertEqual(ok, ezmq:term(C, 500)).
+ {ok, C} = erlzmq:context(),
+ {ok, S} = erlzmq:socket(C, pub),
+ erlzmq:close(S),
+ ?assertEqual(ok, erlzmq:term(C, 500)).
shutdown_blocking_test() ->
- {ok, C} = ezmq:context(),
- {ok, _S} = ezmq:socket(C, pub),
- ?assertMatch({error, timeout, _}, ezmq:term(C, 500)).
+ {ok, C} = erlzmq:context(),
+ {ok, _S} = erlzmq:socket(C, pub),
+ ?assertMatch({error, timeout, _}, erlzmq:term(C, 500)).
shutdown_blocking_unblocking_test() ->
- {ok, C} = ezmq:context(),
- {ok, S} = ezmq:socket(C, pub),
- V = ezmq:term(C, 500),
+ {ok, C} = erlzmq:context(),
+ {ok, S} = erlzmq:socket(C, pub),
+ V = erlzmq:term(C, 500),
?assertMatch({error, timeout, _}, V),
{error, timeout, Ref} = V,
- ezmq:close(S),
+ erlzmq:close(S),
receive
{Ref, ok} ->
ok
@@ -94,29 +94,29 @@ join_procs(N) ->
shutdown_stress_worker_loop(0, _) ->
ok;
shutdown_stress_worker_loop(N, C) ->
- {ok, S2} = ezmq:socket(C, sub),
+ {ok, S2} = erlzmq:socket(C, sub),
spawn(?MODULE, worker, [self(), S2]),
shutdown_stress_worker_loop(N-1, C).
worker(Pid, S) ->
- ?assertMatch(ok, ezmq:connect(S, "tcp://127.0.0.1:5557")),
- ?assertMatch(ok, ezmq:close(S)),
+ ?assertMatch(ok, erlzmq:connect(S, "tcp://127.0.0.1:5557")),
+ ?assertMatch(ok, erlzmq:close(S)),
Pid ! proc_end.
create_bound_pair(Ctx, Type1, Type2, Transport) ->
- {ok, S1} = ezmq:socket(Ctx, Type1),
- {ok, S2} = ezmq:socket(Ctx, Type2),
- ok = ezmq:bind(S1, Transport),
- ok = ezmq:connect(S2, Transport),
+ {ok, S1} = erlzmq:socket(Ctx, Type1),
+ {ok, S2} = erlzmq:socket(Ctx, Type2),
+ ok = erlzmq:bind(S1, Transport),
+ ok = erlzmq:connect(S2, Transport),
{S1, S2}.
ping_pong({S1, S2}, Msg) ->
- ok = ezmq:send(S1, Msg),
- ?assertMatch({ok, Msg}, ezmq:recv(S2)),
- ok = ezmq:send(S2, Msg).
+ ok = erlzmq:send(S1, Msg),
+ ?assertMatch({ok, Msg}, erlzmq:recv(S2)),
+ ok = erlzmq:send(S2, Msg).
basic_tests(Transport, Type1, Type2) ->
- {ok, C} = ezmq:context(1),
+ {ok, C} = erlzmq:context(1),
{S1, S2} = create_bound_pair(C, Type1, Type2, Transport),
ping_pong({S1, S2}, <<"XXX">>).

0 comments on commit baa8345

Please sign in to comment.
Something went wrong with that request. Please try again.