Zoadian hace 11 años
padre
commit
4a0abff2bb
Se han modificado 6 ficheros con 449 adiciones y 2 borrados
  1. 4 0
      .gitignore
  2. 3 2
      README.md
  3. 16 0
      package.json
  4. 119 0
      source/derelict/nanomsg/functions.d
  5. 90 0
      source/derelict/nanomsg/nanomsg.d
  6. 217 0
      source/derelict/nanomsg/types.d

+ 4 - 0
.gitignore

@@ -0,0 +1,4 @@
+lib
+bin
+update.txt
+.dub

+ 3 - 2
README.md

@@ -1,2 +1,3 @@
-# DerelictNanomsg
-dynamic nanomsg binding
+DerelictNanomsg
+============
+

+ 16 - 0
package.json

@@ -0,0 +1,16 @@
+{
+    "name": "derelict_extras-nanomsg",
+    "description": "Dynamic bindings to nanomsg.",
+    "homepage": "https://github.com/Zoadian/DerelictNanomsg",
+    "license": "BSL-1.0",
+    "authors": [
+        "Felix Hufnagel"
+    ],
+
+    "targetName": "DerelictNanomsg",
+    "targetPath": "lib",
+
+    "dependencies": {
+        "derelict-util": ">=1.0.2"
+    }
+}

+ 119 - 0
source/derelict/nanomsg/functions.d

@@ -0,0 +1,119 @@
+/*
+
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+*/
+module derelict.nanomsg.functions;
+
+private {
+    import core.stdc.stdio;
+    import core.stdc.stdarg;
+    import derelict.util.system;
+    import derelict.nanomsg.types;
+}
+
+extern( C ) @nogc nothrow {	
+    alias int function() da_nanomsg_nn_errno;
+    alias const char* function(int) da_nanomsg_nn_strerror;
+    alias const char* function(int, int*) da_nanomsg_nn_symbol;
+    alias int function(int, nn_symbol_properties*, int) da_nanomsg_nn_symbol_info;
+    alias void* function(size_t size, int type) da_nanomsg_nn_term;
+    alias void* function(void* msg, size_t size) da_nanomsg_nn_allocmsg;
+    alias int function(void*) da_nanomsg_nn_freemsg;
+	
+	version(none) {
+		alias nn_cmsghdr* function(const nn_msghdr*, const nn_cmsghdr*) da_nanomsg_nn_cmsg_nxthdr_;
+			
+		auto NN_CMSG_ALIGN(T)(T len) {
+			return (len + size_t.sizeof - 1) & (size_t) ~ (size_t.sizeof - 1);
+		}
+
+
+		/* POSIX-defined msghdr manipulation. */
+		auto NN_CMSG_FIRSTHDR(T)(T mhdr) {
+			return nn_cmsg_nxthdr_(cast(nn_msghdr*)mhdr, null);
+		}
+		auto NN_CMSG_NXTHDR(T, K)(T mhdr, K cmsg) {
+			return nn_cmsg_nxthdr_(cast(nn_msghdr*)mhdr, cast(nn_cmsghdr*)cmsg);
+		}
+		auto NN_CMSG_DATA(T)(T cmsg) {
+			return cast(ubyte*)((cast(nn_cmsghdr*)cmsg) + 1);
+		}
+
+
+		/* Extensions to POSIX defined by RFC 3542.                                   */
+
+		auto NN_CMSG_SPACE(T)(T len) {
+			return NN_CMSG_ALIGN_(len) + NN_CMSG_ALIGN_(nn_cmsghdr.sizeof);
+		}
+			
+		auto NN_CMSG_LEN(T)(T len) {
+			return NN_CMSG_ALIGN_(nn_cmsghdr.sizeof) + len;
+		}
+		
+	}	
+	
+    alias int function(int, int) da_nanomsg_nn_socket;
+    alias int function(int) da_nanomsg_nn_close;
+    alias int function(int, int, int, const void*, size_t) da_nanomsg_nn_setsockopt;
+    alias int function(int, int, int, void*, size_t*) da_nanomsg_nn_getsockopt;
+    alias int function(int, const char*) da_nanomsg_nn_bind;
+    alias int function(int, const char*) da_nanomsg_nn_connect;
+    alias int function(int, int) da_nanomsg_nn_shutdown;
+    alias int function(int, const void*, size_t, int) da_nanomsg_nn_send;
+    alias int function(int, void*, size_t, int) da_nanomsg_nn_recv;
+    alias int function(int, const nn_msghdr*, int) da_nanomsg_nn_sendmsg;
+    alias int function(int, nn_msghdr*, int) da_nanomsg_nn_recvmsg;
+    alias int function(nn_pollfd*, int, int) da_nanomsg_nn_poll;
+    alias int function(int, int) da_nanomsg_nn_device;
+}
+
+__gshared {
+    da_nanomsg_nn_errno nanomsgErrno;
+    da_nanomsg_nn_strerror nanomsgStrerror;
+    da_nanomsg_nn_symbol nanomsgSymbol;
+    da_nanomsg_nn_symbol_info nanomsgSymbolInfo;
+    da_nanomsg_nn_term nanomsgTerm;
+    da_nanomsg_nn_allocmsg nanomsgAllocmsg;
+    da_nanomsg_nn_freemsg nanomsgFreemsg;
+	
+	version(none) {
+		//...
+	}
+	
+    da_nanomsg_nn_socket nanomsgSocket;
+    da_nanomsg_nn_close nanomsgClose;
+    da_nanomsg_nn_setsockopt nanomsgSetsockopt;
+    da_nanomsg_nn_getsockopt nanomsgGetsockopt;
+    da_nanomsg_nn_bind nanomsgBind;
+    da_nanomsg_nn_connect nanomsgConnect;
+    da_nanomsg_nn_shutdown nanomsgShutdown;
+    da_nanomsg_nn_send nanomsgSend;
+    da_nanomsg_nn_recv nanomsgRecv;
+    da_nanomsg_nn_sendmsg nanomsgSendmsg;
+    da_nanomsg_nn_recvmsg nanomsgRecvMsg;
+    da_nanomsg_nn_poll nanomsgPoll;
+    da_nanomsg_nn_device nanomsgDevice;
+}

+ 90 - 0
source/derelict/nanomsg/nanomsg.d

@@ -0,0 +1,90 @@
+/*
+
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license ( the "Software" ) to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+*/
+module derelict.nanomsg.nanomsg;
+
+public {
+    import derelict.nanomsg.types;
+    import derelict.nanomsg.functions;
+}
+
+private {
+    import derelict.util.loader;
+    import derelict.util.system;
+
+    static if( Derelict_OS_Windows )
+        enum libNames = "nanomsg.dll";
+    else
+        static assert( 0, "Need to implement Nanomsg2 libNames for this operating system." );
+}
+
+/*
+This function is not part of the public interface,  but Nanomsg expects it to be called before any subsystems have been intiailized.
+Normally, this happens via linking with libNanomsgmain, but since that doesn't happen when using Derelict, then the loader must
+load this function and call it before the load method returns. Otherwise, bad things can happen.
+*/
+private extern( C ) nothrow alias da_Nanomsg_SetMainReady = void function();
+
+class DerelictNanomsgLoader : SharedLibLoader {
+      public this() {
+            super( libNames );
+      }
+
+      protected override void loadSymbols() {
+            bindFunc(cast(void**)&nanomsgErrno, "nn_errno");
+            bindFunc(cast(void**)&nanomsgStrerror, "nn_strerror");
+            bindFunc(cast(void**)&nanomsgSymbol, "nn_symbol");
+            bindFunc(cast(void**)&nanomsgSymbolInfo, "nn_symbol_info");
+            bindFunc(cast(void**)&nanomsgTerm, "nn_term");
+            bindFunc(cast(void**)&nanomsgAllocmsg, "nn_allocmsg");
+            bindFunc(cast(void**)&nanomsgFreemsg, "nn_freemsg");
+            bindFunc(cast(void**)&nanomsgSocket, "nn_socket");
+            bindFunc(cast(void**)&nanomsgClose, "nn_close");
+            bindFunc(cast(void**)&nanomsgSetsockopt, "nn_setsockopt");
+            bindFunc(cast(void**)&nanomsgGetsockopt, "nn_getsockopt");
+            bindFunc(cast(void**)&nanomsgBind, "nn_bind");
+            bindFunc(cast(void**)&nanomsgConnect, "nn_connect");
+            bindFunc(cast(void**)&nanomsgShutdown, "nn_shutown");
+            bindFunc(cast(void**)&nanomsgSend, "nn_send");
+            bindFunc(cast(void**)&nanomsgRecv, "nn_recv");
+            bindFunc(cast(void**)&nanomsgSendmsg, "nn_sendmsg");
+            bindFunc(cast(void**)&nanomsgRecvMsg, "nn_recvmsg");
+            bindFunc(cast(void**)&nanomsgPoll, "nn_poll");
+            bindFunc(cast(void**)&nanomsgDevice, "nn_device");
+      }
+}
+
+__gshared DerelictNanomsgLoader DerelictNanomsg;
+
+shared static this() {
+    DerelictNanomsg = new DerelictNanomsgLoader();
+}
+
+shared static ~this()
+{
+    DerelictNanomsg.unload();
+}

+ 217 - 0
source/derelict/nanomsg/types.d

@@ -0,0 +1,217 @@
+/*
+
+Boost Software License - Version 1.0 - August 17th, 2003
+
+Permission is hereby granted, free of charge, to any person or organization
+obtaining a copy of the software and accompanying documentation covered by
+this license (the "Software") to use, reproduce, display, distribute,
+execute, and transmit the Software, and to prepare derivative works of the
+Software, and to permit third-parties to whom the Software is furnished to
+do so, all subject to the following:
+
+The copyright notices in the Software and this entire statement, including
+the above license grant, this restriction and the following disclaimer,
+must be included in all copies of the Software, in whole or in part, and
+all derivative works of the Software, unless such copies or derivative
+works are solely in the form of machine-executable object code generated by
+a source language processor.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+DEALINGS IN THE SOFTWARE.
+
+*/
+module derelict.nanomsg.types;
+
+
+
+/******************************************************************************/
+/*  ABI versioning support.                                                   */
+/******************************************************************************/
+
+/*  Don't change this unless you know exactly what you're doing and have      */
+/*  read and understand the following documents:                              */
+/*  www.gnu.org/software/libtool/manual/html_node/Libtool-versioning.html     */
+/*  www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html  */
+
+/*  The current interface version. */
+enum NN_VERSION_CURRENT = 2;
+
+/*  The latest revision of the current interface. */
+enum NN_VERSION_REVISION = 1;
+
+/*  How many past interface versions are still supported. */
+enum NN_VERSION_AGE = 2;
+
+
+/******************************************************************************/
+/*  Errors.                                                                   */
+/******************************************************************************/
+
+/*  A number random enough not to collide with different errno ranges on      */
+/*  different OSes. The assumption is that error_t is at least 32-bit type.   */
+enum NN_HAUSNUMERO = 156384712;
+
+/*  On some platforms some standard POSIX errnos are not defined.    */
+enum ENOTSUP = (NN_HAUSNUMERO + 1);
+enum EPROTONOSUPPORT = (NN_HAUSNUMERO + 2);
+enum ENOBUFS = (NN_HAUSNUMERO + 3);
+enum ENETDOWN = (NN_HAUSNUMERO + 4);
+enum EADDRINUSE = (NN_HAUSNUMERO + 5);
+enum EADDRNOTAVAIL = (NN_HAUSNUMERO + 6);
+enum ECONNREFUSED = (NN_HAUSNUMERO + 7);
+enum EINPROGRESS = (NN_HAUSNUMERO + 8);
+enum ENOTSOCK = (NN_HAUSNUMERO + 9);
+enum EAFNOSUPPORT = (NN_HAUSNUMERO + 10);
+enum EPROTO = (NN_HAUSNUMERO + 11);
+enum EAGAIN = (NN_HAUSNUMERO + 12);
+enum EBADF = (NN_HAUSNUMERO + 13);
+enum EINVAL = (NN_HAUSNUMERO + 14);
+enum EMFILE = (NN_HAUSNUMERO + 15);
+enum EFAULT = (NN_HAUSNUMERO + 16);
+enum EACCES = (NN_HAUSNUMERO + 17);
+enum EACCESS = (EACCES);
+enum ENETRESET = (NN_HAUSNUMERO + 18);
+enum ENETUNREACH = (NN_HAUSNUMERO + 19);
+enum EHOSTUNREACH = (NN_HAUSNUMERO + 20);
+enum ENOTCONN = (NN_HAUSNUMERO + 21);
+enum EMSGSIZE = (NN_HAUSNUMERO + 22);
+enum ETIMEDOUT = (NN_HAUSNUMERO + 23);
+enum ECONNABORTED = (NN_HAUSNUMERO + 24);
+enum ECONNRESET = (NN_HAUSNUMERO + 25);
+enum ENOPROTOOPT = (NN_HAUSNUMERO + 26);
+enum EISCONN = (NN_HAUSNUMERO + 27);
+enum NN_EISCONN_DEFINED = 1;
+enum ESOCKTNOSUPPORT = (NN_HAUSNUMERO + 28);
+
+/*  Native nanomsg error codes.                                               */
+enum ETERM = (NN_HAUSNUMERO + 53);
+enum EFSM = (NN_HAUSNUMERO + 54);
+
+
+/*  Constants that are returned in `ns` member of nn_symbol_properties        */
+enum NN_NS_NAMESPACE = 0;
+enum NN_NS_VERSION = 1;
+enum NN_NS_DOMAIN = 2;
+enum NN_NS_TRANSPORT = 3;
+enum NN_NS_PROTOCOL = 4;
+enum NN_NS_OPTION_LEVEL = 5;
+enum NN_NS_SOCKET_OPTION = 6;
+enum NN_NS_TRANSPORT_OPTION = 7;
+enum NN_NS_OPTION_TYPE = 8;
+enum NN_NS_OPTION_UNIT = 9;
+enum NN_NS_FLAG = 10;
+enum NN_NS_ERROR = 11;
+enum NN_NS_LIMIT = 12;
+
+/*  Constants that are returned in `type` member of nn_symbol_properties      */
+enum NN_TYPE_NONE = 0;
+enum NN_TYPE_INT = 1;
+enum NN_TYPE_STR = 2;
+
+/*  Constants that are returned in the `unit` member of nn_symbol_properties  */
+enum NN_UNIT_NONE = 0;
+enum NN_UNIT_BYTES = 1;
+enum NN_UNIT_MILLISECONDS = 2;
+enum NN_UNIT_PRIORITY = 3;
+enum NN_UNIT_BOOLEAN = 4;
+
+/*  Structure that is returned from nn_symbol  */
+struct nn_symbol_properties {
+
+    /*  The constant value  */
+    int value;
+
+    /*  The constant name  */
+    const char* name;
+
+    /*  The constant namespace, or zero for namespaces themselves */
+    int ns;
+
+    /*  The option type for socket option constants  */
+    int type;
+
+    /*  The unit for the option value for socket option constants  */
+    int unit;
+};
+
+/******************************************************************************/
+/*  Zero-copy support.                                                        */
+/******************************************************************************/
+
+enum NN_MSG = cast(size_t)(-1);
+
+
+/******************************************************************************/
+/*  Socket definition.                                                        */
+/******************************************************************************/
+
+struct nn_iovec {
+    void* iov_base;
+    size_t iov_len;
+};
+
+struct nn_msghdr {
+    nn_iovec* msg_iov;
+    int msg_iovlen;
+    void* msg_control;
+    size_t msg_controllen;
+};
+
+struct nn_cmsghdr {
+    size_t cmsg_len;
+    int cmsg_level;
+    int cmsg_type;
+};
+
+/*  SP address families.                                                      */
+enum AF_SP = 1;
+enum AF_SP_RAW = 2;
+
+/*  Max size of an SP address.                                                */
+enum NN_SOCKADDR_MAX = 128;
+
+/*  Socket option levels: Negative numbers are reserved for transports,
+    positive for socket types. */
+enum NN_SOL_SOCKET = 0;
+
+/*  Generic socket options (NN_SOL_SOCKET level).                             */
+enum NN_LINGER = 1;
+enum NN_SNDBUF = 2;
+enum NN_RCVBUF = 3;
+enum NN_SNDTIMEO = 4;
+enum NN_RCVTIMEO = 5;
+enum NN_RECONNECT_IVL = 6;
+enum NN_RECONNECT_IVL_MAX = 7;
+enum NN_SNDPRIO = 8;
+enum NN_RCVPRIO = 9;
+enum NN_SNDFD = 10;
+enum NN_RCVFD = 11;
+enum NN_DOMAIN = 12;
+enum NN_PROTOCOL = 13;
+enum NN_IPV4ONLY = 14;
+enum NN_SOCKET_NAME = 15;
+
+/*  Send/recv options.                                                        */
+enum NN_DONTWAIT = 1;
+
+/*  Ancillary data.                                                           */
+enum PROTO_SP = 1;
+enum SP_HDR = 1;
+
+/******************************************************************************/
+/*  Socket mutliplexing support.                                              */
+/******************************************************************************/
+
+enum NN_POLLIN = 1;
+enum NN_POLLOUT = 2;
+
+struct nn_pollfd {
+    int fd;
+    short events;
+    short revents;
+};