-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit of hxzmq, covering core 2.1.6 libzmq functionality. Unit tests and guide examples built and tested on following targets: - cpp (Mac64, WindowsXP) - neko (WindowsXP)
- Loading branch information
Showing
53 changed files
with
4,823 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Git ignore file for hxzmq | ||
lib/ | ||
obj/ | ||
all_objs | ||
vc90.pdb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Haxe build file | ||
-cp src | ||
-cp test/src | ||
-cpp out | ||
-D HXCPP_M64 | ||
-main TestZMQ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Users/richardsmith/Projects/hxzmq/build.hxml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
hxzmq Installation Instructions | ||
=============================== | ||
|
||
## haxelib Installation | ||
|
||
To be able to just use hxzmq to build 0MQ messaging into new haXe applications, without modifying the or re-building hxzmq from source, you need: | ||
|
||
1. Install the current hxzmq package using the haXe haxelib tool | ||
haxelib install hxzmq | ||
2. To build your application including the hxzmq project, include the hxzmq library in your hxml haXe compilation file: | ||
-lib hxzmq | ||
3. To run your target executable, your system will need to reach the hxzmq.ndll library file and the libzmq.dll 0MQ library file. Add paths to both to your PATH environment variable, or copy both files into the same folder as your newly-minted haXe executable (e.g. either a neko .n or cpp executable). | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
hxzmq - haXe Language Bindings for ZeroMQ | ||
========================================= | ||
|
||
Welcome to hxzmq, [haXe language bindings] [2] for the iMatix [ZeroMQ messaging library] [3]. 0MQ is a lightweight and fast messaging implementation. | ||
|
||
By Richard Smith [RSBA Technology Ltd] [1] | ||
|
||
|
||
## Introduction | ||
This repository provides C++ binding code that wraps the libzmq library API to create a Neko DLL file, hxzmq.ndll. The ndll is then accessed via the hxzmq org.zeromq package to expose the 0MQ API to haXe application code targetted at C++ or nekovm platforms. | ||
### Background & Rationale | ||
haXe enables applications to be written in a single unified programming language that can then be executed on any combination of an ever-growing number of [target language platforms.] [6]. It is quite possible to write back-end server code targetted at php or C++, with a rich internet application Flash or javascript front-end, plus an iPhone application (via the C++ target), all using a single shared haXe codebase. Code written using non-target specific APIs can be automatically re-used on any of these platforms, such as an application's internal domain model or framework code. Conditional compilation, together with many target - specific APIs contained in the [haXe standard library] [7], provides the opportunity to access platform-specific features, giving the best of both worlds. Most of the target platforms also support extending the standard capabilities by use of externs and Foreign Function Interface mechanisms; an ability which has been used to write hxzmq. haXe is an [open source project] [7]. | ||
|
||
0MQ is a relatively recent entrant into the messaging layer software space, conceived as a low-level, cross-platform but highly - performant messaging library that can replace direct use of in-process and tcp sockets etc with a message-orientated API. It implements a number of well-defined message patterns (e.g. Request-Reply, Publish-Subscribe) that allow very complex distributed system architectures to be built from simple parts. 0MQ is maintained as an [open source project] [8] by iMatix. | ||
|
||
hxzmq has been written to allow the author (and anyone else who might be interested) to explore and experiment what improvements in software design practise can be made when a cross-platform language is coupled with a highly performant cross-platform messaging layer. | ||
### haXe Code Example | ||
|
||
Client: | ||
package ; | ||
import haxe.io.Bytes; | ||
import org.zeromq.ZMQ; | ||
import org.zeromq.ZMQContext; | ||
import org.zeromq.ZMQSocket; | ||
|
||
/** | ||
* Hello World client in Haxe. | ||
*/ | ||
class HelloWorldClient | ||
{ | ||
public static function main() { | ||
var context:ZMQContext = ZMQContext.instance(); | ||
var socket:ZMQSocket = context.socket(ZMQ_REQ); | ||
socket.connect ("tcp://localhost:5556"); | ||
for (i in 0...10) { | ||
var requestString = "Hello "; | ||
socket.sendMsg(Bytes.ofString(requestString)); | ||
var msg:Bytes = socket.recvMsg(); | ||
trace ("Received reply " + i + ": [" + msg.toString() + "]"); | ||
} | ||
socket.close(); | ||
context.term(); | ||
} | ||
} | ||
|
||
Server: | ||
package ; | ||
import haxe.io.Bytes; | ||
import org.zeromq.ZMQ; | ||
import org.zeromq.ZMQContext; | ||
import org.zeromq.ZMQException; | ||
import org.zeromq.ZMQSocket; | ||
|
||
/** | ||
* Hello World server in Haxe | ||
* Binds REP to tcp://*:5556 | ||
* Expects "Hello" from client, replies with "World" | ||
* | ||
*/ | ||
class HelloWorldServer | ||
{ | ||
public static function main() { | ||
var context:ZMQContext = ZMQContext.instance(); | ||
var responder:ZMQSocket = context.socket(ZMQ_REP); | ||
responder.bind("tcp://*:5556"); | ||
while (true) { | ||
var request:Bytes = responder.recvMsg(); | ||
// Do some work | ||
Sys.sleep(1); | ||
// Send reply back to client | ||
responder.sendMsg(Bytes.ofString("World")); | ||
} | ||
responder.close(); | ||
context.term(); | ||
} | ||
} | ||
|
||
## Contents | ||
|
||
Key files and folders contained in this repository: | ||
|
||
* *build.xml* | ||
|
||
XML compilation configuration file used by the hxcpp cross-platform ndll build tool to compile & build the hxzmq.ndll library. See INSTALL.md for further details. | ||
|
||
* *build.sh* | ||
|
||
Mac/linux build shell script that builds hxzmq.ndll, unit test and guide programs | ||
|
||
* *build.bat* | ||
|
||
Windows script file that builds hxzmq.ndll, unit test and guide programs | ||
|
||
* */src* | ||
|
||
The C++ code that wraps the libzmq C library in [hxcpp CFFI] [10] calls, which exposes it to the haXe layer. Compiles into the hxzmq.ndll library. | ||
|
||
* */org/zeromq* | ||
|
||
The haXe code that invokes the native functions defined in hxzmq.ndll. Provides the core API used by haXe applications. | ||
|
||
* */org/zeromq/test* | ||
|
||
Unit tests for the org.zeromq package. Main program invoked from the TestAll.hx class. | ||
|
||
* */org/zeromq/guide* | ||
|
||
haXe implementations of some code examples included in the [0MQ Guide] [11]. Can be compiled separately, or via the menu class, Run.hx. | ||
|
||
* */test* | ||
|
||
Contains build hxml files for compiling the unit tests on different platforms. | ||
|
||
* */guide* | ||
|
||
Contains build hxml files for compiling the 0MQ Guide code examples on different platforms | ||
|
||
* */bin/ndll* | ||
|
||
Contains pre-built ndll files for different platforms | ||
|
||
## Versions | ||
|
||
The current release of hxzmq is 1.0.0, compatable with libzmq-2.1.4 or any later 2.1.x version. The latest released hxzmq package shall also be available in the [haxelib repository] [4], accessable via the [haxelib tool] [5] which is included in the standard haXe distribution. | ||
|
||
## Building and Installation | ||
|
||
If you are a haXe user who just wants to start using 0MQ and hxzmq in your projects, make sure libzmq.dll is available on your system's PATH setting, and then simply install the latest hxzmq package available from the haXe repository, using the haxelib tool: | ||
|
||
haxelib install hxzmq | ||
|
||
Please refer to the separate INSTALL.md file in this distribution for details on how to build and install hxzmq.ndll from source. | ||
|
||
## Copying | ||
|
||
Free use of this software is granted under the terms of the GNU Lesser General | ||
Public License (LGPL). For details see the files `COPYING.LESSER` | ||
included with the hxzmq distribution. | ||
|
||
[1]: http://rsbatechnology.co.uk "RSBA Technology Ltd" | ||
[2]: http://haxe.org "haXe" | ||
[3]: http://zeromq.org "ZeroMQ" | ||
[4]: http://lib.haxe.org "haXelib repository" | ||
[5]: http://haxe.org/com/haxelib "haXelib" | ||
[6]: http://haxe.org/doc/features "haXe Features" | ||
[7]: http://code.google.com/p/haxe "haXe source code repository" | ||
[8]: https://github.com/zeromq/libzmq "libzmq source code repository" | ||
[9]: http://www.imatix.com/ "iMatix Corporation" | ||
[10]: http://haxe.org/doc/cpp/ffi "C++ FC Foreign Function Interface" | ||
[11]: http://zguide.zeromq.org/ "0MQ Guide" | ||
|
||
|
||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
echo "** Build hxzmq.ndll on Windows:" | ||
haxelib run hxcpp build.xml | ||
|
||
echo "** Build Haxe Unit Tests:" | ||
cd test | ||
haxe buildWindows.hxml | ||
|
||
echo "** Build Haxe ZeroMQ Guide programs:" | ||
cd ../guide | ||
haxe buildWindows.hxml | ||
|
||
echo "** Copy hxzmq.ndll:" | ||
cd .. | ||
copy /Y out\ndll\Windows\hxzmq.ndll test\out-cpp\Windows | ||
copy /Y out\ndll\Windows\hxzmq.ndll test\out-neko\Windows | ||
copy /Y out\ndll\Windows\hxzmq.ndll guide\out-cpp\Windows | ||
copy /Y out\ndll\Windows\hxzmq.ndll guide\out-neko\Windows | ||
|
||
|
||
rem echo "** Run CPP unit tests:" | ||
rem cd test/out-cpp/Windows | ||
rem TestAll-debug.exe | ||
|
||
rem echo "** Run Neko unit tests:" | ||
rem cd test/out-neko/Windows | ||
rem neko TestAll.n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
echo "** Build hxzmq.ndll:" | ||
haxelib run hxcpp build.xml -DHXCPP_M64 | ||
|
||
echo "** Build Haxe Unit Tests:" | ||
cd test | ||
/usr/bin/haxe buildMac64.hxml | ||
|
||
echo "** Build Haxe ZeroMQ Guide programs:" | ||
cd ../guide | ||
/usr/bin/haxe buildMac64.hxml | ||
|
||
echo "** Copying hxzmq.ndll:" | ||
cd .. | ||
cp bin/ndll/Mac64/hxzmq.ndll test/out-cpp/Mac64 | ||
cp bin/ndll/Mac64/hxzmq.ndll test/out-neko/Mac64 | ||
cp bin/ndll/Mac64/hxzmq.ndll guide/out-cpp/Mac64 | ||
|
||
echo "** Running CPP executables:" | ||
cd test/out-cpp/Mac64 | ||
./TestAll-debug | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<xml> | ||
<!-- Build file for hxzmq.ndll --> | ||
<!-- Install hxcpp and run with 'haxelib run hxcpp Build.xml' --> | ||
|
||
<include name="${HXCPP}/build-tool/BuildCommon.xml"/> | ||
|
||
<set name="LIB_DIR" value="-Llib" unless="windows"/> | ||
<set name="LIB_DIR" value="-libpath:lib" if="windows"/> | ||
|
||
<set name="DBG" value="d" if="debug"/> | ||
|
||
<files id="files"> | ||
<compilerflag value = "-Iinclude"/> | ||
<!-- Replace with path to your libzmq installation include directory --> | ||
<compilerflag value = "-IC:\zeromq\zeromq-2.1.6\include" if="windows"/> | ||
|
||
<!-- Pick up libzmq's stdint.hpp include file --> | ||
<compilerflag value = "-IC:\zeromq\zeromq-2.1.6\src" if="windows"/> | ||
|
||
<compilerflag value = "-D_FILE_OFFSET_BITS=64" if="macos"/> | ||
<compilerflag value = "-D_LARGE_FILES=64" if="macos"/> | ||
|
||
<!-- Add for valgrind investigation --> | ||
<!-- <compilerflag value = "-DDEBUG"/> --> | ||
|
||
<file name="src/ZMQ.cpp"/> | ||
<file name="src/Context.cpp"/> | ||
<file name="src/Socket.cpp"/> | ||
<file name="src/Poller.cpp"/> | ||
<file name="src/Interrupt.cpp"/> | ||
|
||
</files> | ||
|
||
<target id="hxzmq.ndll" tool="linker" toolid="dll" output="hxzmq"> | ||
<ext value=".ndll"/> | ||
<outdir name="bin/ndll/${BINDIR}"/> | ||
|
||
<files id="files"/> | ||
|
||
<lib name="libzmq.lib" if="windows" /> | ||
<lib name="-lzmq" unless="windows" /> | ||
|
||
</target> | ||
|
||
<target id="default"> | ||
<target id="hxzmq.ndll"/> | ||
</target> | ||
|
||
</xml> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Haxe build file | ||
# Build CPP guide target | ||
-cp .. | ||
-cpp out-cpp/Mac64 | ||
-debug | ||
-D HXCPP_M64 | ||
-D HXCPP_MULTI_THREADED | ||
--remap neko:cpp | ||
-main org.zeromq.guide.Run | ||
|
||
# todo: Neko Mac0SX 64 bit target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Haxe build file | ||
# Builds Windows HXZMQ Guide code | ||
# Build CPP guide target | ||
-cp .. | ||
-cpp out-cpp/Windows | ||
-debug | ||
-D HXCPP_MULTI_THREADED | ||
--remap neko:cpp | ||
-main org.zeromq.guide.Run | ||
--next | ||
# Build Neko guide target | ||
-cp .. | ||
-neko out-neko/Windows/run-debug.n | ||
-debug | ||
-main org.zeromq.guide.Run | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<project name="hxzmq" url="http://github.com/rjsmith/hxzmq" licence="LGPL"> | ||
<depends name="hxcpp"/> | ||
<user name="rjsmith"/> | ||
<tag v="cpp"/> | ||
<tag v="neko"/> | ||
<description>Haxe language binding for the ZeroMQ socket library</description> | ||
<version name="1.0.0">Initial upload, compatable with libzmq 2.1.6+</version> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<project> | ||
<!-- Output SWF options --> | ||
<output> | ||
<movie disabled="True" /> | ||
<movie input="" /> | ||
<movie path="bin" /> | ||
<movie fps="0" /> | ||
<movie width="0" /> | ||
<movie height="0" /> | ||
<movie version="12" /> | ||
<movie background="#FFFFFF" /> | ||
</output> | ||
<!-- Other classes to be compiled into your SWF --> | ||
<classpaths> | ||
<class path="." /> | ||
</classpaths> | ||
<!-- Build options --> | ||
<build> | ||
<option directives="" /> | ||
<option flashStrict="False" /> | ||
<option mainClass="org.zeromq.test.TestAll" /> | ||
<option enabledebug="False" /> | ||
<option additional="" /> | ||
</build> | ||
<!-- haxelib libraries --> | ||
<haxelib> | ||
<!-- example: <library name="..." /> --> | ||
</haxelib> | ||
<!-- Class files to compile (other referenced classes will automatically be included) --> | ||
<compileTargets> | ||
<compile path="src\org\hxzmq\Main.hx" /> | ||
</compileTargets> | ||
<!-- Paths to exclude from the Project Explorer tree --> | ||
<hiddenPaths> | ||
<!-- example: <hidden path="..." /> --> | ||
</hiddenPaths> | ||
<!-- Executed before build --> | ||
<preBuildCommand /> | ||
<!-- Executed after build --> | ||
<postBuildCommand alwaysRun="False" /> | ||
<!-- Other project options --> | ||
<options> | ||
<option showHiddenPaths="False" /> | ||
<option testMovie="Custom" /> | ||
<option testMovieCommand="run.bat" /> | ||
</options> | ||
</project> |
Oops, something went wrong.