# 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* {.pure, final.} = object
      content*: pointer
      flags*: char
      vsm_size*: char
      vsm_data*: array[0 .. MAX_VSM_SIZE - 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* {.pure, final.} = object
      socket*: PSocket
      fd*: cint
      events*: cshort
      revents*: cshort

    EZmq* = object of ESynch

  exception that is raised if something fails

    TConnection* {.pure, final.} = 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* = "zmq.dll"

    HAUSNUMERO* = 156384712

    ENOTSUP* = (HAUSNUMERO + 1)

    EPROTONOSUPPORT* = (HAUSNUMERO + 2)

    ENOBUFS* = (HAUSNUMERO + 3)

    ENETDOWN* = (HAUSNUMERO + 4)

    EADDRINUSE* = (HAUSNUMERO + 5)

    EADDRNOTAVAIL* = (HAUSNUMERO + 6)

    ECONNREFUSED* = (HAUSNUMERO + 7)

    EINPROGRESS* = (HAUSNUMERO + 8)

    EFSM* = (HAUSNUMERO + 51)

    ENOCOMPATPROTO* = (HAUSNUMERO + 52)

    ETERM* = (HAUSNUMERO + 53)

    EMTHREAD* = (HAUSNUMERO + 54)

    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* = DEALER

    XREP* = ROUTER

    UPSTREAM* = PULL

    DOWNSTREAM* = PUSH

# 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 with error message from zmq.strerror.

    proc open*(address: string; server: bool; mode: TConnectionMode = conDEALER;
               numthreads = 4): TConnection

  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)

  closes the connection.

    proc send*(c: var TConnection; msg: string)

  sends a message over the connection.

    proc receive*(c: var TConnection): string

  receives a message from a connection.

Generated: 2012-09-23 21:47:54 UTC