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

add more macros and do some modification for libzmq 3 #54

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion c_src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ZMQ_FLAGS=
endif

ifndef ZEROMQ_VERSION
ZEROMQ_VERSION=v3.1.0
ZEROMQ_VERSION=master
endif

all: $(DEPS)/zeromq3/src/.libs/libzmq.a
Expand Down
28 changes: 23 additions & 5 deletions c_src/erlzmq_nif.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@

#define ERLZMQ_MAX_CONCURRENT_REQUESTS 16384

// add more macro for 3.x
# define more_t int
# define ZMQ_POLL_MSEC 1 // zmq_poll is msec

static ErlNifResourceType* erlzmq_nif_resource_context;
static ErlNifResourceType* erlzmq_nif_resource_socket;

Expand Down Expand Up @@ -337,6 +341,7 @@ NIF(erlzmq_nif_setsockopt)
case ZMQ_IDENTITY:
case ZMQ_SUBSCRIBE:
case ZMQ_UNSUBSCRIBE:
case ZMQ_TCP_ACCEPT_FILTER:
if (! enif_inspect_iolist_as_binary(env, argv[2], &value_binary)) {
return enif_make_badarg(env);
}
Expand All @@ -348,8 +353,8 @@ NIF(erlzmq_nif_setsockopt)
case ZMQ_RCVHWM:
case ZMQ_RATE:
case ZMQ_RECOVERY_IVL:
case ZMQ_RCVBUF:
case ZMQ_SNDBUF:
case ZMQ_RCVBUF:
case ZMQ_LINGER:
case ZMQ_RECONNECT_IVL:
case ZMQ_RECONNECT_IVL_MAX:
Expand All @@ -358,6 +363,13 @@ NIF(erlzmq_nif_setsockopt)
case ZMQ_RCVTIMEO:
case ZMQ_SNDTIMEO:
case ZMQ_IPV4ONLY:
case ZMQ_DELAY_ATTACH_ON_CONNECT:
case ZMQ_ROUTER_MANDATORY:
case ZMQ_XPUB_VERBOSE:
case ZMQ_TCP_KEEPALIVE:
case ZMQ_TCP_KEEPALIVE_IDLE:
case ZMQ_TCP_KEEPALIVE_CNT:
case ZMQ_TCP_KEEPALIVE_INTVL:
if (! enif_get_int(env, argv[2], &value_int)) {
return enif_make_badarg(env);
}
Expand Down Expand Up @@ -427,6 +439,9 @@ NIF(erlzmq_nif_getsockopt)
enif_make_uint64(env, value_uint64));
// binary
case ZMQ_IDENTITY:
case ZMQ_SUBSCRIBE:
case ZMQ_UNSUBSCRIBE:
case ZMQ_TCP_ACCEPT_FILTER:
option_len = sizeof(option_value);
enif_mutex_lock(socket->mutex);
if (zmq_getsockopt(socket->socket_zmq, option_name,
Expand All @@ -440,8 +455,6 @@ NIF(erlzmq_nif_getsockopt)
return enif_make_tuple2(env, enif_make_atom(env, "ok"),
enif_make_binary(env, &value_binary));
// int
case ZMQ_TYPE:
case ZMQ_RCVMORE:
case ZMQ_SNDHWM:
case ZMQ_RCVHWM:
case ZMQ_RATE:
Expand All @@ -456,8 +469,13 @@ NIF(erlzmq_nif_getsockopt)
case ZMQ_RCVTIMEO:
case ZMQ_SNDTIMEO:
case ZMQ_IPV4ONLY:
case ZMQ_EVENTS:
case ZMQ_FD: // FIXME: ZMQ_FD returns SOCKET on Windows
case ZMQ_DELAY_ATTACH_ON_CONNECT:
case ZMQ_ROUTER_MANDATORY:
case ZMQ_XPUB_VERBOSE:
case ZMQ_TCP_KEEPALIVE:
case ZMQ_TCP_KEEPALIVE_IDLE:
case ZMQ_TCP_KEEPALIVE_CNT:
case ZMQ_TCP_KEEPALIVE_INTVL:
option_len = sizeof(value_int);
enif_mutex_lock(socket->mutex);
if (zmq_getsockopt(socket->socket_zmq, option_name,
Expand Down
75 changes: 60 additions & 15 deletions include/erlzmq.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
-define('ZMQ_LINGER', 17).
-define('ZMQ_RECONNECT_IVL', 18).
-define('ZMQ_BACKLOG', 19).
-define('ZMQ_RECOVERY_IVL_MSEC', 20).
-define('ZMQ_RECONNECT_IVL_MAX', 21).
-define('ZMQ_MAXMSGSIZE', 22).
-define('ZMQ_SNDHWM', 23).
Expand All @@ -38,22 +37,35 @@
-define('ZMQ_SNDTIMEO', 28).
-define('ZMQ_IPV4ONLY', 31).
-define('ZMQ_LAST_ENDPOINT', 32).

% Message options
-define('ZMQ_MORE', 1).
-define('ZMQ_ROUTER_MANDATORY', 33).
-define('ZMQ_TCP_KEEPALIVE', 34).
-define('ZMQ_TCP_KEEPALIVE_CNT', 35).
-define('ZMQ_TCP_KEEPALIVE_IDLE', 36).
-define('ZMQ_TCP_KEEPALIVE_INTVL', 37).
-define('ZMQ_TCP_ACCEPT_FILTER', 38).
-define('ZMQ_DELAY_ATTACH_ON_CONNECT', 39).
-define('ZMQ_XPUB_VERBOSE', 40).
-define('ZMQ_ROUTER_RAW', 41).
-define('ZMQ_IPV6', 42).

% Message options
-define('ZMQ_MORE', 1).

% ZMQ send/recv flags
-define('ZMQ_DONTWAIT', 1).
-define('ZMQ_SNDMORE', 2).
-define('ZMQ_SNDMORE', 2).

%% Types

%% @type erlzmq_socket_type() = pair | pub | sub | req | rep | xreq | xrep |
%% pull | push | xpub | xsub.
%% 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 erlzmq_socket_type() :: pair | pub | sub | req | rep | dealer | router | xreq | xrep |
pull | push | xpub | xsub.

%% @type erlzmq_endpoint() = string().
%% The endpoint argument is a string consisting of two parts:
%% <b>transport://address</b><br />
%% The following transports are defined:
Expand All @@ -64,6 +76,16 @@
%% <a href="http://api.zeromq.org/master:zmq_connect">zmq_connect</a></i>
-type erlzmq_endpoint() :: string().

%% @type errno() = eperm | enoent | srch | eintr | eio | enxio | ebad |
%% echild | edeadlk | enomem | eacces | efault | enotblk | ebusy | eexist |
%% exdev | enodev | enotdir | eisdir | einval | enfile | emfile | enotty |
%% etxtbsy | efbig | enospc | espipe | erofs | emlink | epipe | eagain |
%% einprogress | ealready | enotsock | edestaddrreq | emsgsize |
%% eprototype | enoprotoopt | eprotonosupport | esocktnosupport |
%% enotsup | epfnosupport | eafnosupport | eaddrinuse | eaddrnotavail |
%% enetdown | enetunreach | enetreset | econnaborted | econnreset |
%% enobufs | eisconn | enotconn | eshutdown | etoomanyrefs | etimedout |
%% econnrefused | eloop | enametoolong.
%% Standard error atoms.
-type errno() :: eperm | enoent | srch | eintr | eio | enxio | ebad |
echild | edeadlk | enomem | eacces | efault | enotblk |
Expand All @@ -78,50 +100,73 @@
enotconn | eshutdown | etoomanyrefs |
etimedout | econnrefused | eloop | enametoolong.

%% @type erlzmq_error_type() = enotsup | eprotonosupport | enobufs |
%% enetdown | eaddrinuse | eaddnotavail | econnrefused | einprogress |
%% efsm | enocompatproto | eterm | emthread | errno() |
%% {unknown, integer()}.
%% Possible error types.
-type erlzmq_error_type() :: enotsup | eprotonosupport | enobufs | enetdown |
eaddrinuse | eaddnotavail | econnrefused |
eaddrinuse | eaddnotavail | econnrefused |
einprogress | efsm | enocompatproto | eterm |
emthread | errno() | {unknown, integer()}.

%% @type erlzmq_error() = {error, erlzmq_error_type()}.
%% Error tuples returned by most API functions.
-type erlzmq_error() :: {error, erlzmq_error_type()}.

%% @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 erlzmq_context() = binary().
%% An opaque handle to an erlzmq context.
-opaque erlzmq_context() :: binary().

%% @type erlzmq_socket() = binary().
%% An opaque handle to an erlzmq socket.
-opaque erlzmq_socket() :: {pos_integer(), binary()}.

%% @type erlzmq_send_recv_flag() = dontwait | 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 erlzmq_send_recv_flag() :: dontwait | sndmore | recvmore | {timeout, timeout()}.

%% @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 erlzmq:recv/2. recv/2}
-type erlzmq_send_recv_flags() :: list(erlzmq_send_recv_flag()).

%% @type erlzmq_sockopt() :: affinity | indentity | subscribe | unsubsrcibe |
%% rate | recovery_ivl | sndbuf | rcvbuf | rcvmore |
%% fd | events | type | linger | reconnect_ivl |
%% backlog | reconnect_ivl_max | maxmsgsize | sndhwm |
%% rcvhwm | multicast_hops | rcvtimeo | sndtimeo |
%% ipv4only | last_endpoint | router_mandatory |
%% tcp_keepalive | tcp_keepalive_cnt |
%% tcp_keepalive_idle | tcp_keepalive_intvl |
%% tcp_accept_filter | delay_attach_on_connect |
%% xpub_verbose | router_raw | ivp6.
%% 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 erlzmq_sockopt() :: affinity | identity | subscribe |
unsubscribe | rate | recovery_ivl | sndbuf |
rcvbuf | rcvmore | fd | events | linger |
reconnect_ivl | backlog |reconnect_ivl_max
| maxmsgsize | sndhwm | rcvhwm |
multicast_hops | rcvtimeo | sndtimeo |
ipv4only.


-type erlzmq_sockopt() :: affinity | indentity | subscribe | unsubsrcibe |
rate | recovery_ivl | sndbuf | rcvbuf | rcvmore |
fd | events | type | linger | reconnect_ivl |
backlog | reconnect_ivl_max | maxmsgsize | sndhwm |
rcvhwm | multicast_hops | rcvtimeo | sndtimeo |
ipv4only | last_endpoint | router_mandatory |
tcp_keepalive | tcp_keepalive_cnt |
tcp_keepalive_idle | tcp_keepalive_intvl |
tcp_accept_filter | delay_attach_on_connect |
xpub_verbose | router_raw | ivp6.

%% @type erlzmq_sockopt_value() = integer() | iolist().
%% Possible option values for {@link erlzmq:setsockopt/3. setsockopt/3}.
-type erlzmq_sockopt_value() :: integer() | iolist().