# Module zmq

Nimrod 0mq wrapper. This file contains the low level C wrappers as well as some higher level constructs. The higher level constructs are easily recognizable because they are the only ones that have documentation.

Example of a client:

    import zmq

    var connection = zmq.open("tcp://localhost:5555", server=false)
    echo("Connecting...")
    for i in 0..10:
      echo("Sending hello...", i)
      send(connection, "Hello")
      var reply = receive(connection)
      echo("Received ...", reply)
    close(connection)

Example of a server:

    import zmq
    var connection = zmq.open("tcp://*:5555", server=true)
    while True:
      var request = receive(connection)
      echo("Received: ", request)
      send(connection, "World")
    close(connection)

# Types

    TMsgTypes = enum
      DELIMITER = 31, VSM = 32

    TMsgFlags = enum
      MSG_MORE = 1, MSG_SHARED = 128, MSG_MASK = 129

    TMsg = object
      content*: pointer
      flags*: char
      vsm_size*: char
      vsm_data*: array[0 .. 30 - 1, char]

    PContext = ptr TContext

    PSocket = ptr TSocket

    TSockOptions = enum
      HWM = 1, SWAP = 3, AFFINITY = 4, IDENTITY = 5, SUBSCRIBE = 6, UNSUBSCRIBE = 7,
      RATE = 8, RECOVERY_IVL = 9, MCAST_LOOP = 10, SNDBUF = 11, RCVBUF = 12,
      RCVMORE = 13, FD = 14, EVENTS = 15, theTYPE = 16, LINGER = 17,
      RECONNECT_IVL = 18, BACKLOG = 19, RECOVERY_IVL_MSEC = 20,
      RECONNECT_IVL_MAX = 21

    TSendRecvOptions = enum
      NOBLOCK, SNDMORE

    TPollItem = object
      socket*: PSocket
      fd*: cint
      events*: cshort
      revents*: cshort

    EZmq = object of ESynch

  exception that is raised if something fails

    TConnection = object
      c*: PContext                ## the embedded context
      s*: PSocket                 ## the embedded socket

  a connection

    TConnectionMode = enum
      conPAIR = 0, conPUB = 1, conSUB = 2, conREQ = 3, conREP = 4, conDEALER = 5,
      conROUTER = 6, conPULL = 7, conPUSH = 8, conXPUB = 9, conXSUB = 10

  connection mode

# Consts

    zmqdll = "libzmq.so"

    HAUSNUMERO = 156384712

    ENOTSUP = 156384713

    EPROTONOSUPPORT = 156384714

    ENOBUFS = 156384715

    ENETDOWN = 156384716

    EADDRINUSE = 156384717

    EADDRNOTAVAIL = 156384718

    ECONNREFUSED = 156384719

    EINPROGRESS = 156384720

    EFSM = 156384763

    ENOCOMPATPROTO = 156384764

    ETERM = 156384765

    EMTHREAD = 156384766

    MAX_VSM_SIZE = 30

    POLLIN = 1

    POLLOUT = 2

    POLLERR = 4

    STREAMER = 1

    FORWARDER = 2

    QUEUE = 3

    PAIR = 0

    PUB = 1

    SUB = 2

    REQ = 3

    REP = 4

    DEALER = 5

    ROUTER = 6

    PULL = 7

    PUSH = 8

    XPUB = 9

    XSUB = 10

    XREQ = 5

    XREP = 6

    UPSTREAM = 7

    DOWNSTREAM = 8

# Procs

    proc version(major: var cint; minor: var cint; patch: var cint) {.cdecl,
        importc: "zmq_version", dynlib: zmqdll.}

    proc errno(): cint {.cdecl, importc: "zmq_errno", dynlib: zmqdll.}

    proc strerror(errnum: cint): cstring {.cdecl, importc: "zmq_strerror",
                                           dynlib: zmqdll.}

    proc msg_init(msg: var TMsg): cint {.cdecl, importc: "zmq_msg_init",
                                         dynlib: zmqdll.}

    proc msg_init(msg: var TMsg; size: int): cint {.cdecl,
        importc: "zmq_msg_init_size", dynlib: zmqdll.}

    proc msg_init(msg: var TMsg; data: cstring; size: int; ffn: TFreeFn;
                  hint: pointer): cint {.cdecl, importc: "zmq_msg_init_data",
                                         dynlib: zmqdll.}

    proc msg_close(msg: var TMsg): cint {.cdecl, importc: "zmq_msg_close",
                                          dynlib: zmqdll.}

    proc msg_move(dest, src: var TMsg): cint {.cdecl, importc: "zmq_msg_move",
        dynlib: zmqdll.}

    proc msg_copy(dest, src: var TMsg): cint {.cdecl, importc: "zmq_msg_copy",
        dynlib: zmqdll.}

    proc msg_data(msg: var TMsg): cstring {.cdecl, importc: "zmq_msg_data",
                                            dynlib: zmqdll.}

    proc msg_size(msg: var TMsg): int {.cdecl, importc: "zmq_msg_size",
                                        dynlib: zmqdll.}

    proc init(io_threads: cint): PContext {.cdecl, importc: "zmq_init",
                                            dynlib: zmqdll.}

    proc term(context: PContext): cint {.cdecl, importc: "zmq_term", dynlib: zmqdll.}

    proc socket(context: PContext; theType: cint): PSocket {.cdecl,
        importc: "zmq_socket", dynlib: zmqdll.}

    proc close(s: PSocket): cint {.cdecl, importc: "zmq_close", dynlib: zmqdll.}

    proc setsockopt(s: PSocket; option: cint; optval: pointer; optvallen: int): cint {.
        cdecl, importc: "zmq_setsockopt", dynlib: zmqdll.}

    proc getsockopt(s: PSocket; option: cint; optval: pointer; optvallen: ptr int): cint {.
        cdecl, importc: "zmq_getsockopt", dynlib: zmqdll.}

    proc bindAddr(s: PSocket; address: cstring): cint {.cdecl, importc: "zmq_bind",
        dynlib: zmqdll.}

    proc connect(s: PSocket; address: cstring): cint {.cdecl,
        importc: "zmq_connect", dynlib: zmqdll.}

    proc send(s: PSocket; msg: var TMsg; flags: cint): cint {.cdecl,
        importc: "zmq_send", dynlib: zmqdll.}

    proc recv(s: PSocket; msg: var TMsg; flags: cint): cint {.cdecl,
        importc: "zmq_recv", dynlib: zmqdll.}

    proc poll(items: ptr TPollItem; nitems: cint; timeout: int): cint {.cdecl,
        importc: "zmq_poll", dynlib: zmqdll.}

    proc device(device: cint; insocket, outsocket: PSocket): cint {.cdecl,
        importc: "zmq_device", dynlib: zmqdll.}

    proc zmqError() {.noinline, noreturn, raises: [EZmq], tags: [].}

  raises EZmq with error message from zmq.strerror.

    proc open(address: string; server: bool; mode: TConnectionMode = conDEALER;
              numthreads = 4): TConnection {.raises: [EZmq], tags: [].}

  opens a new connection. If server is true, it uses bindAddr for the underlying socket, otherwise it opens the socket with connect.

    proc close(c: var TConnection) {.raises: [EZmq], tags: [].}

  closes the connection.

    proc send(c: var TConnection; msg: string) {.raises: [EZmq], tags: [].}

  sends a message over the connection.

    proc receive(c: var TConnection): string {.raises: [EZmq], tags: [].}

  receives a message from a connection.

Generated: 2013-05-21 09:55:20 UTC