Skip to content

Commit

Permalink
Add. Support ZeroMQ version 4.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
moteus committed May 25, 2017
1 parent 72dbca0 commit 5c635ef
Show file tree
Hide file tree
Showing 12 changed files with 328 additions and 34 deletions.
2 changes: 1 addition & 1 deletion LICENCE.txt
@@ -1,4 +1,4 @@
Copyright (C) 2013-2014 Alexey Melnichuk.
Copyright (C) 2013-2017 Alexey Melnichuk.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 8 additions & 8 deletions README.md
@@ -1,4 +1,4 @@
#Lua binding to [ZeroMQ](http://zeromq.org) library.
# Lua binding to [ZeroMQ](http://zeromq.org) library.

[![Build Status](https://travis-ci.org/zeromq/lzmq.png?branch=master)](https://travis-ci.org/zeromq/lzmq)
[![Build Status](https://buildhive.cloudbees.com/job/zeromq/job/lzmq/badge/icon)](https://buildhive.cloudbees.com/job/zeromq/job/lzmq/)
Expand All @@ -9,10 +9,10 @@ Support ZeroMQ version 3.2.x/4.x<br/>
This library is not dropin replacement for [lua-zmq](https://github.com/Neopallium/lua-zmq) library.<br/>
This library has C and FFI version of binding.

##Source Code
## Source Code
https://github.com/zeromq/lzmq

##Install
## Install
If you plan use `lzmq.threads` module then you should also install [llthreads2](https://github.com/moteus/lua-llthreads2)<br/>

* Using *LuaRocks*:<br/>
Expand All @@ -23,17 +23,17 @@ If you plan use `lzmq.threads` module then you should also install [llthreads2](
`luadist install lua-llthreads2` or `luadist install lua-llthreads2-compat`<br/>
`luadist install lzmq` or `luadist install lzmq-ffi`<br/>

##API
## API
This is short [API](http://moteus.github.io/lzmq/index.html) description.<br/>
See also [exampes](https://github.com/moteus/lzmq-zguide) from [OMQ - The Guide](http://zguide.zeromq.org).<br/>

##Performance
## Performance
To run same test you should copy original performance tests to `exampes/perf2/libzmq`
and run `runner.lua` from `exampes/perf2`. For now it require LuaJIT and exists
C and FFI version of `lzmq` library.<br/>
Of course you can run any test manually.

###Inproc Throughput Test:
### Inproc Throughput Test:

message size: 30 [B]<br/>
message count: 10000<br/>
Expand All @@ -52,7 +52,7 @@ mean throughput [Mb/s]:<br/>
| 9 |397.022 |311.931 |415.945 |187.749 |244.998 |
| 10|438.196 |302.763 |412.229 |189.813 |255.646 |

###Inproc Latency Test:
### Inproc Latency Test:

message size: 1 [B]<br/>
message count: 10000<br/>
Expand All @@ -72,7 +72,7 @@ average latency [us]:<br/>
| 10|95.635 |97.946 |95.684 |96.429 |92.629 |

----
###Incompatibility list with lua-zmq (this is not full)
### Incompatibility list with lua-zmq (this is not full)

| Feature | lua-zmq | lzmq |
|----------------------|------------------------|--------------------------|
Expand Down
10 changes: 5 additions & 5 deletions lakeconfig.lua
Expand Up @@ -247,23 +247,23 @@ end)

lake.define_need('zmq3', function()
return {
incdir = J(ENV.ZMQ3_DIR, 'include');
libdir = J(ENV.ZMQ3_DIR, 'lib');
incdir = J(assert(ENV.ZMQ3_DIR), 'include');
libdir = J(assert(ENV.ZMQ3_DIR), 'lib');
libs = {'libzmq'};
}
end)

lake.define_need('zmq4', function()
return {
incdir = J(ENV.ZMQ4_DIR, 'include');
libdir = J(ENV.ZMQ4_DIR, 'lib');
incdir = J(assert(ENV.ZMQ4_DIR), 'include');
libdir = J(assert(ENV.ZMQ4_DIR), 'lib');
libs = {'libzmq'};
}
end)

lake.define_need('stdint', function()
if not MSVC then return {} end
return {
incdir = J(ENV.CPPLIB_DIR, 'msvc');
incdir = J(assert(ENV.CPPLIB_DIR), 'msvc');
}
end)
10 changes: 7 additions & 3 deletions msvc/luazmq.vcproj
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Version="9,00"
Name="luazmq"
ProjectGUID="{C372E4D2-5680-4793-A0D9-6488413AC277}"
RootNamespace="luazmq"
Expand Down Expand Up @@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="e:\VCL\cpplib\zmq\4.1.dev\include;&quot;$(LUA_DIR)\include&quot;;&quot;$(CPPLIB_DIR)\msvc&quot;"
AdditionalIncludeDirectories="d:\VCL\cpplib\zmq\4.2.2\include;&quot;$(LUA_DIR)\include&quot;;&quot;$(CPPLIB_DIR)\msvc&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LUAZMQ_EXPORTS;LUAZMQ_USE_SEND_AS_BUF;LUAZMQ_DEBUG"
MinimalRebuild="true"
BasicRuntimeChecks="3"
Expand All @@ -64,7 +64,7 @@
AdditionalDependencies="libzmq.lib lua5.1.lib"
OutputFile="$(OutDir)\lzmq.dll"
LinkIncremental="2"
AdditionalLibraryDirectories="e:\VCL\cpplib\zmq\4.1.dev\lib;&quot;$(LUA_DIR)\lib&quot;"
AdditionalLibraryDirectories="d:\VCL\cpplib\zmq\4.2.2\lib;&quot;$(LUA_DIR)\lib&quot;"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
Expand Down Expand Up @@ -247,6 +247,10 @@
RelativePath="..\src\zsocket.h"
>
</File>
<File
RelativePath="..\src\zsupport.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"
Expand Down
4 changes: 4 additions & 0 deletions script/getsockopt.lua
@@ -1,6 +1,10 @@
package.path = "..\\src\\lua\\?.lua;" .. package.path

local api = require "lzmq.ffi.api"
local printf = function(...) print(string.format(...)) end

print(api.zmq_version())

local function rfit(str, n)
if #str >= n then return str end
return str .. (' '):rep(n-#str)
Expand Down
22 changes: 19 additions & 3 deletions src/lua/lzmq/ffi.lua
@@ -1,14 +1,17 @@
--
-- Author: Alexey Melnichuk <mimir@newmail.ru>
--
-- Copyright (C) 2013-2014 Alexey Melnichuk <mimir@newmail.ru>
-- Copyright (C) 2013-2017 Alexey Melnichuk <mimir@newmail.ru>
--
-- Licensed according to the included 'LICENCE' document
--
-- This file is part of lua-lzqm library.
--

local LZMQ_VERSION = "0.4.3"
local LZMQ_VERSION = "0.4.4-dev"
local LZMQ_NAME = "lzmq.ffi"
local LZMQ_LICENSE = "MIT"
local LZMQ_COPYRIGHT = "Copyright (c) 2013-2017 Alexey Melnichuk"

local lua_version_t
local function lua_version()
Expand Down Expand Up @@ -1199,7 +1202,10 @@ end

do -- zmq

zmq._VERSION = LZMQ_VERSION
zmq._VERSION = LZMQ_VERSION
zmq._NAME = LZMQ_NAME
zmq._LICENSE = LZMQ_LICENSE
zmq._COPYRIGHT = LZMQ_COPYRIGHT

function zmq.version(unpack)
local mj,mn,pt = api.zmq_version()
Expand Down Expand Up @@ -1319,6 +1325,16 @@ end

end

if api.zmq_curve_public then

function zmq.curve_public(...)
local pub = api.zmq_curve_public(...)
if pub == -1 then return nil, zerror() end
return pub
end

end

zmq.utils = {
stopwatch = function() return StopWatch:new() end
}
Expand Down
44 changes: 41 additions & 3 deletions src/lua/lzmq/ffi/api.lua
@@ -1,7 +1,7 @@
--
-- Author: Alexey Melnichuk <mimir@newmail.ru>
--
-- Copyright (C) 2013-2014 Alexey Melnichuk <mimir@newmail.ru>
-- Copyright (C) 2013-2017 Alexey Melnichuk <mimir@newmail.ru>
--
-- Licensed according to the included 'LICENCE' document
--
Expand Down Expand Up @@ -233,6 +233,7 @@ header = [[
char *zmq_z85_encode (char *dest, const char *data, size_t size);
char *zmq_z85_decode (char *dest, const char *string);
int zmq_curve_keypair (char *z85_public_key, char *z85_secret_key);
int zmq_curve_public (char *z85_public_key, const char *z85_secret_key);
]]
ffi.cdef(header)

Expand Down Expand Up @@ -640,6 +641,25 @@ end

end

-- zmq_curve_public
if pget(libzmq3, "zmq_curve_public") then

function _M.zmq_curve_public(secret_key, as_binary)
local public_key = ffi.new(vla_char_t, 41)
local ret = libzmq3.zmq_curve_public(public_key, secret_key)
if ret == -1 then return -1 end
if not as_binary then
return ffi.string(public_key, 40)
end
local public_key_bin = ffi.new(vla_char_t, 32)

libzmq3.zmq_z85_decode(public_key_bin, public_key)

return ffi.string(public_key_bin, 32)
end

end

-- zmq_recv_event
do

Expand Down Expand Up @@ -808,8 +828,8 @@ _M.CONTEXT_OPTIONS = O{
ZMQ_THREAD_PRIORITY = 3;
ZMQ_THREAD_SCHED_POLICY = 4;
};
[{4,2,0}] = {
ZMQ_BLOCKY = 70
[{4,2,2}] = {
ZMQ_MAX_MSGSZ = 5
};

}
Expand Down Expand Up @@ -893,6 +913,24 @@ _M.SOCKET_OPTIONS = O{
ZMQ_XPUB_WELCOME_MSG = {72, "WO", "str"},
};

[{4,2,2}] = {
ZMQ_STREAM_NOTIFY = {73, "WO", "int"},
ZMQ_INVERT_MATCHING = {74, "RW", "int"},
ZMQ_HEARTBEAT_IVL = {75, "WO", "int"},
ZMQ_HEARTBEAT_TTL = {76, "WO", "int"},
ZMQ_HEARTBEAT_TIMEOUT = {77, "WO", "int"},
ZMQ_XPUB_VERBOSER = {78, "WO", "int"},
ZMQ_CONNECT_TIMEOUT = {79, "RW", "int"},
ZMQ_TCP_MAXRT = {80, "RW", "int"},
ZMQ_THREAD_SAFE = {81, "RO", "int"},
ZMQ_MULTICAST_MAXTPDU = {84, "RW", "int"},
ZMQ_VMCI_BUFFER_SIZE = {85, "RW", "u64"},
ZMQ_VMCI_BUFFER_MIN_SIZE = {86, "RW", "u64"},
ZMQ_VMCI_BUFFER_MAX_SIZE = {87, "RW", "u64"},
ZMQ_VMCI_CONNECT_TIMEOUT = {88, "RW", "int"},
ZMQ_USE_FD = {89, "RW", "fdt"},
};

}

_M.MESSAGE_OPTIONS = O{
Expand Down
51 changes: 48 additions & 3 deletions src/lzmq.c
@@ -1,15 +1,17 @@
/*
Author: Alexey Melnichuk <mimir@newmail.ru>
Copyright (C) 2013-2014 Alexey Melnichuk <mimir@newmail.ru>
Copyright (C) 2013-2017 Alexey Melnichuk <mimir@newmail.ru>
Licensed according to the included 'LICENCE' document
This file is part of lua-lzqm library.
*/

#include "zmq.h"
#if ZMQ_VERSION < ZMQ_MAKE_VERSION(4,2,0)
#include "zmq_utils.h"
#endif
#include "lzutils.h"
#include "lzmq.h"
#include "zerror.h"
Expand All @@ -22,10 +24,13 @@
#include "zsupport.h"
#include <memory.h>

#define LUAZMQ_MODULE_NAME "lzmq"
#define LUAZMQ_MODULE_LICENSE "MIT"
#define LUAZMQ_MODULE_COPYRIGHT "Copyright (c) 2013-2017 Alexey Melnichuk"
#define LUAZMQ_VERSION_MAJOR 0
#define LUAZMQ_VERSION_MINOR 4
#define LUAZMQ_VERSION_PATCH 3
// #define LUAZMQ_VERSION_COMMENT "dev"
#define LUAZMQ_VERSION_PATCH 4
#define LUAZMQ_VERSION_COMMENT "dev"

const char *LUAZMQ_CONTEXT = LUAZMQ_PREFIX "Context";
const char *LUAZMQ_SOCKET = LUAZMQ_PREFIX "Socket";
Expand Down Expand Up @@ -420,6 +425,30 @@ static int luazmq_curve_keypair(lua_State *L){

#endif

#ifdef LUAZMQ_SUPPORT_CURVE_PUBLIC

static int luazmq_curve_public(lua_State *L){
const char *secret_key = luaL_checkstring(L, 1);
int as_bin = lua_toboolean(L, 2);
char public_key [41];
int rc = zmq_curve_public(public_key, secret_key);
if(rc == -1)
return luazmq_fail(L, 0);

if(as_bin){
uint8_t public_key_bin[32];
zmq_z85_decode (public_key_bin, public_key);
lua_pushlstring(L, (char*)public_key_bin, 32);
}
else{
lua_pushlstring(L, public_key, 40);
}

return 1;
}

#endif

static int luazmq_init_socket(lua_State *L) {
void *src = lua_touserdata(L, 1);
luaL_argcheck(L, lua_islightuserdata(L, 1), 1, "lightuserdata expected");
Expand Down Expand Up @@ -449,6 +478,10 @@ static const struct luaL_Reg luazmqlib[] = {
{ "curve_keypair", luazmq_curve_keypair },
#endif

#ifdef LUAZMQ_SUPPORT_CURVE_PUBLIC
{ "curve_public", luazmq_curve_public },
#endif

#ifdef ZMQ_HAS_CAPABILITIES
{ "has", luazmq_has },
#endif
Expand Down Expand Up @@ -521,6 +554,18 @@ static void luazmq_init_lib(lua_State *L){
lua_pushliteral(L, "_VERSION");
luazmq_push_version(L);
lua_rawset(L, -3);

lua_pushliteral(L, "_NAME");
lua_pushliteral(L, LUAZMQ_MODULE_NAME);
lua_rawset(L, -3);

lua_pushliteral(L, "_LICENSE");
lua_pushliteral(L, LUAZMQ_MODULE_LICENSE);
lua_rawset(L, -3);

lua_pushliteral(L, "_COPYRIGHT");
lua_pushliteral(L, LUAZMQ_MODULE_COPYRIGHT);
lua_rawset(L, -3);
}

LUAZMQ_EXPORT int luaopen_lzmq (lua_State *L){
Expand Down
8 changes: 4 additions & 4 deletions src/zcontext.c
Expand Up @@ -391,8 +391,8 @@ DEFINE_CTX_OPT(thread_priority, ZMQ_THREAD_PRIORITY)
DEFINE_CTX_OPT(thread_sched_policy, ZMQ_THREAD_SCHED_POLICY)
#endif

#ifdef ZMQ_BLOCKY
DEFINE_CTX_OPT(blocky, ZMQ_BLOCKY)
#ifdef ZMQ_MAX_MSGSZ
DEFINE_CTX_OPT(max_msgsz, ZMQ_MAX_MSGSZ)
#endif

static const struct luaL_Reg luazmq_ctx_methods[] = {
Expand Down Expand Up @@ -430,8 +430,8 @@ static const struct luaL_Reg luazmq_ctx_methods[] = {
REGISTER_CTX_OPT(thread_sched_policy),
#endif

#ifdef ZMQ_BLOCKY
REGISTER_CTX_OPT(blocky),
#ifdef ZMQ_MAX_MSGSZ
REGISTER_CTX_OPT(max_msgsz),
#endif

{NULL,NULL}
Expand Down

0 comments on commit 5c635ef

Please sign in to comment.