[
  {
    "path": ".gitignore",
    "content": "*.o\n*.a\n*.[568vq]\n[568vq].out\n*.cgo1.go\n*.cgo2.c\n_cgo_defun.c\n_cgo_gotypes.go\n_cgo_export.*\n*.so\n_obj\n_test\n_testmain.go\n*.exe\n.cache\n"
  },
  {
    "path": ".godocdown.md",
    "content": "# Go (golang) Bindings for 0mq (zmq, zeromq)\n\n[![Build Status](https://travis-ci.org/alecthomas/gozmq.png)](https://travis-ci.org/alecthomas/gozmq)\n\nThis package implements [Go](http://golang.org) (golang) bindings for\nthe [0mq](http://zeromq.org) C API.\n\nIt is licensed under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0).\n\nGoZMQ [does not](#zero-copy) support zero-copy.\n\nA full list of examples is included in the [zguide](https://github.com/imatix/zguide/tree/master/examples/Go).\n\nNote that this is *not* the same as [this\nimplementation](http://github.com/boggle/gozero) or [this\nimplementation](http://code.google.com/p/gozmq/).\n\n## Upgrading\n\nGoZMQ has made some public changes that will break old code.  Fortunately, we've also written a tool based on `go fix` that will upgrade your code for you!  Here's how to run it over your source (after making a backup of course):\n\n    go get github.com/alecthomas/gozmq/gozmqfix\n    cd $YOUR_SOURCE_DIR\n    gozmqfix .\n\n## Installing\n\nGoZMQ currently supports ZMQ 2.1.x, 2.2.x and *basic* support for 3.x. Following are instructions on how to compile against these versions.\n\nInstall gozmq with:\n\n    go get github.com/alecthomas/gozmq\n\nThis implementation works currently against:: ZeroMQ 2.2.x\n\n### ZeroMQ 2.1.x\n\nIf you're using ZeroMQ 2.1.x, install with:\n\n    go get -tags zmq_2_1 github.com/alecthomas/gozmq\n\n### ZeroMQ 3.x\n\nThere is *basic* support for ZeroMQ 3.x. Install with:\n\n    go get -tags zmq_3_x github.com/alecthomas/gozmq\n\n### Troubleshooting\n\n#### Go can't find ZMQ\n\nIf the go tool can't find zmq and you know it is installed, you may need to override the C compiler/linker flags.\n\neg. If you installed zmq into `/opt/zmq` you might try:\n\n\tCGO_CFLAGS=-I/opt/zmq/include CGO_LDFLAGS=-L/opt/zmq/lib \\\n\t\tgo get github.com/alecthomas/gozmq\n\n#### Mismatch in version of ZMQ\n\nIf you get errors like this with 'go get' or 'go build':\n\n    1: error: 'ZMQ_FOO' undeclared (first use in this function)\n    \nThere are two possibilities:\n\n1. Your version of zmq is *very* old. In this case you will need to download and build zmq yourself.\n2. You are building gozmq against the wrong version of zmq. See the [installation](#installation) instructions for details on how to target the correct version.\n\n## Differences from the C API\n\nThe API implemented by this package does not attempt to expose\n`zmq_msg_t` at all. Instead, `Recv()` and `Send()` both operate on byte\nslices, allocating and freeing the memory automatically. Currently this\nrequires copying to/from C malloced memory, but a future implementation\nmay be able to avoid this to a certain extent.\n\nAll major features are supported: contexts, sockets, devices, and polls.\n\n## Example\n\nHere are direct translations of some of the examples from [this blog\npost](http://nichol.as/zeromq-an-introduction).\n\nA simple echo server:\n\n```go\npackage main\n\nimport zmq \"github.com/alecthomas/gozmq\"\n\nfunc main() {\n  context, _ := zmq.NewContext()\n  socket, _ := context.NewSocket(zmq.REP)\n  socket.Bind(\"tcp://127.0.0.1:5000\")\n  socket.Bind(\"tcp://127.0.0.1:6000\")\n\n  for {\n    msg, _ := socket.Recv(0)\n    println(\"Got\", string(msg))\n    socket.Send(msg, 0)\n  }\n}\n```\n\nA simple client for the above server:\n\n```go\npackage main\n\nimport \"fmt\"\nimport zmq \"github.com/alecthomas/gozmq\"\n\nfunc main() {\n  context, _ := zmq.NewContext()\n  socket, _ := context.NewSocket(zmq.REQ)\n  socket.Connect(\"tcp://127.0.0.1:5000\")\n  socket.Connect(\"tcp://127.0.0.1:6000\")\n\n  for i := 0; i < 10; i++ {\n    msg := fmt.Sprintf(\"msg %d\", i)\n    socket.Send([]byte(msg), 0)\n    println(\"Sending\", msg)\n    socket.Recv(0)\n  }\n}\n```\n\n## Caveats\n\n### Zero-copy\n\nGoZMQ does not support zero-copy.\n\nGoZMQ does not attempt to expose `zmq_msg_t` at all. Instead, `Recv()` and `Send()`\nboth operate on byte slices, allocating and freeing the memory automatically.\nCurrently this requires copying to/from C malloced memory, but a future\nimplementation may be able to avoid this to a certain extent.\n\n\n### Memory management\n\nIt's not entirely clear from the 0mq documentation how memory for\n`zmq_msg_t` and packet data is managed once 0mq takes ownership. After\ndigging into the source a little, this package operates under the\nfollowing (educated) assumptions:\n\n-   References to `zmq_msg_t` structures are not held by the C API\n    beyond the duration of any function call.\n-   Packet data is reference counted internally by the C API. The count\n    is incremented when a packet is queued for delivery to a destination\n    (the inference being that for delivery to N destinations, the\n    reference count will be incremented N times) and decremented once\n    the packet has either been delivered or errored.\n\n{{ .EmitUsage }}\n\n*(generated from .[godocdown](https://github.com/robertkrimen/godocdown).md with `godocdown github.com/alecthomas/gozmq > README.md`)*\n"
  },
  {
    "path": ".todo2",
    "content": "{\n  \"title\": \"GoZMQ - ZMQ bindings for Go\",\n  \"tasks\": []\n}"
  },
  {
    "path": ".travis.yml",
    "content": "before_install:\n- sudo apt-get install libzmq3-dev\nlanguage: go\ngo: 1.1.1\ninstall: go get -tags zmq_3_x -d -v ./... && go build -tags zmq_3_x -v ./...\nscript: go test -v -tags zmq_3_x ./...\n"
  },
  {
    "path": "AUTHORS",
    "content": "The GoZmq package was originally written by Alec Thomas <alec@swapoff.org>.\n\nThanks to the following frequent contributors:\n\n  @mcgoo Jim McGrath (https://github.com/mcgoo)\n  @jtacoma Joshua Tacoma (https://github.com/jtacoma)\n  @jhawk28\n\nAnd many others.\n"
  },
  {
    "path": "README.md",
    "content": "# _NOTE:_ These gozmq bindings are in maintenance mode. Only critical bugs will be fixed. Henceforth I would suggest using [@pebbe's](https://github.com/pebbe) actively maintained bindings for [zmq2](https://github.com/pebbe/zmq2), [zmq3](https://github.com/pebbe/zmq3) and [zmq4](https://github.com/pebbe/zmq4).\n\n## Go (golang) Bindings for 0mq (zmq, zeromq)\n\n[![Build Status](https://travis-ci.org/alecthomas/gozmq.png)](https://travis-ci.org/alecthomas/gozmq)\n\nThis package implements [Go](http://golang.org) (golang) bindings for\nthe [0mq](http://zeromq.org) C API.\n\nGoZMQ [does not](#zero-copy) support zero-copy.\n\nA full list of examples is included in the [zguide](https://github.com/imatix/zguide/tree/master/examples/Go).\n\nNote that this is *not* the same as [this\nimplementation](http://github.com/boggle/gozero) or [this\nimplementation](http://code.google.com/p/gozmq/).\n\n## Upgrading\n\nGoZMQ has made some public changes that will break old code.  Fortunately, we've also written a tool based on `go fix` that will upgrade your code for you!  Here's how to run it over your source (after making a backup of course):\n\n    go get github.com/alecthomas/gozmq/gozmqfix\n    cd $YOUR_SOURCE_DIR\n    gozmqfix .\n\n## Installing\n\nGoZMQ currently supports ZMQ 2.1.x, 2.2.x, 3.x and 4.x. Following are instructions on how to compile against these versions.\n\nFor ZeroMQ 2.2.x install with:\n\n    go get github.com/alecthomas/gozmq\n\nFor 2.1.x install with:\n\n    go get -tags zmq_2_1 github.com/alecthomas/gozmq\n\nFor 3.x install with:\n\n    go get -tags zmq_3_x github.com/alecthomas/gozmq\n    \nFor 4.x install with:\n\n    go get -tags zmq_4_x github.com/alecthomas/gozmq\n\n### Troubleshooting\n\n#### Go can't find ZMQ\n\nIf the go tool can't find zmq and you know it is installed, you may need to override the C compiler/linker flags.\n\neg. If you installed zmq into `/opt/zmq` you might try:\n\n  CGO_CFLAGS=-I/opt/zmq/include CGO_LDFLAGS=-L/opt/zmq/lib \\\n    go get github.com/alecthomas/gozmq\n\n#### Mismatch in version of ZMQ\n\nIf you get errors like this with 'go get' or 'go build':\n\n    1: error: 'ZMQ_FOO' undeclared (first use in this function)\n\nThere are two possibilities:\n\n1. Your version of zmq is *very* old. In this case you will need to download and build zmq yourself.\n2. You are building gozmq against the wrong version of zmq. See the [installation](#installation) instructions for details on how to target the correct version.\n\n## Differences from the C API\n\nThe API implemented by this package does not attempt to expose\n`zmq_msg_t` at all. Instead, `Recv()` and `Send()` both operate on byte\nslices, allocating and freeing the memory automatically. Currently this\nrequires copying to/from C malloced memory, but a future implementation\nmay be able to avoid this to a certain extent.\n\nAll major features are supported: contexts, sockets, devices, and polls.\n\n## Example\n\nHere are direct translations of some of the examples from [this blog\npost](http://nichol.as/zeromq-an-introduction).\n\nA simple echo server:\n\n```go\npackage main\n\nimport zmq \"github.com/alecthomas/gozmq\"\n\nfunc main() {\n  context, _ := zmq.NewContext()\n  socket, _ := context.NewSocket(zmq.REP)\n  socket.Bind(\"tcp://127.0.0.1:5000\")\n  socket.Bind(\"tcp://127.0.0.1:6000\")\n\n  for {\n    msg, _ := socket.Recv(0)\n    println(\"Got\", string(msg))\n    socket.Send(msg, 0)\n  }\n}\n```\n\nA simple client for the above server:\n\n```go\npackage main\n\nimport \"fmt\"\nimport zmq \"github.com/alecthomas/gozmq\"\n\nfunc main() {\n  context, _ := zmq.NewContext()\n  socket, _ := context.NewSocket(zmq.REQ)\n  socket.Connect(\"tcp://127.0.0.1:5000\")\n  socket.Connect(\"tcp://127.0.0.1:6000\")\n\n  for i := 0; i < 10; i++ {\n    msg := fmt.Sprintf(\"msg %d\", i)\n    socket.Send([]byte(msg), 0)\n    println(\"Sending\", msg)\n    socket.Recv(0)\n  }\n}\n```\n\n## Caveats\n\n### Zero-copy\n\nGoZMQ does not support zero-copy.\n\nGoZMQ does not attempt to expose `zmq_msg_t` at all. Instead, `Recv()` and `Send()`\nboth operate on byte slices, allocating and freeing the memory automatically.\nCurrently this requires copying to/from C malloced memory, but a future\nimplementation may be able to avoid this to a certain extent.\n\n\n### Memory management\n\nIt's not entirely clear from the 0mq documentation how memory for\n`zmq_msg_t` and packet data is managed once 0mq takes ownership. After\ndigging into the source a little, this package operates under the\nfollowing (educated) assumptions:\n\n-   References to `zmq_msg_t` structures are not held by the C API\n    beyond the duration of any function call.\n-   Packet data is reference counted internally by the C API. The count\n    is incremented when a packet is queued for delivery to a destination\n    (the inference being that for delivery to N destinations, the\n    reference count will be incremented N times) and decremented once\n    the packet has either been delivered or errored.\n\n## Usage\n\n```go\nconst (\n  // NewSocket types\n  PAIR   = SocketType(C.ZMQ_PAIR)\n  PUB    = SocketType(C.ZMQ_PUB)\n  SUB    = SocketType(C.ZMQ_SUB)\n  REQ    = SocketType(C.ZMQ_REQ)\n  REP    = SocketType(C.ZMQ_REP)\n  DEALER = SocketType(C.ZMQ_DEALER)\n  ROUTER = SocketType(C.ZMQ_ROUTER)\n  PULL   = SocketType(C.ZMQ_PULL)\n  PUSH   = SocketType(C.ZMQ_PUSH)\n  XPUB   = SocketType(C.ZMQ_XPUB)\n  XSUB   = SocketType(C.ZMQ_XSUB)\n\n  // Deprecated aliases\n  XREQ       = DEALER\n  XREP       = ROUTER\n  UPSTREAM   = PULL\n  DOWNSTREAM = PUSH\n\n  // NewSocket options\n  AFFINITY          = UInt64SocketOption(C.ZMQ_AFFINITY)\n  IDENTITY          = StringSocketOption(C.ZMQ_IDENTITY)\n  SUBSCRIBE         = StringSocketOption(C.ZMQ_SUBSCRIBE)\n  UNSUBSCRIBE       = StringSocketOption(C.ZMQ_UNSUBSCRIBE)\n  RATE              = Int64SocketOption(C.ZMQ_RATE)\n  RECOVERY_IVL      = Int64SocketOption(C.ZMQ_RECOVERY_IVL)\n  SNDBUF            = UInt64SocketOption(C.ZMQ_SNDBUF)\n  RCVBUF            = UInt64SocketOption(C.ZMQ_RCVBUF)\n  FD                = Int64SocketOption(C.ZMQ_FD)\n  EVENTS            = UInt64SocketOption(C.ZMQ_EVENTS)\n  TYPE              = UInt64SocketOption(C.ZMQ_TYPE)\n  LINGER            = IntSocketOption(C.ZMQ_LINGER)\n  RECONNECT_IVL     = IntSocketOption(C.ZMQ_RECONNECT_IVL)\n  RECONNECT_IVL_MAX = IntSocketOption(C.ZMQ_RECONNECT_IVL_MAX)\n  BACKLOG           = IntSocketOption(C.ZMQ_BACKLOG)\n\n  // Send/recv options\n  SNDMORE = SendRecvOption(C.ZMQ_SNDMORE)\n)\n```\n\n```go\nconst (\n  POLLIN  = PollEvents(C.ZMQ_POLLIN)\n  POLLOUT = PollEvents(C.ZMQ_POLLOUT)\n  POLLERR = PollEvents(C.ZMQ_POLLERR)\n)\n```\n\n```go\nconst (\n  STREAMER  = DeviceType(C.ZMQ_STREAMER)\n  FORWARDER = DeviceType(C.ZMQ_FORWARDER)\n  QUEUE     = DeviceType(C.ZMQ_QUEUE)\n)\n```\n\n```go\nconst (\n  RCVTIMEO = IntSocketOption(C.ZMQ_RCVTIMEO)\n  SNDTIMEO = IntSocketOption(C.ZMQ_SNDTIMEO)\n)\n```\n\n```go\nconst (\n  RCVMORE           = UInt64SocketOption(C.ZMQ_RCVMORE)\n  RECOVERY_IVL_MSEC = Int64SocketOption(C.ZMQ_RECOVERY_IVL_MSEC)\n  SWAP              = Int64SocketOption(C.ZMQ_SWAP)\n  MCAST_LOOP        = Int64SocketOption(C.ZMQ_MCAST_LOOP)\n  HWM               = UInt64SocketOption(C.ZMQ_HWM)\n  NOBLOCK           = SendRecvOption(C.ZMQ_NOBLOCK)\n\n  // Forwards-compatible aliases:\n  DONTWAIT = NOBLOCK\n)\n```\n\n```go\nconst (\n  RCVMORE = IntSocketOption(C.ZMQ_RCVMORE)\n  SNDHWM  = IntSocketOption(C.ZMQ_SNDHWM)\n  RCVHWM  = IntSocketOption(C.ZMQ_RCVHWM)\n\n  // TODO Not documented in the man page...\n  //LAST_ENDPOINT       = UInt64SocketOption(C.ZMQ_LAST_ENDPOINT)\n  FAIL_UNROUTABLE     = BoolSocketOption(C.ZMQ_FAIL_UNROUTABLE)\n  TCP_KEEPALIVE       = IntSocketOption(C.ZMQ_TCP_KEEPALIVE)\n  TCP_KEEPALIVE_CNT   = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_CNT)\n  TCP_KEEPALIVE_IDLE  = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_IDLE)\n  TCP_KEEPALIVE_INTVL = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_INTVL)\n  TCP_ACCEPT_FILTER   = StringSocketOption(C.ZMQ_TCP_ACCEPT_FILTER)\n\n  // Message options\n  MORE = MessageOption(C.ZMQ_MORE)\n\n  // Send/recv options\n  DONTWAIT = SendRecvOption(C.ZMQ_DONTWAIT)\n\n  // Deprecated aliases\n  NOBLOCK = DONTWAIT\n)\n```\n\n```go\nvar (\n  // Additional ZMQ errors\n  ENOTSOCK       error = zmqErrno(C.ENOTSOCK)\n  EFSM           error = zmqErrno(C.EFSM)\n  EINVAL         error = zmqErrno(C.EINVAL)\n  ENOCOMPATPROTO error = zmqErrno(C.ENOCOMPATPROTO)\n  ETERM          error = zmqErrno(C.ETERM)\n  EMTHREAD       error = zmqErrno(C.EMTHREAD)\n)\n```\n\n#### func  Device\n\n```go\nfunc Device(t DeviceType, in, out *Socket) error\n```\nrun a zmq_device passing messages between in and out\n\n#### func  Poll\n\n```go\nfunc Poll(items []PollItem, timeout time.Duration) (count int, err error)\n```\nPoll ZmqSockets and file descriptors for I/O readiness. Timeout is in\ntime.Duration. The smallest possible timeout is time.Millisecond for ZeroMQ\nversion 3 and above, and time.Microsecond for earlier versions.\n\n#### func  Proxy\n\n```go\nfunc Proxy(in, out, capture *Socket) error\n```\nrun a zmq_proxy with in, out and capture sockets\n\n#### func  Version\n\n```go\nfunc Version() (int, int, int)\n```\nvoid zmq_version (int *major, int *minor, int *patch);\n\n#### type BoolSocketOption\n\n```go\ntype BoolSocketOption int\n```\n\n\n#### type Context\n\n```go\ntype Context struct {\n}\n```\n\n* A context handles socket creation and asynchronous message delivery. * There\nshould generally be one context per application.\n\n#### func  NewContext\n\n```go\nfunc NewContext() (*Context, error)\n```\nCreate a new context.\n\n#### func (*Context) Close\n\n```go\nfunc (c *Context) Close()\n```\n\n#### func (*Context) IOThreads\n\n```go\nfunc (c *Context) IOThreads() (int, error)\n```\nGet a context option.\n\n#### func (*Context) MaxSockets\n\n```go\nfunc (c *Context) MaxSockets() (int, error)\n```\n\n#### func (*Context) NewSocket\n\n```go\nfunc (c *Context) NewSocket(t SocketType) (*Socket, error)\n```\nCreate a new socket. void *zmq_socket (void *context, int type);\n\n#### func (*Context) SetIOThreads\n\n```go\nfunc (c *Context) SetIOThreads(value int) error\n```\nSet a context option.\n\n#### func (*Context) SetMaxSockets\n\n```go\nfunc (c *Context) SetMaxSockets(value int) error\n```\n\n#### type DeviceType\n\n```go\ntype DeviceType int\n```\n\n\n#### type Int64SocketOption\n\n```go\ntype Int64SocketOption int\n```\n\n\n#### type IntSocketOption\n\n```go\ntype IntSocketOption int\n```\n\n\n#### type MessageOption\n\n```go\ntype MessageOption int\n```\n\n\n#### type PollEvents\n\n```go\ntype PollEvents C.short\n```\n\n\n#### type PollItem\n\n```go\ntype PollItem struct {\n  Socket  *Socket         // socket to poll for events on\n  Fd      ZmqOsSocketType // fd to poll for events on as returned from os.File.Fd()\n  Events  PollEvents      // event set to poll for\n  REvents PollEvents      // events that were present\n}\n```\n\nItem to poll for read/write events on, either a *Socket or a file descriptor\n\n#### type PollItems\n\n```go\ntype PollItems []PollItem\n```\n\na set of items to poll for events on\n\n#### type SendRecvOption\n\n```go\ntype SendRecvOption int\n```\n\n\n#### type Socket\n\n```go\ntype Socket struct {\n}\n```\n\n\n#### func (*Socket) Affinity\n\n```go\nfunc (s *Socket) Affinity() (uint64, error)\n```\nZMQ_AFFINITY: Retrieve I/O thread affinity.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc7\n\n#### func (*Socket) Backlog\n\n```go\nfunc (s *Socket) Backlog() (int, error)\n```\nZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc18\n\n#### func (*Socket) Bind\n\n```go\nfunc (s *Socket) Bind(address string) error\n```\nBind the socket to a listening address. int zmq_bind (void *s, const char\n*addr);\n\n#### func (*Socket) Close\n\n```go\nfunc (s *Socket) Close() error\n```\nShutdown the socket. int zmq_close (void *s);\n\n#### func (*Socket) Connect\n\n```go\nfunc (s *Socket) Connect(address string) error\n```\nConnect the socket to an address. int zmq_connect (void *s, const char *addr);\n\n#### func (*Socket) Events\n\n```go\nfunc (s *Socket) Events() (uint64, error)\n```\nZMQ_EVENTS: Retrieve socket event state.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc20\n\n#### func (*Socket) GetSockOptBool\n\n```go\nfunc (s *Socket) GetSockOptBool(option BoolSocketOption) (value bool, err error)\n```\n\n#### func (*Socket) GetSockOptInt\n\n```go\nfunc (s *Socket) GetSockOptInt(option IntSocketOption) (value int, err error)\n```\nGet an int option from the socket. int zmq_getsockopt (void *s, int option, void\n*optval, size_t *optvallen);\n\n#### func (*Socket) GetSockOptInt64\n\n```go\nfunc (s *Socket) GetSockOptInt64(option Int64SocketOption) (value int64, err error)\n```\nGet an int64 option from the socket. int zmq_getsockopt (void *s, int option,\nvoid *optval, size_t *optvallen);\n\n#### func (*Socket) GetSockOptString\n\n```go\nfunc (s *Socket) GetSockOptString(option StringSocketOption) (value string, err error)\n```\nGet a string option from the socket. int zmq_getsockopt (void *s, int option,\nvoid *optval, size_t *optvallen);\n\n#### func (*Socket) GetSockOptUInt64\n\n```go\nfunc (s *Socket) GetSockOptUInt64(option UInt64SocketOption) (value uint64, err error)\n```\nGet a uint64 option from the socket. int zmq_getsockopt (void *s, int option,\nvoid *optval, size_t *optvallen);\n\n#### func (*Socket) HWM\n\n```go\nfunc (s *Socket) HWM() (uint64, error)\n```\nZMQ_HWM: Retrieve high water mark.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc5\n\n#### func (*Socket) Identity\n\n```go\nfunc (s *Socket) Identity() (string, error)\n```\nZMQ_IDENTITY: Retrieve socket identity.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc8\n\n#### func (*Socket) Linger\n\n```go\nfunc (s *Socket) Linger() (time.Duration, error)\n```\nZMQ_LINGER: Retrieve linger period for socket shutdown.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc15\n\n#### func (*Socket) McastLoop\n\n```go\nfunc (s *Socket) McastLoop() (bool, error)\n```\nZMQ_MCAST_LOOP: Control multicast loop-back.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc12\n\n#### func (*Socket) Rate\n\n```go\nfunc (s *Socket) Rate() (int64, error)\n```\nZMQ_RATE: Retrieve multicast data rate.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc9\n\n#### func (*Socket) RcvBuf\n\n```go\nfunc (s *Socket) RcvBuf() (uint64, error)\n```\nZMQ_RCVBUF: Retrieve kernel receive buffer size.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc14\n\n#### func (*Socket) RcvHWM\n\n```go\nfunc (s *Socket) RcvHWM() (int, error)\n```\nZMQ_RCVHWM: Retrieve high water mark for inbound messages.\n\nSee: http://api.zeromq.org/3.2:zmq-getsockopt#toc6\n\n#### func (*Socket) RcvMore\n\n```go\nfunc (s *Socket) RcvMore() (bool, error)\n```\nZMQ_RCVMORE: More message parts to follow.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc4\n\n#### func (*Socket) RcvTimeout\n\n```go\nfunc (s *Socket) RcvTimeout() (time.Duration, error)\n```\nZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.\n\nSee: http://api.zeromq.org/2.2:zmq-getsockopt#toc6\n\n#### func (*Socket) ReconnectIvl\n\n```go\nfunc (s *Socket) ReconnectIvl() (time.Duration, error)\n```\nZMQ_RECONNECT_IVL: Retrieve reconnection interval.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc16\n\n#### func (*Socket) ReconnectIvlMax\n\n```go\nfunc (s *Socket) ReconnectIvlMax() (time.Duration, error)\n```\nZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc17\n\n#### func (*Socket) RecoveryIvl\n\n```go\nfunc (s *Socket) RecoveryIvl() (time.Duration, error)\n```\nZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc11\n\n#### func (*Socket) Recv\n\n```go\nfunc (s *Socket) Recv(flags SendRecvOption) (data []byte, err error)\n```\nReceive a message from the socket. int zmq_recv (void *s, zmq_msg_t *msg, int\nflags);\n\n#### func (*Socket) RecvMultipart\n\n```go\nfunc (s *Socket) RecvMultipart(flags SendRecvOption) (parts [][]byte, err error)\n```\nReceive a multipart message.\n\n#### func (*Socket) Send\n\n```go\nfunc (s *Socket) Send(data []byte, flags SendRecvOption) error\n```\nSend a message to the socket. int zmq_send (void *s, zmq_msg_t *msg, int flags);\n\n#### func (*Socket) SendMultipart\n\n```go\nfunc (s *Socket) SendMultipart(parts [][]byte, flags SendRecvOption) (err error)\n```\nSend a multipart message.\n\n#### func (*Socket) SetAffinity\n\n```go\nfunc (s *Socket) SetAffinity(value uint64) error\n```\nZMQ_AFFINITY: Set I/O thread affinity.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc5\n\n#### func (*Socket) SetBacklog\n\n```go\nfunc (s *Socket) SetBacklog(value int) error\n```\nZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc18\n\n#### func (*Socket) SetHWM\n\n```go\nfunc (s *Socket) SetHWM(value uint64) error\n```\nZMQ_HWM: Set high water mark.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc3\n\n#### func (*Socket) SetIdentity\n\n```go\nfunc (s *Socket) SetIdentity(value string) error\n```\nZMQ_IDENTITY: Set socket identity.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc6\n\n#### func (*Socket) SetLinger\n\n```go\nfunc (s *Socket) SetLinger(value time.Duration) error\n```\nZMQ_LINGER: Set linger period for socket shutdown.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc15\n\n#### func (*Socket) SetMcastLoop\n\n```go\nfunc (s *Socket) SetMcastLoop(value bool) error\n```\nZMQ_MCAST_LOOP: Control multicast loop-back.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc12\n\n#### func (*Socket) SetRate\n\n```go\nfunc (s *Socket) SetRate(value int64) error\n```\nZMQ_RATE: Set multicast data rate.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc9\n\n#### func (*Socket) SetRcvBuf\n\n```go\nfunc (s *Socket) SetRcvBuf(value uint64) error\n```\nZMQ_RCVBUF: Set kernel receive buffer size.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc14\n\n#### func (*Socket) SetRcvHWM\n\n```go\nfunc (s *Socket) SetRcvHWM(value int) error\n```\nZMQ_RCVHWM: Set high water mark for inbound messages.\n\nSee: http://api.zeromq.org/3.2:zmq-setsockopt#toc4\n\n#### func (*Socket) SetRcvTimeout\n\n```go\nfunc (s *Socket) SetRcvTimeout(value time.Duration) error\n```\nZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.\n\nSee: http://api.zeromq.org/2.2:zmq-setsockopt#toc9\n\n#### func (*Socket) SetReconnectIvl\n\n```go\nfunc (s *Socket) SetReconnectIvl(value time.Duration) error\n```\nZMQ_RECONNECT_IVL: Set reconnection interval.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc16\n\n#### func (*Socket) SetReconnectIvlMax\n\n```go\nfunc (s *Socket) SetReconnectIvlMax(value time.Duration) error\n```\nZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc17\n\n#### func (*Socket) SetRecoveryIvl\n\n```go\nfunc (s *Socket) SetRecoveryIvl(value time.Duration) error\n```\nZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc11\n\n#### func (*Socket) SetSndBuf\n\n```go\nfunc (s *Socket) SetSndBuf(value uint64) error\n```\nZMQ_SNDBUF: Set kernel transmit buffer size.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc13\n\n#### func (*Socket) SetSndHWM\n\n```go\nfunc (s *Socket) SetSndHWM(value int) error\n```\nZMQ_SNDHWM: Set high water mark for outbound messages.\n\nSee: http://api.zeromq.org/3.2:zmq-setsockopt#toc3\n\n#### func (*Socket) SetSndTimeout\n\n```go\nfunc (s *Socket) SetSndTimeout(value time.Duration) error\n```\nZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.\n\nSee: http://api.zeromq.org/2.2:zmq-setsockopt#toc10\n\n#### func (*Socket) SetSockOptInt\n\n```go\nfunc (s *Socket) SetSockOptInt(option IntSocketOption, value int) error\n```\nSet an int option on the socket. int zmq_setsockopt (void *s, int option, const\nvoid *optval, size_t optvallen);\n\n#### func (*Socket) SetSockOptInt64\n\n```go\nfunc (s *Socket) SetSockOptInt64(option Int64SocketOption, value int64) error\n```\nSet an int64 option on the socket. int zmq_setsockopt (void *s, int option,\nconst void *optval, size_t optvallen);\n\n#### func (*Socket) SetSockOptString\n\n```go\nfunc (s *Socket) SetSockOptString(option StringSocketOption, value string) error\n```\nSet a string option on the socket. int zmq_setsockopt (void *s, int option,\nconst void *optval, size_t optvallen);\n\n#### func (*Socket) SetSockOptStringNil\n\n```go\nfunc (s *Socket) SetSockOptStringNil(option StringSocketOption) error\n```\nSet a string option on the socket to nil. int zmq_setsockopt (void *s, int\noption, const void *optval, size_t optvallen);\n\n#### func (*Socket) SetSockOptUInt64\n\n```go\nfunc (s *Socket) SetSockOptUInt64(option UInt64SocketOption, value uint64) error\n```\nSet a uint64 option on the socket. int zmq_setsockopt (void *s, int option,\nconst void *optval, size_t optvallen);\n\n#### func (*Socket) SetSubscribe\n\n```go\nfunc (s *Socket) SetSubscribe(value string) error\n```\nZMQ_SUBSCRIBE: Establish message filter.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc7\n\n#### func (*Socket) SetSwap\n\n```go\nfunc (s *Socket) SetSwap(value int64) error\n```\nZMQ_SWAP: Set disk offload size.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc4\n\n#### func (*Socket) SetTCPKeepalive\n\n```go\nfunc (s *Socket) SetTCPKeepalive(value int) error\n```\nZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.\n\nSee: http://api.zeromq.org/3.2:zmq-setsockopt#toc25\n\n#### func (*Socket) SetTCPKeepaliveCnt\n\n```go\nfunc (s *Socket) SetTCPKeepaliveCnt(value int) error\n```\nZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.\n\nSee: http://api.zeromq.org/3.2:zmq-setsockopt#toc27\n\n#### func (*Socket) SetTCPKeepaliveIdle\n\n```go\nfunc (s *Socket) SetTCPKeepaliveIdle(value int) error\n```\nZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).\n\nSee: http://api.zeromq.org/3.2:zmq-setsockopt#toc26\n\n#### func (*Socket) SetTCPKeepaliveIntvl\n\n```go\nfunc (s *Socket) SetTCPKeepaliveIntvl(value int) error\n```\nZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.\n\nSee: http://api.zeromq.org/3.2:zmq-setsockopt#toc28\n\n#### func (*Socket) SetUnsubscribe\n\n```go\nfunc (s *Socket) SetUnsubscribe(value string) error\n```\nZMQ_UNSUBSCRIBE: Remove message filter.\n\nSee: http://api.zeromq.org/2.1:zmq-setsockopt#toc8\n\n#### func (*Socket) SndBuf\n\n```go\nfunc (s *Socket) SndBuf() (uint64, error)\n```\nZMQ_SNDBUF: Retrieve kernel transmit buffer size.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc13\n\n#### func (*Socket) SndHWM\n\n```go\nfunc (s *Socket) SndHWM() (int, error)\n```\nZMQ_SNDHWM: Retrieves high water mark for outbound messages.\n\nSee: http://api.zeromq.org/3.2:zmq-getsockopt#toc5\n\n#### func (*Socket) SndTimeout\n\n```go\nfunc (s *Socket) SndTimeout() (time.Duration, error)\n```\nZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.\n\nSee: http://api.zeromq.org/2.2:zmq-getsockopt#toc7\n\n#### func (*Socket) Swap\n\n```go\nfunc (s *Socket) Swap() (int64, error)\n```\nZMQ_SWAP: Retrieve disk offload size.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc6\n\n#### func (*Socket) TCPKeepalive\n\n```go\nfunc (s *Socket) TCPKeepalive() (int, error)\n```\nZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.\n\nSee: http://api.zeromq.org/3.2:zmq-getsockopt#toc26\n\n#### func (*Socket) TCPKeepaliveCnt\n\n```go\nfunc (s *Socket) TCPKeepaliveCnt() (int, error)\n```\nZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.\n\nSee: http://api.zeromq.org/3.2:zmq-getsockopt#toc28\n\n#### func (*Socket) TCPKeepaliveIdle\n\n```go\nfunc (s *Socket) TCPKeepaliveIdle() (int, error)\n```\nZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).\n\nSee: http://api.zeromq.org/3.2:zmq-getsockopt#toc27\n\n#### func (*Socket) TCPKeepaliveIntvl\n\n```go\nfunc (s *Socket) TCPKeepaliveIntvl() (int, error)\n```\nZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.\n\nSee: http://api.zeromq.org/3.2:zmq-getsockopt#toc29\n\n#### func (*Socket) Type\n\n```go\nfunc (s *Socket) Type() (SocketType, error)\n```\nZMQ_TYPE: Retrieve socket type.\n\nSee: http://api.zeromq.org/2.1:zmq-getsockopt#toc3\n\n#### type SocketType\n\n```go\ntype SocketType int\n```\n\n\n#### type StringSocketOption\n\n```go\ntype StringSocketOption int\n```\n\n\n#### type UInt64SocketOption\n\n```go\ntype UInt64SocketOption int\n```\n\n\n#### type ZmqOsSocketType\n\n```go\ntype ZmqOsSocketType C.SOCKET\n```\n\n\n#### func (ZmqOsSocketType) ToRaw\n\n```go\nfunc (self ZmqOsSocketType) ToRaw() C.SOCKET\n```\n\n*(generated from .[godocdown](https://github.com/robertkrimen/godocdown).md with `godocdown github.com/alecthomas/gozmq > README.md`)*\n"
  },
  {
    "path": "examples/client/client.go",
    "content": "/*\n  Copyright 2010 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\npackage main\n\nimport \"fmt\"\nimport zmq \"github.com/alecthomas/gozmq\"\n\nfunc main() {\n\tcontext, _ := zmq.NewContext()\n\tsocket, _ := context.NewSocket(zmq.REQ)\n\tsocket.Connect(\"tcp://127.0.0.1:5000\")\n\tsocket.Connect(\"tcp://127.0.0.1:6000\")\n\n\tfor i := 0; i < 10; i++ {\n\t\tmsg := fmt.Sprintf(\"msg %d\", i)\n\t\tsocket.Send([]byte(msg), 0)\n\t\tprintln(\"Sending\", msg)\n\t\tsocket.Recv(0)\n\t}\n}\n"
  },
  {
    "path": "examples/server/server.go",
    "content": "/*\n  Copyright 2010 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\npackage main\n\nimport zmq \"github.com/alecthomas/gozmq\"\n\nfunc main() {\n\tcontext, _ := zmq.NewContext()\n\tsocket, _ := context.NewSocket(zmq.REP)\n\tsocket.Bind(\"tcp://127.0.0.1:5000\")\n\tsocket.Bind(\"tcp://127.0.0.1:6000\")\n\n\tfor {\n\t\tmsg, _ := socket.Recv(0)\n\t\tprintln(\"Got\", string(msg))\n\t\tsocket.Send(msg, 0)\n\t}\n}\n"
  },
  {
    "path": "gozmqfix/LICENSE",
    "content": "Copyright (c) 2012 The Go Authors. All rights reserved.\nCopyright (c) 2013 Joshua Tacoma. All rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are\nmet:\n\n   * Redistributions of source code must retain the above copyright\nnotice, this list of conditions and the following disclaimer.\n   * Redistributions in binary form must reproduce the above\ncopyright notice, this list of conditions and the following disclaimer\nin the documentation and/or other materials provided with the\ndistribution.\n   * Neither the name of Google Inc. nor the names of its\ncontributors may be used to endorse or promote products derived from\nthis software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\nLIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\nA PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\nOWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\nSPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\nLIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\nDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\nTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\nOF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
  },
  {
    "path": "gozmqfix/README.md",
    "content": "# gozmqfix\n\nA `go tool fix` for gozmq projects.\n"
  },
  {
    "path": "gozmqfix/fix.go",
    "content": "// Copyright 2011 The Go Authors.  All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage main\n\nimport (\n\t\"fmt\"\n\t\"go/ast\"\n\t\"go/parser\"\n\t\"go/token\"\n\t\"os\"\n\t\"path\"\n\t\"reflect\"\n\t\"strconv\"\n\t\"strings\"\n)\n\ntype fix struct {\n\tname string\n\tdate string // date that fix was introduced, in YYYY-MM-DD format\n\tf    func(*ast.File) bool\n\tdesc string\n}\n\n// main runs sort.Sort(byName(fixes)) before printing list of fixes.\ntype byName []fix\n\nfunc (f byName) Len() int           { return len(f) }\nfunc (f byName) Swap(i, j int)      { f[i], f[j] = f[j], f[i] }\nfunc (f byName) Less(i, j int) bool { return f[i].name < f[j].name }\n\n// main runs sort.Sort(byDate(fixes)) before applying fixes.\ntype byDate []fix\n\nfunc (f byDate) Len() int           { return len(f) }\nfunc (f byDate) Swap(i, j int)      { f[i], f[j] = f[j], f[i] }\nfunc (f byDate) Less(i, j int) bool { return f[i].date < f[j].date }\n\nvar fixes []fix\n\nfunc register(f fix) {\n\tfixes = append(fixes, f)\n}\n\n// walk traverses the AST x, calling visit(y) for each node y in the tree but\n// also with a pointer to each ast.Expr, ast.Stmt, and *ast.BlockStmt,\n// in a bottom-up traversal.\nfunc walk(x interface{}, visit func(interface{})) {\n\twalkBeforeAfter(x, nop, visit)\n}\n\nfunc nop(interface{}) {}\n\n// walkBeforeAfter is like walk but calls before(x) before traversing\n// x's children and after(x) afterward.\nfunc walkBeforeAfter(x interface{}, before, after func(interface{})) {\n\tbefore(x)\n\n\tswitch n := x.(type) {\n\tdefault:\n\t\tpanic(fmt.Errorf(\"unexpected type %T in walkBeforeAfter\", x))\n\n\tcase nil:\n\n\t// pointers to interfaces\n\tcase *ast.Decl:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *ast.Expr:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *ast.Spec:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *ast.Stmt:\n\t\twalkBeforeAfter(*n, before, after)\n\n\t// pointers to struct pointers\n\tcase **ast.BlockStmt:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase **ast.CallExpr:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase **ast.FieldList:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase **ast.FuncType:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase **ast.Ident:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase **ast.BasicLit:\n\t\twalkBeforeAfter(*n, before, after)\n\n\t// pointers to slices\n\tcase *[]ast.Decl:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *[]ast.Expr:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *[]*ast.File:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *[]*ast.Ident:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *[]ast.Spec:\n\t\twalkBeforeAfter(*n, before, after)\n\tcase *[]ast.Stmt:\n\t\twalkBeforeAfter(*n, before, after)\n\n\t// These are ordered and grouped to match ../../pkg/go/ast/ast.go\n\tcase *ast.Field:\n\t\twalkBeforeAfter(&n.Names, before, after)\n\t\twalkBeforeAfter(&n.Type, before, after)\n\t\twalkBeforeAfter(&n.Tag, before, after)\n\tcase *ast.FieldList:\n\t\tfor _, field := range n.List {\n\t\t\twalkBeforeAfter(field, before, after)\n\t\t}\n\tcase *ast.BadExpr:\n\tcase *ast.Ident:\n\tcase *ast.Ellipsis:\n\t\twalkBeforeAfter(&n.Elt, before, after)\n\tcase *ast.BasicLit:\n\tcase *ast.FuncLit:\n\t\twalkBeforeAfter(&n.Type, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.CompositeLit:\n\t\twalkBeforeAfter(&n.Type, before, after)\n\t\twalkBeforeAfter(&n.Elts, before, after)\n\tcase *ast.ParenExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\tcase *ast.SelectorExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\tcase *ast.IndexExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\t\twalkBeforeAfter(&n.Index, before, after)\n\tcase *ast.SliceExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\t\tif n.Low != nil {\n\t\t\twalkBeforeAfter(&n.Low, before, after)\n\t\t}\n\t\tif n.High != nil {\n\t\t\twalkBeforeAfter(&n.High, before, after)\n\t\t}\n\tcase *ast.TypeAssertExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\t\twalkBeforeAfter(&n.Type, before, after)\n\tcase *ast.CallExpr:\n\t\twalkBeforeAfter(&n.Fun, before, after)\n\t\twalkBeforeAfter(&n.Args, before, after)\n\tcase *ast.StarExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\tcase *ast.UnaryExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\tcase *ast.BinaryExpr:\n\t\twalkBeforeAfter(&n.X, before, after)\n\t\twalkBeforeAfter(&n.Y, before, after)\n\tcase *ast.KeyValueExpr:\n\t\twalkBeforeAfter(&n.Key, before, after)\n\t\twalkBeforeAfter(&n.Value, before, after)\n\n\tcase *ast.ArrayType:\n\t\twalkBeforeAfter(&n.Len, before, after)\n\t\twalkBeforeAfter(&n.Elt, before, after)\n\tcase *ast.StructType:\n\t\twalkBeforeAfter(&n.Fields, before, after)\n\tcase *ast.FuncType:\n\t\twalkBeforeAfter(&n.Params, before, after)\n\t\tif n.Results != nil {\n\t\t\twalkBeforeAfter(&n.Results, before, after)\n\t\t}\n\tcase *ast.InterfaceType:\n\t\twalkBeforeAfter(&n.Methods, before, after)\n\tcase *ast.MapType:\n\t\twalkBeforeAfter(&n.Key, before, after)\n\t\twalkBeforeAfter(&n.Value, before, after)\n\tcase *ast.ChanType:\n\t\twalkBeforeAfter(&n.Value, before, after)\n\n\tcase *ast.BadStmt:\n\tcase *ast.DeclStmt:\n\t\twalkBeforeAfter(&n.Decl, before, after)\n\tcase *ast.EmptyStmt:\n\tcase *ast.LabeledStmt:\n\t\twalkBeforeAfter(&n.Stmt, before, after)\n\tcase *ast.ExprStmt:\n\t\twalkBeforeAfter(&n.X, before, after)\n\tcase *ast.SendStmt:\n\t\twalkBeforeAfter(&n.Chan, before, after)\n\t\twalkBeforeAfter(&n.Value, before, after)\n\tcase *ast.IncDecStmt:\n\t\twalkBeforeAfter(&n.X, before, after)\n\tcase *ast.AssignStmt:\n\t\twalkBeforeAfter(&n.Lhs, before, after)\n\t\twalkBeforeAfter(&n.Rhs, before, after)\n\tcase *ast.GoStmt:\n\t\twalkBeforeAfter(&n.Call, before, after)\n\tcase *ast.DeferStmt:\n\t\twalkBeforeAfter(&n.Call, before, after)\n\tcase *ast.ReturnStmt:\n\t\twalkBeforeAfter(&n.Results, before, after)\n\tcase *ast.BranchStmt:\n\tcase *ast.BlockStmt:\n\t\twalkBeforeAfter(&n.List, before, after)\n\tcase *ast.IfStmt:\n\t\twalkBeforeAfter(&n.Init, before, after)\n\t\twalkBeforeAfter(&n.Cond, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\t\twalkBeforeAfter(&n.Else, before, after)\n\tcase *ast.CaseClause:\n\t\twalkBeforeAfter(&n.List, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.SwitchStmt:\n\t\twalkBeforeAfter(&n.Init, before, after)\n\t\twalkBeforeAfter(&n.Tag, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.TypeSwitchStmt:\n\t\twalkBeforeAfter(&n.Init, before, after)\n\t\twalkBeforeAfter(&n.Assign, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.CommClause:\n\t\twalkBeforeAfter(&n.Comm, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.SelectStmt:\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.ForStmt:\n\t\twalkBeforeAfter(&n.Init, before, after)\n\t\twalkBeforeAfter(&n.Cond, before, after)\n\t\twalkBeforeAfter(&n.Post, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\tcase *ast.RangeStmt:\n\t\twalkBeforeAfter(&n.Key, before, after)\n\t\twalkBeforeAfter(&n.Value, before, after)\n\t\twalkBeforeAfter(&n.X, before, after)\n\t\twalkBeforeAfter(&n.Body, before, after)\n\n\tcase *ast.ImportSpec:\n\tcase *ast.ValueSpec:\n\t\twalkBeforeAfter(&n.Type, before, after)\n\t\twalkBeforeAfter(&n.Values, before, after)\n\t\twalkBeforeAfter(&n.Names, before, after)\n\tcase *ast.TypeSpec:\n\t\twalkBeforeAfter(&n.Type, before, after)\n\n\tcase *ast.BadDecl:\n\tcase *ast.GenDecl:\n\t\twalkBeforeAfter(&n.Specs, before, after)\n\tcase *ast.FuncDecl:\n\t\tif n.Recv != nil {\n\t\t\twalkBeforeAfter(&n.Recv, before, after)\n\t\t}\n\t\twalkBeforeAfter(&n.Type, before, after)\n\t\tif n.Body != nil {\n\t\t\twalkBeforeAfter(&n.Body, before, after)\n\t\t}\n\n\tcase *ast.File:\n\t\twalkBeforeAfter(&n.Decls, before, after)\n\n\tcase *ast.Package:\n\t\twalkBeforeAfter(&n.Files, before, after)\n\n\tcase []*ast.File:\n\t\tfor i := range n {\n\t\t\twalkBeforeAfter(&n[i], before, after)\n\t\t}\n\tcase []ast.Decl:\n\t\tfor i := range n {\n\t\t\twalkBeforeAfter(&n[i], before, after)\n\t\t}\n\tcase []ast.Expr:\n\t\tfor i := range n {\n\t\t\twalkBeforeAfter(&n[i], before, after)\n\t\t}\n\tcase []*ast.Ident:\n\t\tfor i := range n {\n\t\t\twalkBeforeAfter(&n[i], before, after)\n\t\t}\n\tcase []ast.Stmt:\n\t\tfor i := range n {\n\t\t\twalkBeforeAfter(&n[i], before, after)\n\t\t}\n\tcase []ast.Spec:\n\t\tfor i := range n {\n\t\t\twalkBeforeAfter(&n[i], before, after)\n\t\t}\n\t}\n\tafter(x)\n}\n\n// imports returns true if f imports path.\nfunc imports(f *ast.File, path string) bool {\n\treturn importSpec(f, path) != nil\n}\n\n// importSpec returns the import spec if f imports path,\n// or nil otherwise.\nfunc importSpec(f *ast.File, path string) *ast.ImportSpec {\n\tfor _, s := range f.Imports {\n\t\tif importPath(s) == path {\n\t\t\treturn s\n\t\t}\n\t}\n\treturn nil\n}\n\n// importPath returns the unquoted import path of s,\n// or \"\" if the path is not properly quoted.\nfunc importPath(s *ast.ImportSpec) string {\n\tt, err := strconv.Unquote(s.Path.Value)\n\tif err == nil {\n\t\treturn t\n\t}\n\treturn \"\"\n}\n\n// declImports reports whether gen contains an import of path.\nfunc declImports(gen *ast.GenDecl, path string) bool {\n\tif gen.Tok != token.IMPORT {\n\t\treturn false\n\t}\n\tfor _, spec := range gen.Specs {\n\t\timpspec := spec.(*ast.ImportSpec)\n\t\tif importPath(impspec) == path {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\n\n// isPkgDot returns true if t is the expression \"pkg.name\"\n// where pkg is an imported identifier.\nfunc isPkgDot(t ast.Expr, pkg, name string) bool {\n\tsel, ok := t.(*ast.SelectorExpr)\n\treturn ok && isTopName(sel.X, pkg) && sel.Sel.String() == name\n}\n\n// isPtrPkgDot returns true if f is the expression \"*pkg.name\"\n// where pkg is an imported identifier.\nfunc isPtrPkgDot(t ast.Expr, pkg, name string) bool {\n\tptr, ok := t.(*ast.StarExpr)\n\treturn ok && isPkgDot(ptr.X, pkg, name)\n}\n\n// isTopName returns true if n is a top-level unresolved identifier with the given name.\nfunc isTopName(n ast.Expr, name string) bool {\n\tid, ok := n.(*ast.Ident)\n\treturn ok && id.Name == name && id.Obj == nil\n}\n\n// isName returns true if n is an identifier with the given name.\nfunc isName(n ast.Expr, name string) bool {\n\tid, ok := n.(*ast.Ident)\n\treturn ok && id.String() == name\n}\n\n// isCall returns true if t is a call to pkg.name.\nfunc isCall(t ast.Expr, pkg, name string) bool {\n\tcall, ok := t.(*ast.CallExpr)\n\treturn ok && isPkgDot(call.Fun, pkg, name)\n}\n\n// If n is an *ast.Ident, isIdent returns it; otherwise isIdent returns nil.\nfunc isIdent(n interface{}) *ast.Ident {\n\tid, _ := n.(*ast.Ident)\n\treturn id\n}\n\n// refersTo returns true if n is a reference to the same object as x.\nfunc refersTo(n ast.Node, x *ast.Ident) bool {\n\tid, ok := n.(*ast.Ident)\n\t// The test of id.Name == x.Name handles top-level unresolved\n\t// identifiers, which all have Obj == nil.\n\treturn ok && id.Obj == x.Obj && id.Name == x.Name\n}\n\n// isBlank returns true if n is the blank identifier.\nfunc isBlank(n ast.Expr) bool {\n\treturn isName(n, \"_\")\n}\n\n// isEmptyString returns true if n is an empty string literal.\nfunc isEmptyString(n ast.Expr) bool {\n\tlit, ok := n.(*ast.BasicLit)\n\treturn ok && lit.Kind == token.STRING && len(lit.Value) == 2\n}\n\nfunc warn(pos token.Pos, msg string, args ...interface{}) {\n\tif pos.IsValid() {\n\t\tmsg = \"%s: \" + msg\n\t\targ1 := []interface{}{fset.Position(pos).String()}\n\t\targs = append(arg1, args...)\n\t}\n\tfmt.Fprintf(os.Stderr, msg+\"\\n\", args...)\n}\n\n// countUses returns the number of uses of the identifier x in scope.\nfunc countUses(x *ast.Ident, scope []ast.Stmt) int {\n\tcount := 0\n\tff := func(n interface{}) {\n\t\tif n, ok := n.(ast.Node); ok && refersTo(n, x) {\n\t\t\tcount++\n\t\t}\n\t}\n\tfor _, n := range scope {\n\t\twalk(n, ff)\n\t}\n\treturn count\n}\n\n// rewriteUses replaces all uses of the identifier x and !x in scope\n// with f(x.Pos()) and fnot(x.Pos()).\nfunc rewriteUses(x *ast.Ident, f, fnot func(token.Pos) ast.Expr, scope []ast.Stmt) {\n\tvar lastF ast.Expr\n\tff := func(n interface{}) {\n\t\tptr, ok := n.(*ast.Expr)\n\t\tif !ok {\n\t\t\treturn\n\t\t}\n\t\tnn := *ptr\n\n\t\t// The child node was just walked and possibly replaced.\n\t\t// If it was replaced and this is a negation, replace with fnot(p).\n\t\tnot, ok := nn.(*ast.UnaryExpr)\n\t\tif ok && not.Op == token.NOT && not.X == lastF {\n\t\t\t*ptr = fnot(nn.Pos())\n\t\t\treturn\n\t\t}\n\t\tif refersTo(nn, x) {\n\t\t\tlastF = f(nn.Pos())\n\t\t\t*ptr = lastF\n\t\t}\n\t}\n\tfor _, n := range scope {\n\t\twalk(n, ff)\n\t}\n}\n\n// assignsTo returns true if any of the code in scope assigns to or takes the address of x.\nfunc assignsTo(x *ast.Ident, scope []ast.Stmt) bool {\n\tassigned := false\n\tff := func(n interface{}) {\n\t\tif assigned {\n\t\t\treturn\n\t\t}\n\t\tswitch n := n.(type) {\n\t\tcase *ast.UnaryExpr:\n\t\t\t// use of &x\n\t\t\tif n.Op == token.AND && refersTo(n.X, x) {\n\t\t\t\tassigned = true\n\t\t\t\treturn\n\t\t\t}\n\t\tcase *ast.AssignStmt:\n\t\t\tfor _, l := range n.Lhs {\n\t\t\t\tif refersTo(l, x) {\n\t\t\t\t\tassigned = true\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tfor _, n := range scope {\n\t\tif assigned {\n\t\t\tbreak\n\t\t}\n\t\twalk(n, ff)\n\t}\n\treturn assigned\n}\n\n// newPkgDot returns an ast.Expr referring to \"pkg.name\" at position pos.\nfunc newPkgDot(pos token.Pos, pkg, name string) ast.Expr {\n\treturn &ast.SelectorExpr{\n\t\tX: &ast.Ident{\n\t\t\tNamePos: pos,\n\t\t\tName:    pkg,\n\t\t},\n\t\tSel: &ast.Ident{\n\t\t\tNamePos: pos,\n\t\t\tName:    name,\n\t\t},\n\t}\n}\n\n// renameTop renames all references to the top-level name old.\n// It returns true if it makes any changes.\nfunc renameTop(f *ast.File, old, new string) bool {\n\tvar fixed bool\n\n\t// Rename any conflicting imports\n\t// (assuming package name is last element of path).\n\tfor _, s := range f.Imports {\n\t\tif s.Name != nil {\n\t\t\tif s.Name.Name == old {\n\t\t\t\ts.Name.Name = new\n\t\t\t\tfixed = true\n\t\t\t}\n\t\t} else {\n\t\t\t_, thisName := path.Split(importPath(s))\n\t\t\tif thisName == old {\n\t\t\t\ts.Name = ast.NewIdent(new)\n\t\t\t\tfixed = true\n\t\t\t}\n\t\t}\n\t}\n\n\t// Rename any top-level declarations.\n\tfor _, d := range f.Decls {\n\t\tswitch d := d.(type) {\n\t\tcase *ast.FuncDecl:\n\t\t\tif d.Recv == nil && d.Name.Name == old {\n\t\t\t\td.Name.Name = new\n\t\t\t\td.Name.Obj.Name = new\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.GenDecl:\n\t\t\tfor _, s := range d.Specs {\n\t\t\t\tswitch s := s.(type) {\n\t\t\t\tcase *ast.TypeSpec:\n\t\t\t\t\tif s.Name.Name == old {\n\t\t\t\t\t\ts.Name.Name = new\n\t\t\t\t\t\ts.Name.Obj.Name = new\n\t\t\t\t\t\tfixed = true\n\t\t\t\t\t}\n\t\t\t\tcase *ast.ValueSpec:\n\t\t\t\t\tfor _, n := range s.Names {\n\t\t\t\t\t\tif n.Name == old {\n\t\t\t\t\t\t\tn.Name = new\n\t\t\t\t\t\t\tn.Obj.Name = new\n\t\t\t\t\t\t\tfixed = true\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Rename top-level old to new, both unresolved names\n\t// (probably defined in another file) and names that resolve\n\t// to a declaration we renamed.\n\twalk(f, func(n interface{}) {\n\t\tid, ok := n.(*ast.Ident)\n\t\tif ok && isTopName(id, old) {\n\t\t\tid.Name = new\n\t\t\tfixed = true\n\t\t}\n\t\tif ok && id.Obj != nil && id.Name == old && id.Obj.Name == new {\n\t\t\tid.Name = id.Obj.Name\n\t\t\tfixed = true\n\t\t}\n\t})\n\n\treturn fixed\n}\n\n// matchLen returns the length of the longest prefix shared by x and y.\nfunc matchLen(x, y string) int {\n\ti := 0\n\tfor i < len(x) && i < len(y) && x[i] == y[i] {\n\t\ti++\n\t}\n\treturn i\n}\n\n// addImport adds the import path to the file f, if absent.\nfunc addImport(f *ast.File, ipath string) (added bool) {\n\tif imports(f, ipath) {\n\t\treturn false\n\t}\n\n\t// Determine name of import.\n\t// Assume added imports follow convention of using last element.\n\t_, name := path.Split(ipath)\n\n\t// Rename any conflicting top-level references from name to name_.\n\trenameTop(f, name, name+\"_\")\n\n\tnewImport := &ast.ImportSpec{\n\t\tPath: &ast.BasicLit{\n\t\t\tKind:  token.STRING,\n\t\t\tValue: strconv.Quote(ipath),\n\t\t},\n\t}\n\n\t// Find an import decl to add to.\n\tvar (\n\t\tbestMatch  = -1\n\t\tlastImport = -1\n\t\timpDecl    *ast.GenDecl\n\t\timpIndex   = -1\n\t)\n\tfor i, decl := range f.Decls {\n\t\tgen, ok := decl.(*ast.GenDecl)\n\t\tif ok && gen.Tok == token.IMPORT {\n\t\t\tlastImport = i\n\t\t\t// Do not add to import \"C\", to avoid disrupting the\n\t\t\t// association with its doc comment, breaking cgo.\n\t\t\tif declImports(gen, \"C\") {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Compute longest shared prefix with imports in this block.\n\t\t\tfor j, spec := range gen.Specs {\n\t\t\t\timpspec := spec.(*ast.ImportSpec)\n\t\t\t\tn := matchLen(importPath(impspec), ipath)\n\t\t\t\tif n > bestMatch {\n\t\t\t\t\tbestMatch = n\n\t\t\t\t\timpDecl = gen\n\t\t\t\t\timpIndex = j\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no import decl found, add one after the last import.\n\tif impDecl == nil {\n\t\timpDecl = &ast.GenDecl{\n\t\t\tTok: token.IMPORT,\n\t\t}\n\t\tf.Decls = append(f.Decls, nil)\n\t\tcopy(f.Decls[lastImport+2:], f.Decls[lastImport+1:])\n\t\tf.Decls[lastImport+1] = impDecl\n\t}\n\n\t// Ensure the import decl has parentheses, if needed.\n\tif len(impDecl.Specs) > 0 && !impDecl.Lparen.IsValid() {\n\t\timpDecl.Lparen = impDecl.Pos()\n\t}\n\n\tinsertAt := impIndex + 1\n\tif insertAt == 0 {\n\t\tinsertAt = len(impDecl.Specs)\n\t}\n\timpDecl.Specs = append(impDecl.Specs, nil)\n\tcopy(impDecl.Specs[insertAt+1:], impDecl.Specs[insertAt:])\n\timpDecl.Specs[insertAt] = newImport\n\tif insertAt > 0 {\n\t\t// Assign same position as the previous import,\n\t\t// so that the sorter sees it as being in the same block.\n\t\tprev := impDecl.Specs[insertAt-1]\n\t\tnewImport.Path.ValuePos = prev.Pos()\n\t\tnewImport.EndPos = prev.Pos()\n\t}\n\n\tf.Imports = append(f.Imports, newImport)\n\treturn true\n}\n\n// deleteImport deletes the import path from the file f, if present.\nfunc deleteImport(f *ast.File, path string) (deleted bool) {\n\toldImport := importSpec(f, path)\n\n\t// Find the import node that imports path, if any.\n\tfor i, decl := range f.Decls {\n\t\tgen, ok := decl.(*ast.GenDecl)\n\t\tif !ok || gen.Tok != token.IMPORT {\n\t\t\tcontinue\n\t\t}\n\t\tfor j, spec := range gen.Specs {\n\t\t\timpspec := spec.(*ast.ImportSpec)\n\t\t\tif oldImport != impspec {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// We found an import spec that imports path.\n\t\t\t// Delete it.\n\t\t\tdeleted = true\n\t\t\tcopy(gen.Specs[j:], gen.Specs[j+1:])\n\t\t\tgen.Specs = gen.Specs[:len(gen.Specs)-1]\n\n\t\t\t// If this was the last import spec in this decl,\n\t\t\t// delete the decl, too.\n\t\t\tif len(gen.Specs) == 0 {\n\t\t\t\tcopy(f.Decls[i:], f.Decls[i+1:])\n\t\t\t\tf.Decls = f.Decls[:len(f.Decls)-1]\n\t\t\t} else if len(gen.Specs) == 1 {\n\t\t\t\tgen.Lparen = token.NoPos // drop parens\n\t\t\t}\n\t\t\tif j > 0 {\n\t\t\t\t// We deleted an entry but now there will be\n\t\t\t\t// a blank line-sized hole where the import was.\n\t\t\t\t// Close the hole by making the previous\n\t\t\t\t// import appear to \"end\" where this one did.\n\t\t\t\tgen.Specs[j-1].(*ast.ImportSpec).EndPos = impspec.End()\n\t\t\t}\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Delete it from f.Imports.\n\tfor i, imp := range f.Imports {\n\t\tif imp == oldImport {\n\t\t\tcopy(f.Imports[i:], f.Imports[i+1:])\n\t\t\tf.Imports = f.Imports[:len(f.Imports)-1]\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn\n}\n\n// rewriteImport rewrites any import of path oldPath to path newPath.\nfunc rewriteImport(f *ast.File, oldPath, newPath string) (rewrote bool) {\n\tfor _, imp := range f.Imports {\n\t\tif importPath(imp) == oldPath {\n\t\t\trewrote = true\n\t\t\t// record old End, because the default is to compute\n\t\t\t// it using the length of imp.Path.Value.\n\t\t\timp.EndPos = imp.End()\n\t\t\timp.Path.Value = strconv.Quote(newPath)\n\t\t}\n\t}\n\treturn\n}\n\nfunc usesImport(f *ast.File, path string) (used bool) {\n\tspec := importSpec(f, path)\n\tif spec == nil {\n\t\treturn\n\t}\n\n\tname := spec.Name.String()\n\tswitch name {\n\tcase \"<nil>\":\n\t\t// If the package name is not explicitly specified,\n\t\t// make an educated guess. This is not guaranteed to be correct.\n\t\tlastSlash := strings.LastIndex(path, \"/\")\n\t\tif lastSlash == -1 {\n\t\t\tname = path\n\t\t} else {\n\t\t\tname = path[lastSlash+1:]\n\t\t}\n\tcase \"_\", \".\":\n\t\t// Not sure if this import is used - err on the side of caution.\n\t\treturn true\n\t}\n\n\twalk(f, func(n interface{}) {\n\t\tsel, ok := n.(*ast.SelectorExpr)\n\t\tif ok && isTopName(sel.X, name) {\n\t\t\tused = true\n\t\t}\n\t})\n\n\treturn\n}\n\nfunc expr(s string) ast.Expr {\n\tx, err := parser.ParseExpr(s)\n\tif err != nil {\n\t\tpanic(\"parsing \" + s + \": \" + err.Error())\n\t}\n\t// Remove position information to avoid spurious newlines.\n\tkillPos(reflect.ValueOf(x))\n\treturn x\n}\n\nvar posType = reflect.TypeOf(token.Pos(0))\n\nfunc killPos(v reflect.Value) {\n\tswitch v.Kind() {\n\tcase reflect.Ptr, reflect.Interface:\n\t\tif !v.IsNil() {\n\t\t\tkillPos(v.Elem())\n\t\t}\n\tcase reflect.Slice:\n\t\tn := v.Len()\n\t\tfor i := 0; i < n; i++ {\n\t\t\tkillPos(v.Index(i))\n\t\t}\n\tcase reflect.Struct:\n\t\tn := v.NumField()\n\t\tfor i := 0; i < n; i++ {\n\t\t\tf := v.Field(i)\n\t\t\tif f.Type() == posType {\n\t\t\t\tf.SetInt(0)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tkillPos(f)\n\t\t}\n\t}\n}\n\n// A Rename describes a single renaming.\ntype rename struct {\n\tOldImport string // only apply rename if this import is present\n\tNewImport string // add this import during rewrite\n\tOld       string // old name: p.T or *p.T\n\tNew       string // new name: p.T or *p.T\n}\n\nfunc renameFix(tab []rename) func(*ast.File) bool {\n\treturn func(f *ast.File) bool {\n\t\treturn renameFixTab(f, tab)\n\t}\n}\n\nfunc parseName(s string) (ptr bool, pkg, nam string) {\n\ti := strings.Index(s, \".\")\n\tif i < 0 {\n\t\tpanic(\"parseName: invalid name \" + s)\n\t}\n\tif strings.HasPrefix(s, \"*\") {\n\t\tptr = true\n\t\ts = s[1:]\n\t\ti--\n\t}\n\tpkg = s[:i]\n\tnam = s[i+1:]\n\treturn\n}\n\nfunc renameFixTab(f *ast.File, tab []rename) bool {\n\tfixed := false\n\tadded := map[string]bool{}\n\tcheck := map[string]bool{}\n\tfor _, t := range tab {\n\t\tif !imports(f, t.OldImport) {\n\t\t\tcontinue\n\t\t}\n\t\toptr, opkg, onam := parseName(t.Old)\n\t\twalk(f, func(n interface{}) {\n\t\t\tnp, ok := n.(*ast.Expr)\n\t\t\tif !ok {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tx := *np\n\t\t\tif optr {\n\t\t\t\tp, ok := x.(*ast.StarExpr)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tx = p.X\n\t\t\t}\n\t\t\tif !isPkgDot(x, opkg, onam) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif t.NewImport != \"\" && !added[t.NewImport] {\n\t\t\t\taddImport(f, t.NewImport)\n\t\t\t\tadded[t.NewImport] = true\n\t\t\t}\n\t\t\t*np = expr(t.New)\n\t\t\tcheck[t.OldImport] = true\n\t\t\tfixed = true\n\t\t})\n\t}\n\n\tfor ipath := range check {\n\t\tif !usesImport(f, ipath) {\n\t\t\tdeleteImport(f, ipath)\n\t\t}\n\t}\n\treturn fixed\n}\n"
  },
  {
    "path": "gozmqfix/main.go",
    "content": "// Copyright 2011 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage main\n\nimport (\n\t\"bytes\"\n\t\"flag\"\n\t\"fmt\"\n\t\"go/ast\"\n\t\"go/parser\"\n\t\"go/printer\"\n\t\"go/scanner\"\n\t\"go/token\"\n\t\"io/ioutil\"\n\t\"os\"\n\t\"os/exec\"\n\t\"path/filepath\"\n\t\"sort\"\n\t\"strings\"\n)\n\nvar (\n\tfset     = token.NewFileSet()\n\texitCode = 0\n)\n\nvar allowedRewrites = flag.String(\"r\", \"\",\n\t\"restrict the rewrites to this comma-separated list\")\n\nvar forceRewrites = flag.String(\"force\", \"\",\n\t\"force these fixes to run even if the code looks updated\")\n\nvar allowed, force map[string]bool\n\nvar doDiff = flag.Bool(\"diff\", false, \"display diffs instead of rewriting files\")\n\n// enable for debugging fix failures\nconst debug = false // display incorrectly reformatted source and exit\n\nfunc usage() {\n\tfmt.Fprintf(os.Stderr, \"usage: go tool fix [-diff] [-r fixname,...] [-force fixname,...] [path ...]\\n\")\n\tflag.PrintDefaults()\n\tfmt.Fprintf(os.Stderr, \"\\nAvailable rewrites are:\\n\")\n\tsort.Sort(byName(fixes))\n\tfor _, f := range fixes {\n\t\tfmt.Fprintf(os.Stderr, \"\\n%s\\n\", f.name)\n\t\tdesc := strings.TrimSpace(f.desc)\n\t\tdesc = strings.Replace(desc, \"\\n\", \"\\n\\t\", -1)\n\t\tfmt.Fprintf(os.Stderr, \"\\t%s\\n\", desc)\n\t}\n\tos.Exit(2)\n}\n\nfunc main() {\n\tflag.Usage = usage\n\tflag.Parse()\n\n\tsort.Sort(byDate(fixes))\n\n\tif *allowedRewrites != \"\" {\n\t\tallowed = make(map[string]bool)\n\t\tfor _, f := range strings.Split(*allowedRewrites, \",\") {\n\t\t\tallowed[f] = true\n\t\t}\n\t}\n\n\tif *forceRewrites != \"\" {\n\t\tforce = make(map[string]bool)\n\t\tfor _, f := range strings.Split(*forceRewrites, \",\") {\n\t\t\tforce[f] = true\n\t\t}\n\t}\n\n\tif flag.NArg() == 0 {\n\t\tif err := processFile(\"standard input\", true); err != nil {\n\t\t\treport(err)\n\t\t}\n\t\tos.Exit(exitCode)\n\t}\n\n\tfor i := 0; i < flag.NArg(); i++ {\n\t\tpath := flag.Arg(i)\n\t\tswitch dir, err := os.Stat(path); {\n\t\tcase err != nil:\n\t\t\treport(err)\n\t\tcase dir.IsDir():\n\t\t\twalkDir(path)\n\t\tdefault:\n\t\t\tif err := processFile(path, false); err != nil {\n\t\t\t\treport(err)\n\t\t\t}\n\t\t}\n\t}\n\n\tos.Exit(exitCode)\n}\n\nconst (\n\ttabWidth    = 8\n\tparserMode  = parser.ParseComments\n\tprinterMode = printer.TabIndent | printer.UseSpaces\n)\n\nvar printConfig = &printer.Config{\n\tMode:     printerMode,\n\tTabwidth: tabWidth,\n}\n\nfunc gofmtFile(f *ast.File) ([]byte, error) {\n\tvar buf bytes.Buffer\n\n\tast.SortImports(fset, f)\n\terr := printConfig.Fprint(&buf, fset, f)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn buf.Bytes(), nil\n}\n\nfunc processFile(filename string, useStdin bool) error {\n\tvar f *os.File\n\tvar err error\n\tvar fixlog bytes.Buffer\n\n\tif useStdin {\n\t\tf = os.Stdin\n\t} else {\n\t\tf, err = os.Open(filename)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tdefer f.Close()\n\t}\n\n\tsrc, err := ioutil.ReadAll(f)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tfile, err := parser.ParseFile(fset, filename, src, parserMode)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Apply all fixes to file.\n\tnewFile := file\n\tfixed := false\n\tfor _, fix := range fixes {\n\t\tif allowed != nil && !allowed[fix.name] {\n\t\t\tcontinue\n\t\t}\n\t\tif fix.f(newFile) {\n\t\t\tfixed = true\n\t\t\tfmt.Fprintf(&fixlog, \" %s\", fix.name)\n\n\t\t\t// AST changed.\n\t\t\t// Print and parse, to update any missing scoping\n\t\t\t// or position information for subsequent fixers.\n\t\t\tnewSrc, err := gofmtFile(newFile)\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tnewFile, err = parser.ParseFile(fset, filename, newSrc, parserMode)\n\t\t\tif err != nil {\n\t\t\t\tif debug {\n\t\t\t\t\tfmt.Printf(\"%s\", newSrc)\n\t\t\t\t\treport(err)\n\t\t\t\t\tos.Exit(exitCode)\n\t\t\t\t}\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\tif !fixed {\n\t\treturn nil\n\t}\n\tfmt.Fprintf(os.Stderr, \"%s: fixed %s\\n\", filename, fixlog.String()[1:])\n\n\t// Print AST.  We did that after each fix, so this appears\n\t// redundant, but it is necessary to generate gofmt-compatible\n\t// source code in a few cases.  The official gofmt style is the\n\t// output of the printer run on a standard AST generated by the parser,\n\t// but the source we generated inside the loop above is the\n\t// output of the printer run on a mangled AST generated by a fixer.\n\tnewSrc, err := gofmtFile(newFile)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tif *doDiff {\n\t\tdata, err := diff(src, newSrc)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"computing diff: %s\", err)\n\t\t}\n\t\tfmt.Printf(\"diff %s fixed/%s\\n\", filename, filename)\n\t\tos.Stdout.Write(data)\n\t\treturn nil\n\t}\n\n\tif useStdin {\n\t\tos.Stdout.Write(newSrc)\n\t\treturn nil\n\t}\n\n\treturn ioutil.WriteFile(f.Name(), newSrc, 0)\n}\n\nvar gofmtBuf bytes.Buffer\n\nfunc gofmt(n interface{}) string {\n\tgofmtBuf.Reset()\n\terr := printConfig.Fprint(&gofmtBuf, fset, n)\n\tif err != nil {\n\t\treturn \"<\" + err.Error() + \">\"\n\t}\n\treturn gofmtBuf.String()\n}\n\nfunc report(err error) {\n\tscanner.PrintError(os.Stderr, err)\n\texitCode = 2\n}\n\nfunc walkDir(path string) {\n\tfilepath.Walk(path, visitFile)\n}\n\nfunc visitFile(path string, f os.FileInfo, err error) error {\n\tif err == nil && isGoFile(f) {\n\t\terr = processFile(path, false)\n\t}\n\tif err != nil {\n\t\treport(err)\n\t}\n\treturn nil\n}\n\nfunc isGoFile(f os.FileInfo) bool {\n\t// ignore non-Go files\n\tname := f.Name()\n\treturn !f.IsDir() && !strings.HasPrefix(name, \".\") && strings.HasSuffix(name, \".go\")\n}\n\nfunc diff(b1, b2 []byte) (data []byte, err error) {\n\tf1, err := ioutil.TempFile(\"\", \"go-fix\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer os.Remove(f1.Name())\n\tdefer f1.Close()\n\n\tf2, err := ioutil.TempFile(\"\", \"go-fix\")\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer os.Remove(f2.Name())\n\tdefer f2.Close()\n\n\tf1.Write(b1)\n\tf2.Write(b2)\n\n\tdata, err = exec.Command(\"diff\", \"-u\", f1.Name(), f2.Name()).CombinedOutput()\n\tif len(data) > 0 {\n\t\t// diff exits with a non-zero status when the files don't match.\n\t\t// Ignore that failure as long as we get output.\n\t\terr = nil\n\t}\n\treturn\n}\n"
  },
  {
    "path": "gozmqfix/main_test.go",
    "content": "// Copyright 2011 The Go Authors.  All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage main\n\nimport (\n\t\"go/ast\"\n\t\"go/parser\"\n\t\"strings\"\n\t\"testing\"\n)\n\ntype testCase struct {\n\tName string\n\tFn   func(*ast.File) bool\n\tIn   string\n\tOut  string\n}\n\nvar testCases []testCase\n\nfunc addTestCases(t []testCase, fn func(*ast.File) bool) {\n\t// Fill in fn to avoid repetition in definitions.\n\tif fn != nil {\n\t\tfor i := range t {\n\t\t\tif t[i].Fn == nil {\n\t\t\t\tt[i].Fn = fn\n\t\t\t}\n\t\t}\n\t}\n\ttestCases = append(testCases, t...)\n}\n\nfunc fnop(*ast.File) bool { return false }\n\nfunc parseFixPrint(t *testing.T, fn func(*ast.File) bool, desc, in string, mustBeGofmt bool) (out string, fixed, ok bool) {\n\tfile, err := parser.ParseFile(fset, desc, in, parserMode)\n\tif err != nil {\n\t\tt.Errorf(\"%s: parsing: %v\", desc, err)\n\t\treturn\n\t}\n\n\toutb, err := gofmtFile(file)\n\tif err != nil {\n\t\tt.Errorf(\"%s: printing: %v\", desc, err)\n\t\treturn\n\t}\n\tif s := string(outb); in != s && mustBeGofmt {\n\t\tt.Errorf(\"%s: not gofmt-formatted.\\n--- %s\\n%s\\n--- %s | gofmt\\n%s\",\n\t\t\tdesc, desc, in, desc, s)\n\t\ttdiff(t, in, s)\n\t\treturn\n\t}\n\n\tif fn == nil {\n\t\tfor _, fix := range fixes {\n\t\t\tif fix.f(file) {\n\t\t\t\tfixed = true\n\t\t\t}\n\t\t}\n\t} else {\n\t\tfixed = fn(file)\n\t}\n\n\toutb, err = gofmtFile(file)\n\tif err != nil {\n\t\tt.Errorf(\"%s: printing: %v\", desc, err)\n\t\treturn\n\t}\n\n\treturn string(outb), fixed, true\n}\n\nfunc TestRewrite(t *testing.T) {\n\tfor _, tt := range testCases {\n\t\t// Apply fix: should get tt.Out.\n\t\tout, fixed, ok := parseFixPrint(t, tt.Fn, tt.Name, tt.In, true)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\t// reformat to get printing right\n\t\tout, _, ok = parseFixPrint(t, fnop, tt.Name, out, false)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tif out != tt.Out {\n\t\t\tt.Errorf(\"%s: incorrect output.\\n\", tt.Name)\n\t\t\tif !strings.HasPrefix(tt.Name, \"testdata/\") {\n\t\t\t\tt.Errorf(\"--- have\\n%s\\n--- want\\n%s\", out, tt.Out)\n\t\t\t}\n\t\t\ttdiff(t, out, tt.Out)\n\t\t\tcontinue\n\t\t}\n\n\t\tif changed := out != tt.In; changed != fixed {\n\t\t\tt.Errorf(\"%s: changed=%v != fixed=%v\", tt.Name, changed, fixed)\n\t\t\tcontinue\n\t\t}\n\n\t\t// Should not change if run again.\n\t\tout2, fixed2, ok := parseFixPrint(t, tt.Fn, tt.Name+\" output\", out, true)\n\t\tif !ok {\n\t\t\tcontinue\n\t\t}\n\n\t\tif fixed2 {\n\t\t\tt.Errorf(\"%s: applied fixes during second round\", tt.Name)\n\t\t\tcontinue\n\t\t}\n\n\t\tif out2 != out {\n\t\t\tt.Errorf(\"%s: changed output after second round of fixes.\\n--- output after first round\\n%s\\n--- output after second round\\n%s\",\n\t\t\t\ttt.Name, out, out2)\n\t\t\ttdiff(t, out, out2)\n\t\t}\n\t}\n}\n\nfunc tdiff(t *testing.T, a, b string) {\n\tdata, err := diff([]byte(a), []byte(b))\n\tif err != nil {\n\t\tt.Error(err)\n\t\treturn\n\t}\n\tt.Error(string(data))\n}\n"
  },
  {
    "path": "gozmqfix/zmqstruct.go",
    "content": "// Copyright 2013 Joshua Tacoma.  All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage main\n\nimport (\n\t\"go/ast\"\n)\n\nfunc init() {\n\tregister(zmqstructFix)\n}\n\nvar zmqstructFix = fix{\n\t\"zmqstruct\",\n\t\"2013-03-20\",\n\tzmqstruct,\n\t`\n\tMake github.com/alecthomas/gozmq use structs instead of interfaces.\n`,\n}\n\nfunc zmqstruct(f *ast.File) bool {\n\tspec := importSpec(f, \"github.com/alecthomas/gozmq\")\n\tif spec == nil {\n\t\treturn false\n\t}\n\tzmq := \"gozmq\"\n\tif spec.Name != nil {\n\t\tzmq = spec.Name.Name\n\t}\n\n\tfixed := false\n\twalk(f, func(n interface{}) {\n\t\tswitch node := n.(type) {\n\t\tcase *ast.ArrayType:\n\t\t\tt := zmqstructtype(zmq, node.Elt)\n\t\t\tif t != nil {\n\t\t\t\tnode.Elt = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.CompositeLit:\n\t\t\t// This is irrelevant only because the original type is an\n\t\t\t// interface i.e. cannot be the type of a composite literal.\n\t\tcase *ast.Ellipsis:\n\t\t\tt := zmqstructtype(zmq, node.Elt)\n\t\t\tif t != nil {\n\t\t\t\tnode.Elt = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.Field:\n\t\t\tt := zmqstructtype(zmq, node.Type)\n\t\t\tif t != nil {\n\t\t\t\tnode.Type = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.MapType:\n\t\t\tt := zmqstructtype(zmq, node.Key)\n\t\t\tif t != nil {\n\t\t\t\tnode.Key = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\t\tt = zmqstructtype(zmq, node.Value)\n\t\t\tif t != nil {\n\t\t\t\tnode.Value = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.Object:\n\t\t\t// Does something need to be done here with node.Type?\n\t\t\t// What does it take to trigger this case?\n\t\tcase *ast.TypeAssertExpr:\n\t\t\tt := zmqstructtype(zmq, node.Type)\n\t\t\tif t != nil {\n\t\t\t\tnode.Type = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.TypeSpec:\n\t\t\tt := zmqstructtype(zmq, node.Type)\n\t\t\tif t != nil {\n\t\t\t\tnode.Type = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\tcase *ast.ValueSpec:\n\t\t\tt := zmqstructtype(zmq, node.Type)\n\t\t\tif t != nil {\n\t\t\t\tnode.Type = t\n\t\t\t\tfixed = true\n\t\t\t}\n\t\t}\n\t})\n\treturn fixed\n}\n\nfunc zmqstructtype(zmq string, n ast.Expr) ast.Expr {\n\ts, ok := n.(*ast.SelectorExpr)\n\tif ok {\n\t\tp, ok := s.X.(*ast.Ident)\n\t\tif ok && p.Name == zmq {\n\t\t\tif s.Sel.Name == \"Context\" || s.Sel.Name == \"Socket\" {\n\t\t\t\treturn &ast.StarExpr{\n\t\t\t\t\tX: &ast.SelectorExpr{\n\t\t\t\t\t\tX:   ast.NewIdent(zmq),\n\t\t\t\t\t\tSel: ast.NewIdent(s.Sel.Name),\n\t\t\t\t\t},\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n"
  },
  {
    "path": "gozmqfix/zmqstruct_test.go",
    "content": "// Copyright 2013 Joshua Tacoma.  All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\npackage main\n\nfunc init() {\n\taddTestCases(zmqstructTests, zmqstruct)\n}\n\nvar zmqstructTests = []testCase{\n\t{\n\t\tName: \"zmqstruct.0\",\n\t\tIn: `package main\n\nimport zmq \"github.com/alecthomas/gozmq\"\n\ntype M struct {\n\tc  zmq.Context\n\ts  zmq.Socket\n\tss []zmq.Socket\n\tm  map[zmq.Context]zmq.Socket\n}\n\ntype S0 zmq.Socket\n\nfunc newM(c zmq.Context, s zmq.Socket, ss ...zmq.Socket) *M {\n\tif s == nil {\n\t\ts = c.NewSocket(zmq.PUB)\n\t}\n\treturn &M{\n\t\tc:  c,\n\t\ts:  s,\n\t\tss: ss,\n\t}\n}\n\nvar GlobalM = newM(c.NewContext(), nil.(zmq.Socket))\n\ntype Socket zmq.Socket\n\nvar S Socket = Socket(M.s)\n`,\n\t\tOut: `package main\n\nimport zmq \"github.com/alecthomas/gozmq\"\n\ntype M struct {\n\tc  *zmq.Context\n\ts  *zmq.Socket\n\tss []*zmq.Socket\n\tm  map[*zmq.Context]*zmq.Socket\n}\n\ntype S0 *zmq.Socket\n\nfunc newM(c *zmq.Context, s *zmq.Socket, ss ...*zmq.Socket) *M {\n\tif s == nil {\n\t\ts = c.NewSocket(zmq.PUB)\n\t}\n\treturn &M{\n\t\tc:  c,\n\t\ts:  s,\n\t\tss: ss,\n\t}\n}\n\nvar GlobalM = newM(c.NewContext(), nil.(*zmq.Socket))\n\ntype Socket *zmq.Socket\n\nvar S Socket = Socket(M.s)\n`,\n\t},\n\t{\n\t\tName: \"zmqstruct.1\",\n\t\tIn: `package main\n\nimport \"github.com/alecthomas/gozmq\"\n\ntype Socket *gozmq.Socket\n`,\n\t\tOut: `package main\n\nimport \"github.com/alecthomas/gozmq\"\n\ntype Socket *gozmq.Socket\n`,\n\t},\n}\n"
  },
  {
    "path": "gozmqgen/README.md",
    "content": "# gozmqgen\n\nIntended use is:\n\n    cd gozmq\n    go run ./gozmqgen/main.go\n\nIn case the template isn't quite right, you should also:\n\n    go fmt *.go\n\n"
  },
  {
    "path": "gozmqgen/header.txt",
    "content": ""
  },
  {
    "path": "gozmqgen/main.go",
    "content": "package main\n\nimport (\n\t\"encoding/xml\"\n\t\"flag\"\n\t\"fmt\"\n\t\"io\"\n\t\"io/ioutil\"\n\t\"net/http\"\n\t\"os\"\n\t\"path\"\n\t\"strings\"\n\t\"text/template\"\n)\n\ntype Args struct {\n\tzversion      string\n\tpages         string\n\tcomment_width uint\n\ttemplsource   string\n\theadersource  string\n}\n\nvar args = Args{\n\tzversion:      \"2.1,2.2,3.2,4.0\",\n\tpages:         \"getsockopt,setsockopt\",\n\tcomment_width: 72,\n\ttemplsource:   \"./gozmqgen/template.txt\",\n\theadersource:  \"./gozmqgen/header.txt\",\n}\n\nfunc main() {\n\tflag.StringVar(&args.zversion, \"zversion\", args.zversion, \"version of zmq\")\n\tflag.StringVar(&args.pages, \"pages\", args.pages, \"comma-delimited man page names\")\n\tflag.UintVar(&args.comment_width, \"comment-width\", args.comment_width, \"maximum width of comment text\")\n\tflag.StringVar(&args.templsource, \"template\", args.templsource, \"Name of template file or - to read STDIN.\")\n\tflag.StringVar(&args.headersource, \"header\", args.headersource, \"Name of header file.\")\n\tflag.Parse()\n\n\tif len(args.templsource) == 0 {\n\t\tpanic(\"'template' is required.\")\n\t}\n\n\tdata := map[string]interface{}{\n\t\t\"copyright\": string(mustRead(args.headersource)),\n\t}\n\tfor _, version := range strings.Split(args.zversion, \",\") {\n\t\tdata[\"build\"] = buildtags[version]\n\t\tdata[\"version\"] = version\n\t\tfor _, page := range strings.Split(args.pages, \",\") {\n\t\t\tmanual, err := LoadManual(version, \"zmq_\"+page)\n\t\t\tif err != nil {\n\t\t\t\tpanic(err.Error())\n\t\t\t}\n\t\t\tdefer manual.Close()\n\t\t\tcite := \"http://api.zeromq.org/\" + version + \":zmq-\" + page\n\t\t\tvar options []map[string]interface{}\n\t\t\toptlist, err := ParseOptions(version, manual)\n\t\t\tif err != nil {\n\t\t\t\tpanic(err.Error())\n\t\t\t}\n\t\t\tfor _, o := range optlist {\n\t\t\t\to.SetCitation(cite + \"#\" + o.anchor)\n\t\t\t\tif !ignore[\"\"][o.shortname] && !ignore[version][o.shortname] {\n\t\t\t\t\toptions = append(options, o.Pod())\n\t\t\t\t}\n\t\t\t}\n\t\t\tdata[page] = map[string]interface{}{\n\t\t\t\t\"cite\":    cite,\n\t\t\t\t\"options\": options,\n\t\t\t}\n\t\t}\n\t\traw_template := mustRead(args.templsource)\n\t\tt, err := template.New(\"main\").Parse(string(raw_template))\n\t\tif err != nil {\n\t\t\tpanic(err.Error())\n\t\t}\n\t\tout, err := os.Create(\"zmqgen_\" + strings.Replace(version, \".\", \"_\", -1) + \".go\")\n\t\tif err != nil {\n\t\t\tpanic(err.Error())\n\t\t} else if err = t.Execute(out, data); err != nil {\n\t\t\tpanic(err.Error())\n\t\t}\n\t}\n}\n\nvar (\n\tgotypes = map[string]map[string]string{\n\t\t\"binary data\": map[string]string{\n\t\t\t\"\": \"string\",\n\t\t},\n\t\t\"binary data or Z85 text string\": map[string]string{\n\t\t\t\"\": \"string\",\n\t\t},\n\t\t\"character string\": map[string]string{\n\t\t\t\"\": \"string\",\n\t\t},\n\t\t\"int\": map[string]string{\n\t\t\t\"\":             \"int\",\n\t\t\t\"boolean\":      \"bool\",\n\t\t\t\"milliseconds\": \"time.Duration\",\n\t\t},\n\t\t\"int on POSIX systems, SOCKET on Windows\": map[string]string{\n\t\t\t\"\": \"int\",\n\t\t},\n\t\t\"int64_t\": map[string]string{\n\t\t\t\"\":             \"int64\",\n\t\t\t\"boolean\":      \"bool\",\n\t\t\t\"milliseconds\": \"time.Duration\",\n\t\t},\n\t\t\"NULL-terminated character string\": map[string]string{\n\t\t\t\"\": \"string\",\n\t\t},\n\t\t\"uint32_t\": map[string]string{\n\t\t\t\"\": \"uint32\",\n\t\t},\n\t\t\"uint64_t\": map[string]string{\n\t\t\t\"\":        \"uint64\",\n\t\t\t\"boolean\": \"bool\",\n\t\t},\n\t}\n\n\tztypes = map[string]map[string]string{\n\t\t\"binary data\":                    map[string]string{\"\": \"String\"},\n\t\t\"binary data or Z85 text string\": map[string]string{\"\": \"String\"},\n\t\t\"character string\":               map[string]string{\"\": \"String\"},\n\t\t\"int\":                            map[string]string{\"\": \"Int\"},\n\t\t\"int on POSIX systems, SOCKET on Windows\": map[string]string{\"\": \"Int\"},\n\t\t\"int64_t\":                          map[string]string{\"\": \"Int64\"},\n\t\t\"NULL-terminated character string\": map[string]string{\"\": \"String\"},\n\t\t\"uint32_t\":                         map[string]string{\"\": \"UInt32\"},\n\t\t\"uint64_t\":                         map[string]string{\"\": \"UInt64\"},\n\t}\n\n\tlowtypes = map[string]string{\n\t\t\"int32_t\":  \"int32\",\n\t\t\"int64_t\":  \"int64\",\n\t\t\"uint32_t\": \"uint32\",\n\t\t\"uint64_t\": \"uint64\",\n\t}\n\n\treplacements = map[string]string{\n\t\t\"buf\":      \"Buf\",\n\t\t\"Hwm\":      \"HWM\",\n\t\t\"hwm\":      \"HWM\",\n\t\t\"Ipv4only\": \"IPv4Only\",\n\t\t\"more\":     \"More\",\n\t\t\"msg\":      \"Msg\",\n\t\t\"pub\":      \"PUB\",\n\t\t\"Router\":   \"ROUTER\",\n\t\t\"size\":     \"Size\",\n\t\t\"Tcp\":      \"TCP\",\n\t\t\"timeo\":    \"Timeout\",\n\t}\n\n\tcachedir = path.Join(\".cache\", \"codegen\")\n\n\t// version : shortname : C type\n\tfixedtypes = map[string]map[string]string{\n\t\t\"\": map[string]string{\n\t\t\t\"EVENTS\":       \"uint64_t\",\n\t\t\t\"FD\":           \"int\",\n\t\t\t\"RATE\":         \"int64_t\",\n\t\t\t\"RCVBUF\":       \"uint64_t\",\n\t\t\t\"RECOVERY_IVL\": \"int64_t\",\n\t\t\t\"SNDBUF\":       \"uint64_t\",\n\t\t\t\"TYPE\":         \"uint64_t\",\n\t\t},\n\t\t\"2.1\": map[string]string{\n\t\t\t\"RCVMORE\": \"uint64_t\",\n\t\t},\n\t\t\"2.2\": map[string]string{\n\t\t\t\"RCVMORE\": \"uint64_t\",\n\t\t},\n\t}\n\n\tfixedgotypes = map[string]string{\n\t\t\"TYPE\": \"SocketType\",\n\t}\n\n\t// shortname : unit\n\tfixedunits = map[string]string{\n\t\t\"DELAY_ATTACH_ON_CONNECT\": \"boolean\",\n\t\t\"ROUTER_MANDATORY\":        \"boolean\",\n\t\t\"XPUB_VERBOSE\":            \"boolean\",\n\t}\n\n\t// version : shortname\n\tignore = map[string]map[string]bool{\n\t\t\"\": map[string]bool{\n\t\t\t\"FD\":             true,\n\t\t\t\"LAST_ENDPOINT\":  true,\n\t\t\t\"MULTICAST_HOPS\": true,\n\t\t},\n\t\t\"2.1\": map[string]bool{\n\t\t\t\"RECOVERY_IVL\": true,\n\t\t},\n\t\t\"2.2\": map[string]bool{\n\t\t\t\"RECOVERY_IVL\": true,\n\t\t},\n\t\t\"3.2\": map[string]bool{},\n\t}\n\n\t// shortname : shortname\n\trename = map[string]string{\n\t\t\"RECOVERY_IVL_MSEC\": \"RECOVERY_IVL\",\n\t}\n\n\tbuildtags = map[string]string{\n\t\t\"2.1\": \"zmq_2_1\",\n\t\t\"2.2\": \"!zmq_2_1,!zmq_3_x,!zmq_4_x\",\n\t\t\"3.2\": \"zmq_3_x\",\n\t\t\"4.0\": \"zmq_4_x\",\n\t}\n)\n\nfunc fix(s string) string {\n\tfor key, value := range replacements {\n\t\ts = strings.Replace(s, key, value, -1)\n\t}\n\treturn s\n}\n\nfunc LoadManual(version string, funcname string) (io.ReadCloser, error) {\n\tpagename := version + \":\" + funcname\n\tpagename = strings.Replace(pagename, \".\", \"-\", -1)\n\tpagename = strings.Replace(pagename, \"_\", \"-\", -1)\n\tcachepath := path.Join(cachedir, pagename)\n\tcachefile, err := os.Open(cachepath)\n\tif err == nil {\n\t\treturn cachefile, nil\n\t}\n\tos.MkdirAll(cachedir, 0755)\n\turl := \"http://api.zeromq.org/\" + pagename\n\tresp, err := http.Get(url)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != 200 {\n\t\treturn nil, fmt.Errorf(\"%s -> %s\", url, resp.Status)\n\t}\n\tif cachefile, err = os.Create(cachepath); err != nil {\n\t\treturn nil, err\n\t}\n\tif _, err := io.Copy(cachefile, resp.Body); err != nil {\n\t\treturn nil, err\n\t}\n\treturn os.Open(cachepath)\n}\n\ntype Option struct {\n\ttyp       string   // type as listed in source documentation\n\tunit      string   // unit as listed source documentation\n\tfullname  string   // e.g. \"ZMQ_RCVMORE\"\n\tshortname string   // e.g. \"RCVMORE\"\n\tdesc      []string // one or more paragraphs\n\tcite      string   // URL to source documentation\n\tctype     string   // C type e.g. \"uint64_t\"\n\tgotype    string   // Go type e.g. \"SocketType\"\n\tztype     string   // option method suffix e.g. \"Int64\"\n\tlowtype   string   // go equivalent of C type e.g. \"uint64\"\n\tanchor    string   // id in source documentation\n\tduration  bool     // true if gotype==\"time.Duration\"\n\tgounit    string   // e.g. \"time.Millisecond\"\n\tcast      bool     // true if gotype needs casting\n}\n\nfunc NewOption(fullname string) *Option {\n\treturn &Option{\n\t\tfullname:  fullname,\n\t\tshortname: fullname[4:],\n\t}\n}\n\nfunc (o *Option) Name() (name string) {\n\tshortname, ok := rename[o.shortname]\n\tif !ok {\n\t\tshortname = o.shortname\n\t}\n\tfor _, part := range strings.Split(shortname, \"_\") {\n\t\tname = name + string(part[0]) + strings.ToLower(part[1:])\n\t}\n\treturn fix(name)\n}\n\nfunc (o *Option) AppendDescription(line string) {\n\tline = strings.TrimSpace(line)\n\tif len(line) > 0 {\n\t\to.desc = append(o.desc, line)\n\t}\n}\n\nfunc (o *Option) SetCitation(cite string) {\n\to.cite = cite\n}\n\nfunc (o *Option) Comment() (comment string) {\n\tdesc := o.desc[1:]\n\tif len(o.cite) > 0 {\n\t\tdesc = append([]string{o.cite, \"\"}, desc...)\n\t}\n\tfor _, line := range desc {\n\t\tif len(line) > 0 && line[0] == ' ' {\n\t\t\tcomment = comment + strings.TrimRight(line, \"\\n\") + \"\\n\"\n\t\t} else {\n\t\t\t// TODO: wrap line to width chars\n\t\t\t//wrapped = textwrap.wrap(line, width)\n\t\t\t//\"\\n\".join(wrapped) + \"\\n%s\\n\" % wrapped\n\t\t\tcomment = comment + line\n\t\t}\n\t}\n\treturn\n}\n\nfunc (o *Option) Summary() string {\n\treturn o.fullname + \": \" + o.desc[0] + \".\"\n}\n\nfunc (o *Option) Pod() map[string]interface{} {\n\treturn map[string]interface{}{\n\t\t\"fullname\":    o.fullname,\n\t\t\"shortname\":   o.shortname,\n\t\t\"nicename\":    o.Name(),\n\t\t\"summary\":     o.Summary(),\n\t\t\"description\": strings.Split(o.Comment(), \"\\n\"),\n\t\t\"ctype\":       o.typ,\n\t\t\"gotype\":      o.gotype,\n\t\t\"ztype\":       o.ztype,\n\t\t\"lowtype\":     o.lowtype,\n\t\t\"anchor\":      o.anchor,\n\t\t\"duration\":    o.duration,\n\t\t\"citation\":    o.cite,\n\t\t\"boolean\":     o.gotype == \"bool\",\n\t\t\"gounit\":      o.gounit,\n\t\t\"cast\":        o.cast,\n\t}\n}\n\nfunc (o *Option) String() string { return o.Name() }\n\ntype OptionsBuilder struct {\n\toptions []*Option\n\tversion string\n}\n\nfunc (b *OptionsBuilder) Add(name string, info string) bool {\n\tif !strings.HasPrefix(name, \"ZMQ_\") {\n\t\treturn false\n\t}\n\toption := NewOption(name)\n\tb.options = append(b.options, option)\n\toption.AppendDescription(info)\n\treturn true\n}\n\nfunc (b *OptionsBuilder) Describe(info string) {\n\tif len(b.options) > 0 {\n\t\tb.options[len(b.options)-1].AppendDescription(info)\n\t}\n}\n\nfunc (b *OptionsBuilder) SetAnchor(anchor string) {\n\tif len(b.options) > 0 {\n\t\tb.options[len(b.options)-1].anchor = anchor\n\t}\n}\n\nfunc (b *OptionsBuilder) SetProperty(name string, value string) {\n\tif len(b.options) > 0 {\n\t\toption := b.options[len(b.options)-1]\n\t\tname = strings.TrimSpace(name)\n\t\tswitch name {\n\t\tcase \"Option value type\":\n\t\t\toption.typ = value\n\t\t\tbreak\n\t\tcase \"Option value unit\":\n\t\t\toption.unit = value\n\t\t\tbreak\n\t\tcase \"Option value size\":\n\t\t\toption.unit = \"Z85\"\n\t\t\tbreak\n\t\t}\n\t\tif len(option.typ) > 0 && len(option.unit) > 0 {\n\t\t\tif val, ok := fixedtypes[\"\"][option.shortname]; ok {\n\t\t\t\toption.typ = val\n\t\t\t} else if val, ok := fixedtypes[b.version][option.shortname]; ok {\n\t\t\t\toption.typ = val\n\t\t\t}\n\t\t\tif val, ok := lowtypes[option.typ]; ok {\n\t\t\t\toption.lowtype = val\n\t\t\t} else {\n\t\t\t\toption.lowtype = option.typ\n\t\t\t}\n\t\t\tif val, ok := fixedunits[option.shortname]; ok {\n\t\t\t\toption.unit = val\n\t\t\t}\n\t\t\tgomap := gotypes[option.typ]\n\t\t\tif val, ok := gomap[option.unit]; ok {\n\t\t\t\toption.gotype = val\n\t\t\t} else {\n\t\t\t\toption.gotype = gomap[\"\"]\n\t\t\t}\n\t\t\tif val, ok := fixedgotypes[option.shortname]; ok {\n\t\t\t\toption.gotype = val\n\t\t\t\toption.cast = true\n\t\t\t}\n\t\t\tzmap := ztypes[option.typ]\n\t\t\tif val, ok := zmap[option.unit]; ok {\n\t\t\t\toption.ztype = val\n\t\t\t} else {\n\t\t\t\toption.ztype = zmap[\"\"]\n\t\t\t}\n\t\t\tif option.gotype == \"time.Duration\" {\n\t\t\t\toption.duration = true\n\t\t\t\tswitch option.unit {\n\t\t\t\tcase \"milliseconds\":\n\t\t\t\t\toption.gounit = \"time.Millisecond\"\n\t\t\t\tcase \"seconds\":\n\t\t\t\t\toption.gounit = \"time.Second\"\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\toption.AppendDescription(fmt.Sprintf(\" %-25s %s\\n\", name, value))\n\t}\n}\n\nfunc ParseOptions(version string, r io.Reader) ([]*Option, error) {\n\td := xml.NewDecoder(r)\n\td.Strict = false\n\td.AutoClose = xml.HTMLAutoClose\n\td.Entity = xml.HTMLEntity\n\tb := &OptionsBuilder{version: version}\n\tvar state, text, text2 string\n\tfor {\n\t\tt, err := d.Token()\n\t\tif err == io.EOF {\n\t\t\tbreak\n\t\t} else if err != nil {\n\t\t\treturn nil, err\n\t\t} else {\n\t\t\tswitch token := t.(type) {\n\t\t\tcase xml.StartElement:\n\t\t\t\tswitch token.Name.Local {\n\t\t\t\tcase \"h3\":\n\t\t\t\t\tstate = \"title\"\n\t\t\t\t\ttext = \"\"\n\t\t\t\t\ttext2 = \"unknown\"\n\t\t\t\t\tfor _, attr := range token.Attr {\n\t\t\t\t\t\tswitch attr.Name.Local {\n\t\t\t\t\t\tcase \"id\":\n\t\t\t\t\t\t\ttext2 = attr.Value\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tcase \"table\":\n\t\t\t\t\tswitch state {\n\t\t\t\t\tcase \"describing\":\n\t\t\t\t\t\tfor _, attr := range token.Attr {\n\t\t\t\t\t\t\tswitch attr.Name.Local {\n\t\t\t\t\t\t\tcase \"class\":\n\t\t\t\t\t\t\t\tif attr.Value == \"wiki-content-table\" {\n\t\t\t\t\t\t\t\t\tb.Describe(text)\n\t\t\t\t\t\t\t\t\ttext = \"\"\n\t\t\t\t\t\t\t\t\tstate = \"properties\"\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\tcase \"td\":\n\t\t\t\t\tswitch state {\n\t\t\t\t\tcase \"properties\":\n\t\t\t\t\t\tstate = \"property-name\"\n\t\t\t\t\tcase \"property-name\":\n\t\t\t\t\t\tstate = \"property-value\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase xml.EndElement:\n\t\t\t\tswitch state {\n\t\t\t\tcase \"title\":\n\t\t\t\t\tswitch token.Name.Local {\n\t\t\t\t\tcase \"h3\":\n\t\t\t\t\t\tparts := strings.SplitN(text, \": \", 2)\n\t\t\t\t\t\tif b.Add(parts[0], parts[1]) {\n\t\t\t\t\t\t\tstate = \"describing\"\n\t\t\t\t\t\t\tb.SetAnchor(text2)\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tstate = \"\"\n\t\t\t\t\t\t}\n\t\t\t\t\t\ttext = \"\"\n\t\t\t\t\t\ttext2 = \"\"\n\t\t\t\t\t}\n\t\t\t\tcase \"describing\":\n\t\t\t\t\tswitch token.Name.Local {\n\t\t\t\t\tcase \"p\", \"li\":\n\t\t\t\t\t\tb.Describe(text)\n\t\t\t\t\t\ttext = \"\"\n\t\t\t\t\t}\n\t\t\t\tcase \"properties\":\n\t\t\t\t\tswitch token.Name.Local {\n\t\t\t\t\tcase \"table\":\n\t\t\t\t\t\tstate = \"\"\n\t\t\t\t\t}\n\t\t\t\tcase \"property-value\":\n\t\t\t\t\tswitch token.Name.Local {\n\t\t\t\t\tcase \"td\":\n\t\t\t\t\t\tb.SetProperty(text, text2)\n\t\t\t\t\t\tstate = \"properties\"\n\t\t\t\t\t\ttext = \"\"\n\t\t\t\t\t\ttext2 = \"\"\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\tcase xml.CharData:\n\t\t\t\tswitch state {\n\t\t\t\tcase \"title\":\n\t\t\t\t\ttext += string(token)\n\t\t\t\tcase \"describing\":\n\t\t\t\t\ttext += string(token)\n\t\t\t\tcase \"property-name\":\n\t\t\t\t\ttext += string(token)\n\t\t\t\tcase \"property-value\":\n\t\t\t\t\ttext2 += string(token)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\treturn b.options, nil\n}\n\nfunc mustRead(name string) []byte {\n\tvar raw []byte\n\tvar err error\n\tif name == \"-\" {\n\t\traw, err = ioutil.ReadAll(os.Stdin)\n\t} else {\n\t\traw, err = ioutil.ReadFile(name)\n\t}\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\treturn raw\n}\n"
  },
  {
    "path": "gozmqgen/main_test.go",
    "content": "package main\n\nimport (\n\t\"testing\"\n)\n\n// This test depends on a remote HTTP service that may not even be available.\nfunc TestLoadManual(t *testing.T) {\n\tif m, err := LoadManual(\"3.2\", \"zmq-setsockopt\"); err != nil {\n\t\tt.Errorf(err.Error())\n\t} else if m == nil {\n\t\tt.Errorf(\"no error yet nil reader.\")\n\t}\n}\n"
  },
  {
    "path": "gozmqgen/template.txt",
    "content": "// +build {{.build}}\n//\n{{if .copyright}}{{.copyright}}\n{{end}}\npackage gozmq\n\nimport (\n\t\"time\"\n)\n\n// This file was {{/*NOT */}}generated automatically.  Changes made here will {{/*NOT */}}be lost.\n\n// Socket Option Getters{{with .getsockopt}}{{range .options}}\n\n// {{.summary}}\n//\n// See: {{.citation}}\n//\nfunc (s *Socket) {{.nicename}}() ({{.gotype}}, error) {\n\t{{if .duration}}ms, err := s.GetSockOpt{{.ztype}}({{.shortname}})\n\treturn time.Duration(ms) * {{.gounit}}, err{{else}}{{if .boolean}}value, err := s.GetSockOpt{{.ztype}}({{.shortname}})\n\treturn value != 0, err{{else}}{{if .cast}}value, err := s.GetSockOpt{{.ztype}}({{.shortname}})\n\treturn {{.gotype}}(value), err{{else}}return s.GetSockOpt{{.ztype}}({{.shortname}}){{end}}{{end}}{{end}}\n}{{end}}{{end}}\n\n// Socket Option Setters{{with .setsockopt}}{{range .options}}\n\n// {{.summary}}\n//\n// See: {{.citation}}\n//\nfunc (s *Socket) Set{{.nicename}}(value {{.gotype}}) error {\n\t{{if .duration}}return s.SetSockOpt{{.ztype}}({{.shortname}}, {{.lowtype}}(value/{{.gounit}})){{else}}{{if .boolean}}if value {\n\t\treturn s.SetSockOpt{{.ztype}}({{.shortname}}, 1)\n\t}\n\treturn s.SetSockOpt{{.ztype}}({{.shortname}}, 0){{else}}return s.SetSockOpt{{.ztype}}({{.shortname}}, {{if .cast}}{{.lowtype}}({{end}}value{{if .cast}}){{end}}){{end}}{{end}}\n}{{end}}{{end}}\n"
  },
  {
    "path": "zmq.go",
    "content": "/*\n  Copyright 2010-2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\n// Go (golang) Bindings for 0mq (zmq, zeromq)\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n#include <stdlib.h>\n#include <string.h>\n*/\nimport \"C\"\n\nimport (\n\t\"errors\"\n\t\"sync\"\n\t\"syscall\"\n\t\"time\"\n\t\"unsafe\"\n)\n\ntype SocketType int\n\ntype IntSocketOption int\ntype Int64SocketOption int\ntype UInt64SocketOption int\ntype StringSocketOption int\ntype BoolSocketOption int\n\ntype MessageOption int\ntype SendRecvOption int\n\nconst (\n\t// NewSocket types\n\tPAIR   = SocketType(C.ZMQ_PAIR)\n\tPUB    = SocketType(C.ZMQ_PUB)\n\tSUB    = SocketType(C.ZMQ_SUB)\n\tREQ    = SocketType(C.ZMQ_REQ)\n\tREP    = SocketType(C.ZMQ_REP)\n\tDEALER = SocketType(C.ZMQ_DEALER)\n\tROUTER = SocketType(C.ZMQ_ROUTER)\n\tPULL   = SocketType(C.ZMQ_PULL)\n\tPUSH   = SocketType(C.ZMQ_PUSH)\n\tXPUB   = SocketType(C.ZMQ_XPUB)\n\tXSUB   = SocketType(C.ZMQ_XSUB)\n\n\t// Deprecated aliases\n\tXREQ       = DEALER\n\tXREP       = ROUTER\n\tUPSTREAM   = PULL\n\tDOWNSTREAM = PUSH\n\n\t// NewSocket options\n\tAFFINITY          = UInt64SocketOption(C.ZMQ_AFFINITY)\n\tIDENTITY          = StringSocketOption(C.ZMQ_IDENTITY)\n\tSUBSCRIBE         = StringSocketOption(C.ZMQ_SUBSCRIBE)\n\tUNSUBSCRIBE       = StringSocketOption(C.ZMQ_UNSUBSCRIBE)\n\tRATE              = Int64SocketOption(C.ZMQ_RATE)\n\tRECOVERY_IVL      = Int64SocketOption(C.ZMQ_RECOVERY_IVL)\n\tSNDBUF            = UInt64SocketOption(C.ZMQ_SNDBUF)\n\tRCVBUF            = UInt64SocketOption(C.ZMQ_RCVBUF)\n\tFD                = Int64SocketOption(C.ZMQ_FD)\n\tEVENTS            = UInt64SocketOption(C.ZMQ_EVENTS)\n\tTYPE              = UInt64SocketOption(C.ZMQ_TYPE)\n\tLINGER            = IntSocketOption(C.ZMQ_LINGER)\n\tRECONNECT_IVL     = IntSocketOption(C.ZMQ_RECONNECT_IVL)\n\tRECONNECT_IVL_MAX = IntSocketOption(C.ZMQ_RECONNECT_IVL_MAX)\n\tBACKLOG           = IntSocketOption(C.ZMQ_BACKLOG)\n\n\t// Send/recv options\n\tSNDMORE = SendRecvOption(C.ZMQ_SNDMORE)\n)\n\ntype zmqErrno syscall.Errno\n\nvar (\n\t// Additional ZMQ errors\n\tENOTSOCK       error = zmqErrno(C.ENOTSOCK)\n\tEFSM           error = zmqErrno(C.EFSM)\n\tEINVAL         error = syscall.EINVAL\n\tENOCOMPATPROTO error = zmqErrno(C.ENOCOMPATPROTO)\n\tETERM          error = zmqErrno(C.ETERM)\n\tEMTHREAD       error = zmqErrno(C.EMTHREAD)\n)\n\ntype PollEvents C.short\n\nconst (\n\tPOLLIN  = PollEvents(C.ZMQ_POLLIN)\n\tPOLLOUT = PollEvents(C.ZMQ_POLLOUT)\n\tPOLLERR = PollEvents(C.ZMQ_POLLERR)\n)\n\ntype DeviceType int\n\nconst (\n\tSTREAMER  = DeviceType(C.ZMQ_STREAMER)\n\tFORWARDER = DeviceType(C.ZMQ_FORWARDER)\n\tQUEUE     = DeviceType(C.ZMQ_QUEUE)\n)\n\nvar (\n\tpollunit time.Duration\n)\n\nfunc init() {\n\tif v, _, _ := Version(); v < 3 {\n\t\tpollunit = time.Microsecond\n\t} else {\n\t\tpollunit = time.Millisecond\n\t}\n}\n\n// void zmq_version (int *major, int *minor, int *patch);\nfunc Version() (int, int, int) {\n\tvar major, minor, patch C.int\n\tC.zmq_version(&major, &minor, &patch)\n\treturn int(major), int(minor), int(patch)\n}\n\nfunc (e zmqErrno) Error() string {\n\treturn C.GoString(C.zmq_strerror(C.int(e)))\n}\n\n// If possible, convert a syscall.Errno to a zmqErrno.\nfunc casterr(fromcgo error) error {\n\terrno, ok := fromcgo.(syscall.Errno)\n\tif !ok {\n\t\treturn fromcgo\n\t}\n\tzmqerrno := zmqErrno(errno)\n\tswitch zmqerrno {\n\tcase ENOTSOCK:\n\t\treturn zmqerrno\n\t}\n\tif zmqerrno >= C.ZMQ_HAUSNUMERO {\n\t\treturn zmqerrno\n\t}\n\treturn errno\n}\n\nfunc getErrorForTesting() error {\n\treturn zmqErrno(C.EFSM)\n}\n\n/*\n * A context handles socket creation and asynchronous message delivery.\n * There should generally be one context per application.\n */\ntype Context struct {\n\tc         unsafe.Pointer\n\tmutex     sync.Mutex // ensure init is only called once\n\tinit      func()     // func that calls zmq_init\n\terr       error      // error returned from zmq_init\n\tiothreads int        // hold the iothreads option until zmq_init time\n}\n\n// Create a new context.\nfunc NewContext() (*Context, error) {\n\tc := &Context{iothreads: 1}\n\tc.init = func() {\n\t\tc.mutex.Lock()\n\t\tdefer c.mutex.Unlock()\n\t\tif c.c == nil && c.err == nil {\n\t\t\t// C.NULL is correct but causes a runtime failure on darwin at present\n\t\t\tif ptr, err := C.zmq_init(C.int(c.iothreads)); ptr != nil /*C.NULL*/ {\n\t\t\t\tc.c = ptr\n\t\t\t} else {\n\t\t\t\tc.err = casterr(err)\n\t\t\t}\n\t\t}\n\t}\n\treturn c, nil\n}\n\nfunc (c *Context) Close() {\n\t// C.NULL is correct but causes a runtime failure on darwin at present\n\tif c.c != nil /*C.NULL*/ {\n\t\tC.zmq_term(c.c)\n\t}\n}\n\n// Create a new socket.\n// void *zmq_socket (void *context, int type);\nfunc (c *Context) NewSocket(t SocketType) (*Socket, error) {\n\tif c.init(); c.err != nil {\n\t\treturn nil, c.err\n\t}\n\ts, err := C.zmq_socket(c.c, C.int(t))\n\t// C.NULL is correct but causes a runtime failure on darwin at present\n\tif s != nil /*C.NULL*/ {\n\t\treturn &Socket{c: c, s: s}, nil\n\t}\n\treturn nil, casterr(err)\n}\n\ntype Socket struct {\n\t// XXX Ensure the zmq context doesn't get destroyed underneath us.\n\tc *Context\n\ts unsafe.Pointer\n}\n\n// Shutdown the socket.\n// int zmq_close (void *s);\nfunc (s *Socket) Close() error {\n\tif s.c == nil {\n\t\treturn ENOTSOCK\n\t}\n\tif rc, err := C.zmq_close(s.s); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\ts.c = nil\n\treturn nil\n}\n\n// Set an int option on the socket.\n// int zmq_setsockopt (void *s, int option, const void *optval, size_t optvallen);\nfunc (s *Socket) SetSockOptInt(option IntSocketOption, value int) error {\n\tval := C.int(value)\n\tif rc, err := C.zmq_setsockopt(s.s, C.int(option), unsafe.Pointer(&val), C.size_t(unsafe.Sizeof(val))); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Set an int64 option on the socket.\n// int zmq_setsockopt (void *s, int option, const void *optval, size_t optvallen);\nfunc (s *Socket) SetSockOptInt64(option Int64SocketOption, value int64) error {\n\tif rc, err := C.zmq_setsockopt(s.s, C.int(option), unsafe.Pointer(&value), C.size_t(unsafe.Sizeof(value))); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Set a uint64 option on the socket.\n// int zmq_setsockopt (void *s, int option, const void *optval, size_t optvallen);\nfunc (s *Socket) SetSockOptUInt64(option UInt64SocketOption, value uint64) error {\n\tif rc, err := C.zmq_setsockopt(s.s, C.int(option), unsafe.Pointer(&value), C.size_t(unsafe.Sizeof(value))); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Set a string option on the socket.\n// int zmq_setsockopt (void *s, int option, const void *optval, size_t optvallen);\nfunc (s *Socket) SetSockOptString(option StringSocketOption, value string) error {\n\tv := C.CString(value)\n\tdefer C.free(unsafe.Pointer(v))\n\tif rc, err := C.zmq_setsockopt(s.s, C.int(option), unsafe.Pointer(v), C.size_t(len(value))); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Set a string option on the socket to nil.\n// int zmq_setsockopt (void *s, int option, const void *optval, size_t optvallen);\nfunc (s *Socket) SetSockOptStringNil(option StringSocketOption) error {\n\tif rc, err := C.zmq_setsockopt(s.s, C.int(option), nil, 0); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Get an int option from the socket.\n// int zmq_getsockopt (void *s, int option, void *optval, size_t *optvallen);\nfunc (s *Socket) GetSockOptInt(option IntSocketOption) (value int, err error) {\n\tsize := C.size_t(unsafe.Sizeof(value))\n\tvar rc C.int\n\tif rc, err = C.zmq_getsockopt(s.s, C.int(option), unsafe.Pointer(&value), &size); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\treturn\n}\n\n// Get an int64 option from the socket.\n// int zmq_getsockopt (void *s, int option, void *optval, size_t *optvallen);\nfunc (s *Socket) GetSockOptInt64(option Int64SocketOption) (value int64, err error) {\n\tsize := C.size_t(unsafe.Sizeof(value))\n\tvar rc C.int\n\tif rc, err = C.zmq_getsockopt(s.s, C.int(option), unsafe.Pointer(&value), &size); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\treturn\n}\n\n// Get a uint64 option from the socket.\n// int zmq_getsockopt (void *s, int option, void *optval, size_t *optvallen);\nfunc (s *Socket) GetSockOptUInt64(option UInt64SocketOption) (value uint64, err error) {\n\tsize := C.size_t(unsafe.Sizeof(value))\n\tvar rc C.int\n\tif rc, err = C.zmq_getsockopt(s.s, C.int(option), unsafe.Pointer(&value), &size); rc != 0 {\n\t\tprintln(\"GetSockOptUInt64:\", err.Error())\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\treturn\n}\n\n// Get a string option from the socket.\n// int zmq_getsockopt (void *s, int option, void *optval, size_t *optvallen);\nfunc (s *Socket) GetSockOptString(option StringSocketOption) (value string, err error) {\n\tvar buffer [1024]byte\n\tvar size C.size_t = 1024\n\tvar rc C.int\n\tif rc, err = C.zmq_getsockopt(s.s, C.int(option), unsafe.Pointer(&buffer), &size); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\tvalue = string(buffer[:size])\n\treturn\n}\n\nfunc (s *Socket) GetSockOptBool(option BoolSocketOption) (value bool, err error) {\n\tsize := C.size_t(unsafe.Sizeof(value))\n\tvar rc C.int\n\tif rc, err = C.zmq_getsockopt(s.s, C.int(option), unsafe.Pointer(&value), &size); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\treturn\n}\n\n// Bind the socket to a listening address.\n// int zmq_bind (void *s, const char *addr);\nfunc (s *Socket) Bind(address string) error {\n\ta := C.CString(address)\n\tdefer C.free(unsafe.Pointer(a))\n\tif rc, err := C.zmq_bind(s.s, a); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Connect the socket to an address.\n// int zmq_connect (void *s, const char *addr);\nfunc (s *Socket) Connect(address string) error {\n\tif s.c == nil {\n\t\treturn ENOTSOCK\n\t}\n\ta := C.CString(address)\n\tdefer C.free(unsafe.Pointer(a))\n\tif rc, err := C.zmq_connect(s.s, a); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Send a multipart message.\nfunc (s *Socket) SendMultipart(parts [][]byte, flags SendRecvOption) (err error) {\n\tfor i := 0; i < len(parts)-1; i++ {\n\t\tif err = s.Send(parts[i], SNDMORE|flags); err != nil {\n\t\t\treturn\n\t\t}\n\t}\n\terr = s.Send(parts[(len(parts)-1)], flags)\n\treturn\n}\n\n// Receive a multipart message.\nfunc (s *Socket) RecvMultipart(flags SendRecvOption) (parts [][]byte, err error) {\n\tparts = make([][]byte, 0)\n\tfor {\n\t\tvar data []byte\n\t\tvar more bool\n\n\t\tdata, err = s.Recv(flags)\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tparts = append(parts, data)\n\t\tmore, err = s.getRcvmore()\n\t\tif err != nil {\n\t\t\treturn\n\t\t}\n\t\tif !more {\n\t\t\tbreak\n\t\t}\n\t}\n\treturn\n}\n\n// return the\nfunc (s *Socket) apiSocket() unsafe.Pointer {\n\treturn s.s\n}\n\n// Item to poll for read/write events on, either a *Socket or a file descriptor\ntype PollItem struct {\n\tSocket  *Socket         // socket to poll for events on\n\tFd      ZmqOsSocketType // fd to poll for events on as returned from os.File.Fd()\n\tEvents  PollEvents      // event set to poll for\n\tREvents PollEvents      // events that were present\n}\n\n// a set of items to poll for events on\ntype PollItems []PollItem\n\n// Poll ZmqSockets and file descriptors for I/O readiness. Timeout is in\n// time.Duration. The smallest possible timeout is time.Millisecond for\n// ZeroMQ version 3 and above, and time.Microsecond for earlier versions.\nfunc Poll(items []PollItem, timeout time.Duration) (count int, err error) {\n\tzitems := make([]C.zmq_pollitem_t, len(items))\n\tfor i, pi := range items {\n\t\tzitems[i].socket = pi.Socket.apiSocket()\n\t\tzitems[i].fd = pi.Fd.ToRaw()\n\t\tzitems[i].events = C.short(pi.Events)\n\t}\n\tztimeout := C.long(-1)\n\tif timeout >= 0 {\n\t\tztimeout = C.long(uint64(timeout / pollunit))\n\t}\n\trc, err := C.zmq_poll(&zitems[0], C.int(len(zitems)), ztimeout)\n\tif rc == -1 {\n\t\treturn 0, casterr(err)\n\t}\n\n\tfor i, zi := range zitems {\n\t\titems[i].REvents = PollEvents(zi.revents)\n\t}\n\n\treturn int(rc), nil\n}\n\n// run a zmq_device passing messages between in and out\nfunc Device(t DeviceType, in, out *Socket) error {\n\tif rc, err := C.zmq_device(C.int(t), in.apiSocket(), out.apiSocket()); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn errors.New(\"zmq_device() returned unexpectedly.\")\n}\n\n// XXX For now, this library abstracts zmq_msg_t out of the API.\n// int zmq_msg_init (zmq_msg_t *msg);\n// int zmq_msg_init_size (zmq_msg_t *msg, size_t size);\n// int zmq_msg_close (zmq_msg_t *msg);\n// size_t zmq_msg_size (zmq_msg_t *msg);\n// void *zmq_msg_data (zmq_msg_t *msg);\n// int zmq_msg_copy (zmq_msg_t *dest, zmq_msg_t *src);\n// int zmq_msg_move (zmq_msg_t *dest, zmq_msg_t *src);\n"
  },
  {
    "path": "zmq_2_2.go",
    "content": "// +build !zmq_2_1\n\n/*\n  Copyright 2010-2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n*/\nimport \"C\"\n\nconst (\n\tRCVTIMEO = IntSocketOption(C.ZMQ_RCVTIMEO)\n\tSNDTIMEO = IntSocketOption(C.ZMQ_SNDTIMEO)\n)\n"
  },
  {
    "path": "zmq_2_x.go",
    "content": "// +build !zmq_3_x,!zmq_4_x\n\n/*\n  Copyright 2010-2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n#include <stdlib.h>\n#include <string.h>\n*/\nimport \"C\"\nimport \"unsafe\"\n\nconst (\n\tRCVMORE           = UInt64SocketOption(C.ZMQ_RCVMORE)\n\tRECOVERY_IVL_MSEC = Int64SocketOption(C.ZMQ_RECOVERY_IVL_MSEC)\n\tSWAP              = Int64SocketOption(C.ZMQ_SWAP)\n\tMCAST_LOOP        = Int64SocketOption(C.ZMQ_MCAST_LOOP)\n\tHWM               = UInt64SocketOption(C.ZMQ_HWM)\n\tNOBLOCK           = SendRecvOption(C.ZMQ_NOBLOCK)\n\n\t// Forwards-compatible aliases:\n\tDONTWAIT = NOBLOCK\n)\n\n// Get a context option.\nfunc (c *Context) IOThreads() (int, error) {\n\treturn c.iothreads, nil\n}\n\n// Set a context option.\nfunc (c *Context) SetIOThreads(value int) error {\n\tc.iothreads = value\n\treturn nil\n}\n\n// Send a message to the socket.\n// int zmq_send (void *s, zmq_msg_t *msg, int flags);\nfunc (s *Socket) Send(data []byte, flags SendRecvOption) error {\n\tvar m C.zmq_msg_t\n\t// Copy data array into C-allocated buffer.\n\tsize := C.size_t(len(data))\n\n\tif rc, err := C.zmq_msg_init_size(&m, size); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\n\tif size > 0 {\n\t\t// FIXME Ideally this wouldn't require a copy.\n\t\tC.memcpy(C.zmq_msg_data(&m), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)\n\t}\n\n\tif rc, err := C.zmq_send(s.s, &m, C.int(flags)); rc != 0 {\n\t\t// zmq_send did not take ownership, free message\n\t\tC.zmq_msg_close(&m)\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Receive a message from the socket.\n// int zmq_recv (void *s, zmq_msg_t *msg, int flags);\nfunc (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) {\n\t// Allocate and initialise a new zmq_msg_t\n\tvar m C.zmq_msg_t\n\tvar rc C.int\n\tif rc, err = C.zmq_msg_init(&m); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\tdefer C.zmq_msg_close(&m)\n\t// Receive into message\n\tif rc, err = C.zmq_recv(s.s, &m, C.int(flags)); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\terr = nil\n\t// Copy message data into a byte array\n\t// FIXME Ideally this wouldn't require a copy.\n\tsize := C.zmq_msg_size(&m)\n\tif size > 0 {\n\t\tdata = C.GoBytes(C.zmq_msg_data(&m), C.int(size))\n\t} else {\n\t\tdata = nil\n\t}\n\treturn\n}\n\n// Portability helper\nfunc (s *Socket) getRcvmore() (more bool, err error) {\n\tvalue, err := s.GetSockOptUInt64(RCVMORE)\n\tmore = value != 0\n\treturn\n}\n"
  },
  {
    "path": "zmq_3_x.go",
    "content": "// +build zmq_3_x zmq_4_x\n\n/*\n  Copyright 2010-2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n#include <stdlib.h>\n#include <string.h>\n*/\nimport \"C\"\nimport (\n\t\"errors\"\n\t\"unsafe\"\n)\n\nconst (\n\tRCVMORE = IntSocketOption(C.ZMQ_RCVMORE)\n\tSNDHWM  = IntSocketOption(C.ZMQ_SNDHWM)\n\tRCVHWM  = IntSocketOption(C.ZMQ_RCVHWM)\n\n\t// TODO Not documented in the man page...\n\t//LAST_ENDPOINT       = UInt64SocketOption(C.ZMQ_LAST_ENDPOINT)\n\tDELAY_ATTACH_ON_CONNECT = IntSocketOption(C.ZMQ_DELAY_ATTACH_ON_CONNECT)\n\tFAIL_UNROUTABLE         = BoolSocketOption(C.ZMQ_FAIL_UNROUTABLE)\n\tIPV4ONLY                = IntSocketOption(C.ZMQ_IPV4ONLY)\n\tMAXMSGSIZE              = Int64SocketOption(C.ZMQ_MAXMSGSIZE)\n\tROUTER_MANDATORY        = IntSocketOption(C.ZMQ_ROUTER_MANDATORY)\n\tTCP_KEEPALIVE           = IntSocketOption(C.ZMQ_TCP_KEEPALIVE)\n\tTCP_KEEPALIVE_CNT       = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_CNT)\n\tTCP_KEEPALIVE_IDLE      = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_IDLE)\n\tTCP_KEEPALIVE_INTVL     = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_INTVL)\n\tTCP_ACCEPT_FILTER       = StringSocketOption(C.ZMQ_TCP_ACCEPT_FILTER)\n\tXPUB_VERBOSE            = IntSocketOption(C.ZMQ_XPUB_VERBOSE)\n\n\t// Message options\n\tMORE = MessageOption(C.ZMQ_MORE)\n\n\t// Send/recv options\n\tDONTWAIT = SendRecvOption(C.ZMQ_DONTWAIT)\n\n\t// Deprecated aliases\n\tNOBLOCK = DONTWAIT\n)\n\n// Socket transport events\ntype Event int\n\nconst (\n\tEVENT_CONNECTED       = Event(C.ZMQ_EVENT_CONNECTED)\n\tEVENT_CONNECT_DELAYED = Event(C.ZMQ_EVENT_CONNECT_DELAYED)\n\tEVENT_CONNECT_RETRIED = Event(C.ZMQ_EVENT_CONNECT_RETRIED)\n\n\tEVENT_LISTENING   = Event(C.ZMQ_EVENT_LISTENING)\n\tEVENT_BIND_FAILED = Event(C.ZMQ_EVENT_BIND_FAILED)\n\n\tEVENT_ACCEPTED      = Event(C.ZMQ_EVENT_ACCEPTED)\n\tEVENT_ACCEPT_FAILED = Event(C.ZMQ_EVENT_ACCEPT_FAILED)\n\n\tEVENT_CLOSED       = Event(C.ZMQ_EVENT_CLOSED)\n\tEVENT_CLOSE_FAILED = Event(C.ZMQ_EVENT_CLOSE_FAILED)\n\tEVENT_DISCONNECTED = Event(C.ZMQ_EVENT_DISCONNECTED)\n\n\tEVENT_ALL = EVENT_CONNECTED | EVENT_CONNECT_DELAYED |\n\t\tEVENT_CONNECT_RETRIED | EVENT_LISTENING | EVENT_BIND_FAILED |\n\t\tEVENT_ACCEPTED | EVENT_ACCEPT_FAILED | EVENT_CLOSED |\n\t\tEVENT_CLOSE_FAILED | EVENT_DISCONNECTED\n)\n\n// Get a context option.\n// int zmq_ctx_get (void *c, int);\nfunc (c *Context) get(option C.int) (int, error) {\n\tif c.init(); c.err != nil {\n\t\treturn -1, c.err\n\t}\n\tvar value C.int\n\tvar err error\n\tif value, err = C.zmq_ctx_get(c.c, option); err != nil {\n\t\treturn -1, casterr(err)\n\t}\n\treturn int(value), nil\n}\n\n// Set a context option.\n// int zmq_ctx_set (void *c, int, int);\nfunc (c *Context) set(option C.int, value int) error {\n\tif c.init(); c.err != nil {\n\t\treturn c.err\n\t}\n\tif rc, err := C.zmq_ctx_set(c.c, option, C.int(value)); rc == -1 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\nfunc (c *Context) IOThreads() (int, error) {\n\treturn c.get(C.ZMQ_IO_THREADS)\n}\n\nfunc (c *Context) MaxSockets() (int, error) {\n\treturn c.get(C.ZMQ_MAX_SOCKETS)\n}\n\nfunc (c *Context) SetIOThreads(value int) error {\n\treturn c.set(C.ZMQ_IO_THREADS, value)\n}\n\nfunc (c *Context) SetMaxSockets(value int) error {\n\treturn c.set(C.ZMQ_MAX_SOCKETS, value)\n}\n\nfunc (s *Socket) SetHWM(value int) error {\n\tsnd := s.SetSndHWM(value)\n\trcv := s.SetRcvHWM(value)\n\tif snd != nil {\n\t\treturn snd\n\t}\n\treturn rcv\n}\n\nfunc (s *Socket) SetTCPAcceptFilterNil() error {\n\treturn s.SetSockOptStringNil(TCP_ACCEPT_FILTER)\n}\n\n// Disconnect the socket from the address.\n// int zmq_disconnect (void *s, const char *addr);\nfunc (s *Socket) Disconnect(address string) error {\n\tif s.c == nil {\n\t\treturn ENOTSOCK\n\t}\n\ta := C.CString(address)\n\tdefer C.free(unsafe.Pointer(a))\n\tif rc, err := C.zmq_disconnect(s.s, a); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Send a message to the socket.\n// int zmq_send (void *s, zmq_msg_t *msg, int flags);\nfunc (s *Socket) Send(data []byte, flags SendRecvOption) error {\n\tvar m C.zmq_msg_t\n\t// Copy data array into C-allocated buffer.\n\tsize := C.size_t(len(data))\n\n\tif rc, err := C.zmq_msg_init_size(&m, size); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\n\tif size > 0 {\n\t\t// FIXME Ideally this wouldn't require a copy.\n\t\tC.memcpy(C.zmq_msg_data(&m), unsafe.Pointer(&data[0]), size) // XXX I hope this works...(seems to)\n\t}\n\n\tif rc, err := C.zmq_sendmsg(s.s, &m, C.int(flags)); rc == -1 {\n\t\t// zmq_send did not take ownership, free message\n\t\tC.zmq_msg_close(&m)\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Receive a message from the socket.\n// int zmq_recv (void *s, zmq_msg_t *msg, int flags);\nfunc (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) {\n\t// Allocate and initialise a new zmq_msg_t\n\tvar m C.zmq_msg_t\n\tvar rc C.int\n\tif rc, err = C.zmq_msg_init(&m); rc != 0 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\tdefer C.zmq_msg_close(&m)\n\t// Receive into message\n\tif rc, err = C.zmq_recvmsg(s.s, &m, C.int(flags)); rc == -1 {\n\t\terr = casterr(err)\n\t\treturn\n\t}\n\terr = nil\n\t// Copy message data into a byte array\n\t// FIXME Ideally this wouldn't require a copy.\n\tsize := C.zmq_msg_size(&m)\n\tif size > 0 {\n\t\tdata = C.GoBytes(C.zmq_msg_data(&m), C.int(size))\n\t} else {\n\t\tdata = nil\n\t}\n\treturn\n}\n\n// Register a monitoring callback endpoint.\n// int zmq_socket_monitor (void *s, const char *addr, int events);\nfunc (s *Socket) Monitor(address string, events Event) error {\n\ta := C.CString(address)\n\tdefer C.free(unsafe.Pointer(a))\n\n\trc, err := C.zmq_socket_monitor(s.apiSocket(), a, C.int(events))\n\tif rc == -1 {\n\t\treturn casterr(err)\n\t}\n\treturn nil\n}\n\n// Portability helper\nfunc (s *Socket) getRcvmore() (more bool, err error) {\n\tvalue, err := s.GetSockOptInt(RCVMORE)\n\tmore = value != 0\n\treturn\n}\n\n// run a zmq_proxy with in, out and capture sockets\nfunc Proxy(in, out, capture *Socket) error {\n\tvar c unsafe.Pointer\n\tif capture != nil {\n\t\tc = capture.apiSocket()\n\t}\n\tif rc, err := C.zmq_proxy(in.apiSocket(), out.apiSocket(), c); rc != 0 {\n\t\treturn casterr(err)\n\t}\n\treturn errors.New(\"zmq_proxy() returned unexpectedly.\")\n}\n"
  },
  {
    "path": "zmq_3_x_test.go",
    "content": "// +build zmq_3_x zmq_4_x\n\n/*\n  Copyright 2010 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\npackage gozmq\n\nimport (\n\t\"errors\"\n\t\"testing\"\n\t\"time\"\n)\n\nconst ADDR_PROXY_IN = \"tcp://127.0.0.1:24114\"\nconst ADDR_PROXY_OUT = \"tcp://127.0.0.1:24115\"\nconst ADDR_PROXY_CAP = \"tcp://127.0.0.1:24116\"\n\nfunc TestProxy(t *testing.T) {\n\tte1, te2 := NewTestEnv(t), NewTestEnv(t)\n\texitOk := make(chan bool, 1)\n\tgo func() {\n\t\tin := te1.NewBoundSocket(ROUTER, ADDR_PROXY_IN)\n\t\tout := te1.NewBoundSocket(DEALER, ADDR_PROXY_OUT)\n\t\tcapture := te1.NewBoundSocket(PUSH, ADDR_PROXY_CAP)\n\t\terr := Proxy(in, out, capture)\n\n\t\tselect {\n\t\tcase <-exitOk:\n\t\tdefault:\n\t\t\tt.Error(\"Proxy() failed: \", err)\n\t\t}\n\t}()\n\n\tin := te2.NewConnectedSocket(REQ, ADDR_PROXY_IN)\n\tout := te2.NewConnectedSocket(REP, ADDR_PROXY_OUT)\n\tcapture := te2.NewConnectedSocket(PULL, ADDR_PROXY_CAP)\n\ttime.Sleep(1e8)\n\tte2.Send(in, nil, 0)\n\tte2.Recv(out, 0)\n\tte2.Recv(capture, 0)\n\n\tte2.Close()\n\texitOk <- true\n\tte1.Close()\n}\n\nfunc TestProxyNoCapture(t *testing.T) {\n\tte1, te2 := NewTestEnv(t), NewTestEnv(t)\n\texitOk := make(chan bool, 1)\n\tgo func() {\n\t\tin := te1.NewBoundSocket(ROUTER, ADDR_PROXY_IN)\n\t\tout := te1.NewBoundSocket(DEALER, ADDR_PROXY_OUT)\n\t\terr := Proxy(in, out, nil)\n\n\t\tselect {\n\t\tcase <-exitOk:\n\t\tdefault:\n\t\t\tt.Error(\"Proxy() failed: \", err)\n\t\t}\n\t}()\n\n\tin := te2.NewConnectedSocket(REQ, ADDR_PROXY_IN)\n\tout := te2.NewConnectedSocket(REP, ADDR_PROXY_OUT)\n\ttime.Sleep(1e8)\n\tte2.Send(in, nil, 0)\n\tte2.Recv(out, 0)\n\n\tte2.Close()\n\texitOk <- true\n\tte1.Close()\n}\n\nfunc TestSocket_SetSockOptStringNil(t *testing.T) {\n\tfailed := make(chan bool, 2)\n\tc, _ := NewContext()\n\tdefer c.Close()\n\tgo func() {\n\t\tsrv, _ := c.NewSocket(REP)\n\t\tdefer srv.Close()\n\t\tsrv.SetSockOptString(TCP_ACCEPT_FILTER, \"127.0.0.1\")\n\t\tsrv.SetSockOptString(TCP_ACCEPT_FILTER, \"192.0.2.1\")\n\t\tsrv.Bind(ADDRESS1) // 127.0.0.1 and 192.0.2.1 are allowed here.\n\t\t// The test will fail if the following line is removed:\n\t\tsrv.SetSockOptStringNil(TCP_ACCEPT_FILTER)\n\t\tsrv.SetSockOptString(TCP_ACCEPT_FILTER, \"192.0.2.2\")\n\t\tsrv.Bind(ADDRESS2) // Only 192.0.2.1 is allowed here.\n\t\tfor {\n\t\t\tif _, err := srv.Recv(0); err != nil {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tsrv.Send(nil, 0)\n\t\t}\n\t}()\n\tgo func() {\n\t\ts2, _ := c.NewSocket(REQ)\n\t\tdefer s2.Close()\n\t\ts2.SetSockOptInt(LINGER, 0)\n\t\ts2.Connect(ADDRESS2)\n\t\ts2.Send(nil, 0)\n\t\tif _, err := s2.Recv(0); err == nil {\n\t\t\t// 127.0.0.1 is supposed to be ignored by ADDRESS2:\n\t\t\tt.Error(\"SetSockOptStringNil did not clear TCP_ACCEPT_FILTER.\")\n\t\t}\n\t\tfailed <- true\n\t}()\n\ts1, _ := c.NewSocket(REQ)\n\tdefer s1.Close()\n\ts1.Connect(ADDRESS1)\n\ts1.Send(nil, 0)\n\ts1.Recv(0)\n\tselect {\n\tcase <-failed:\n\tcase <-time.After(50 * time.Millisecond):\n\t}\n}\n\nconst (\n\tTESTMONITOR_ADDR_SINK   = \"tcp://127.0.0.1:24117\"\n\tTESTMONITOR_ADDR_EVENTS = \"inproc://TestMonitorEvents\"\n)\n\nfunc TestMonitor(t *testing.T) {\n\tte := NewTestEnv(t)\n\tdefer te.Close()\n\n\t// Prepare the sink socket.\n\tout := te.NewSocket(PULL)\n\terr := out.Bind(TESTMONITOR_ADDR_SINK)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\t// Prepare the source socket, do not connect yet.\n\tin := te.NewSocket(PUSH)\n\tdefer in.Close()\n\n\t// Attach the monitor.\n\terr = in.Monitor(TESTMONITOR_ADDR_EVENTS,\n\t\tEVENT_CONNECTED|EVENT_DISCONNECTED)\n\tif err != nil {\n\t\tout.Close()\n\t\tt.Fatal(err)\n\t}\n\n\tmonitor := te.NewConnectedSocket(PAIR, TESTMONITOR_ADDR_EVENTS)\n\n\t// Connect the client to the server, wait for EVENT_CONNECTED.\n\terr = in.Connect(TESTMONITOR_ADDR_SINK)\n\tif err != nil {\n\t\tout.Close()\n\t\tt.Fatal(err)\n\t}\n\n\terr = waitForEvent(t, monitor)\n\tif err != nil {\n\t\tout.Close()\n\t\tt.Fatal(err)\n\t}\n\n\t// Close the sink socket, wait for EVENT_DISCONNECTED.\n\terr = out.Close()\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n\n\terr = waitForEvent(t, monitor)\n\tif err != nil {\n\t\tt.Fatal(err)\n\t}\n}\n\nfunc waitForEvent(t *testing.T, monitor *Socket) error {\n\texit := make(chan error, 1)\n\n\t// This goroutine will return either when an event is received\n\t// or the context is closed.\n\tgo func() {\n\t\t// RecvMultipart should work for both zeromq3-x and libzmq API.\n\t\t_, ex := monitor.RecvMultipart(0)\n\t\texit <- ex\n\t}()\n\n\ttimeout := time.After(time.Second)\n\n\tselect {\n\tcase err := <-exit:\n\t\treturn err\n\tcase <-timeout:\n\t\treturn errors.New(\"Test timed out\")\n\t}\n\n\treturn nil\n}\n"
  },
  {
    "path": "zmq_4_x.go",
    "content": "// +build zmq_4_x\n\n/*\n  Copyright 2010-2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n#include <stdlib.h>\n#include <string.h>\n*/\nimport \"C\"\n\nconst (\n\tIPV6            = IntSocketOption(C.ZMQ_IPV6)\n\tIMMEDIATE       = IntSocketOption(C.ZMQ_IMMEDIATE)\n\tMECHANISM       = IntSocketOption(C.ZMQ_MECHANISM)\n\tPLAIN_SERVER    = IntSocketOption(C.ZMQ_PLAIN_SERVER)\n\tPLAIN_USERNAME  = StringSocketOption(C.ZMQ_PLAIN_USERNAME)\n\tPLAIN_PASSWORD  = StringSocketOption(C.ZMQ_PLAIN_PASSWORD)\n\tCURVE_PUBLICKEY = StringSocketOption(C.ZMQ_CURVE_PUBLICKEY)\n\tCURVE_SECRETKEY = StringSocketOption(C.ZMQ_CURVE_SECRETKEY)\n\tCURVE_SERVERKEY = StringSocketOption(C.ZMQ_CURVE_SERVERKEY)\n\tZAP_DOMAIN      = StringSocketOption(C.ZMQ_ZAP_DOMAIN)\n\tROUTER_RAW      = IntSocketOption(C.ZMQ_ROUTER_RAW)\n\tPROBE_ROUTER    = IntSocketOption(C.ZMQ_PROBE_ROUTER)\n\tREQ_CORRELATE   = IntSocketOption(C.ZMQ_REQ_CORRELATE)\n\tREQ_RELAXED     = IntSocketOption(C.ZMQ_REQ_RELAXED)\n\tCURVE_SERVER    = IntSocketOption(C.ZMQ_CURVE_SERVER)\n\tCONFLATE        = IntSocketOption(C.ZMQ_CONFLATE)\n)\n"
  },
  {
    "path": "zmq_test.go",
    "content": "/*\n  Copyright 2010 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\npackage gozmq\n\nimport (\n\t\"log\"\n\t\"runtime\"\n\t\"syscall\"\n\t\"testing\"\n\t\"time\"\n)\n\nconst ADDRESS1 = \"tcp://127.0.0.1:23456\"\nconst ADDRESS2 = \"tcp://127.0.0.1:23457\"\nconst ADDRESS3 = \"tcp://127.0.0.1:23458\"\n\n// Addresses for the device test. These cannot be reused since the device\n// will keep running after the test terminates\nconst ADDR_DEV_IN = \"tcp://127.0.0.1:24111\"\nconst ADDR_DEV_OUT = \"tcp://127.0.0.1:24112\"\n\n// a process local address\nconst ADDRESS_INPROC = \"inproc://test\"\n\nconst SERVER_READY = \"SERVER READY\"\n\nfunc runServer(t *testing.T, c *Context, callback func(s *Socket)) chan bool {\n\tfinished := make(chan bool)\n\tgo func() {\n\t\truntime.LockOSThread()\n\t\tdefer runtime.UnlockOSThread()\n\t\ts, _ := c.NewSocket(REP)\n\t\tdefer s.Close()\n\t\tif rc := s.Bind(ADDRESS1); rc != nil {\n\t\t\tt.Errorf(\"Failed to bind to %s; %s\", ADDRESS1, rc.Error())\n\t\t}\n\t\tcallback(s)\n\t\tfinished <- true\n\t}()\n\treturn finished\n}\n\nfunc runPollServer(t *testing.T) (done, bound chan bool) {\n\tdone = make(chan bool)\n\tbound = make(chan bool)\n\tgo func() {\n\t\tte := NewTestEnv(t)\n\t\tdefer te.Close()\n\t\ts1 := te.NewBoundSocket(REP, ADDRESS1)\n\t\ts2 := te.NewBoundSocket(REP, ADDRESS2)\n\t\ts3 := te.NewBoundSocket(REP, ADDRESS3)\n\n\t\tpi := PollItems{\n\t\t\tPollItem{Socket: s1, Events: POLLIN},\n\t\t\tPollItem{Socket: s2, Events: POLLIN},\n\t\t\tPollItem{Socket: s3, Events: POLLIN},\n\t\t}\n\t\tbound <- true\n\n\t\tsent := 0\n\t\tfor {\n\t\t\t_, err := Poll(pi, -1)\n\t\t\tif err != nil {\n\t\t\t\tdone <- false\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tswitch {\n\t\t\tcase pi[0].REvents&POLLIN != 0:\n\t\t\t\tpi[0].Socket.Recv(0) // eat the incoming message\n\t\t\t\tpi[0].Socket.Send(nil, 0)\n\t\t\t\tsent++\n\t\t\tcase pi[1].REvents&POLLIN != 0:\n\t\t\t\tpi[1].Socket.Recv(0) // eat the incoming message\n\t\t\t\tpi[1].Socket.Send(nil, 0)\n\t\t\t\tsent++\n\t\t\tcase pi[2].REvents&POLLIN != 0:\n\t\t\t\tpi[2].Socket.Recv(0) // eat the incoming message\n\t\t\t\tpi[2].Socket.Send(nil, 0)\n\t\t\t\tsent++\n\t\t\t}\n\n\t\t\tif sent == 3 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tdone <- true\n\t}()\n\treturn\n}\n\nfunc TestVersion(t *testing.T) {\n\tmajor, minor, patch := Version()\n\t// Require at least 2.0.9\n\tif major > 2 && minor >= 0 && patch >= 9 {\n\t\tt.Errorf(\"expected at least 0mq version 2.0.9\")\n\t}\n}\n\nfunc TestCreateDestroyContext(t *testing.T) {\n\tc, _ := NewContext()\n\tc.Close()\n\tc, _ = NewContext()\n\tc.Close()\n}\n\nfunc TestContext_IOThreads(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\tif iothreads, err := c.IOThreads(); err != nil {\n\t\tt.Fatalf(\"Failed to get IO_THREADS: %s\", err.Error())\n\t} else if iothreads != 1 {\n\t\tt.Fatalf(\"Got IO_THREADS = %s\", iothreads)\n\t}\n}\n\nfunc TestContext_SetIOThreads(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\tif err := c.SetIOThreads(2); err != nil {\n\t\tt.Fatalf(\"Failed to set IO_THREADS: %s\", err.Error())\n\t}\n\tif iothreads, err := c.IOThreads(); err != nil {\n\t\tt.Fatalf(\"Failed to get IO_THREADS: %s\", err.Error())\n\t} else if iothreads != 2 {\n\t\tt.Fatalf(\"Got IO_THREADS = %s\", iothreads)\n\t}\n}\n\nfunc TestSocket_Connect(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\ts, _ := c.NewSocket(REP)\n\tdefer s.Close()\n\tif rc := s.Connect(ADDRESS1); rc != nil {\n\t\tt.Errorf(\"Failed to bind to %s; %s\", ADDRESS1, rc.Error())\n\t}\n\tbad_address := \"a malformed address\"\n\trc := s.Connect(bad_address)\n\tswitch rc {\n\tcase syscall.EINVAL: //pass\n\tcase nil:\n\t\tt.Errorf(\"Connected to %s\", bad_address)\n\tdefault:\n\t\tt.Errorf(\"Received incorrect error connecting to %s; %s\", bad_address, rc.Error())\n\t}\n\ts.Close()\n\trc = s.Connect(ADDRESS1)\n\tswitch rc {\n\tcase ENOTSOCK: //pass\n\tcase nil:\n\t\tt.Errorf(\"Connected a closed socket\")\n\tdefault:\n\t\tt.Errorf(\"Expected ENOTSOCK, got %T(%d); %s\", rc, rc, rc.Error())\n\t}\n}\n\nfunc TestBindToLoopBack(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\ts, _ := c.NewSocket(REP)\n\tdefer s.Close()\n\tif rc := s.Bind(ADDRESS1); rc != nil {\n\t\tt.Errorf(\"Failed to bind to %s; %s\", ADDRESS1, rc.Error())\n\t}\n}\n\nfunc TestSetSockOptInt(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\ts, _ := c.NewSocket(REQ)\n\tdefer s.Close()\n\tvar linger int = 42\n\tif rc := s.SetSockOptInt(LINGER, linger); rc != nil {\n\t\tt.Errorf(\"Failed to set linger; %v\", rc)\n\t}\n\tif val, rc := s.GetSockOptInt(LINGER); rc != nil {\n\t\tt.Errorf(\"Failed to get linger; %v\", rc)\n\t} else if val != linger {\n\t\tt.Errorf(\"Expected %d, got %d\", linger, val)\n\t}\n}\n\nfunc TestSetSockOptString(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\ts, _ := c.NewSocket(SUB)\n\tdefer s.Close()\n\tif rc := s.Bind(ADDRESS1); rc != nil {\n\t\tt.Errorf(\"Failed to bind to %s; %s\", ADDRESS1, rc.Error())\n\t}\n\tif rc := s.SetSockOptString(SUBSCRIBE, \"TEST\"); rc != nil {\n\t\tt.Errorf(\"Failed to subscribe; %v\", rc)\n\t}\n\tif rc := s.SetSubscribe(\"TEST\"); rc != nil {\n\t\tt.Errorf(\"Failed to subscribe; %v\", rc)\n\t}\n\tif rc := s.SetUnsubscribe(\"TEST\"); rc != nil {\n\t\tt.Errorf(\"Failed to unsubscribe; %v\", rc)\n\t}\n}\n\nfunc TestMultipart(t *testing.T) {\n\tc, _ := NewContext()\n\tdefer c.Close()\n\tfinished := runServer(t, c, func(s *Socket) {\n\t\tparts, rc := s.RecvMultipart(0)\n\t\tif rc != nil {\n\t\t\tt.Errorf(\"Failed to receive multipart message; %s\", rc.Error())\n\t\t}\n\t\tif len(parts) != 2 {\n\t\t\tt.Errorf(\"Invalid multipart message, not enough parts; %d\", len(parts))\n\t\t}\n\t\tif string(parts[0]) != \"part1\" || string(parts[1]) != \"part2\" {\n\t\t\tt.Errorf(\"Invalid multipart message.\")\n\t\t}\n\t})\n\n\ts, _ := c.NewSocket(REQ)\n\tdefer s.Close()\n\tif rc := s.Connect(ADDRESS1); rc != nil {\n\t\tt.Errorf(\"Failed to connect to %s; %s\", ADDRESS1, rc.Error())\n\t}\n\tif rc := s.SendMultipart([][]byte{[]byte(\"part1\"), []byte(\"part2\")}, 0); rc != nil {\n\t\tt.Errorf(\"Failed to send multipart message; %s\", rc.Error())\n\t}\n\t<-finished\n}\n\nfunc TestPoll(t *testing.T) {\n\tte := NewTestEnv(t)\n\tdefer te.Close()\n\tfinished, bound := runPollServer(t)\n\n\t// wait for sockets to bind\n\t<-bound\n\n\tfor _, addr := range []string{ADDRESS2, ADDRESS3, ADDRESS1} {\n\t\tsock := te.NewConnectedSocket(REQ, addr)\n\t\tte.Send(sock, []byte(\"request data\"), 0)\n\t\tte.Recv(sock, 0)\n\t}\n\n\t<-finished\n\n}\n\nfunc TestDevice(t *testing.T) {\n\tgo func() {\n\t\t// the device will never exit so this goroutine will never terminate\n\t\tte := NewTestEnv(t)\n\t\tdefer te.Close()\n\t\tin := te.NewBoundSocket(PULL, ADDR_DEV_IN)\n\t\tout := te.NewBoundSocket(PUSH, ADDR_DEV_OUT)\n\t\terr := Device(STREAMER, in, out)\n\n\t\t// Should never get to here\n\t\tt.Error(\"Device() failed: \", err)\n\t}()\n\n\tte := NewTestEnv(t)\n\tdefer te.Close()\n\tout := te.NewConnectedSocket(PUSH, ADDR_DEV_IN)\n\tin := te.NewConnectedSocket(PULL, ADDR_DEV_OUT)\n\n\ttime.Sleep(1e8)\n\n\tte.Send(out, nil, 0)\n\tte.Recv(in, 0)\n}\n\nfunc TestZmqErrorStr(t *testing.T) {\n\tvar e error = EFSM\n\tes := e.Error()\n\tif es != \"Operation cannot be accomplished in current state\" {\n\t\tt.Errorf(\"EFSM.String() returned unexpected result: %s\", e)\n\t}\n}\n\nfunc TestZmqErrorComparison(t *testing.T) {\n\tvar e error = getErrorForTesting()\n\tif e != EFSM {\n\t\tt.Errorf(\"EFSM did not compare correctly. This should not happen.\")\n\t}\n}\n\n// expensive test - send a huge amount of data. should be enough to\n// trash a current machine if Send or Recv are leaking.\n/*\nfunc TestMessageMemory(t *testing.T) {\n\t// primarily to see if Send or Recv are leaking memory\n\n\tconst MSG_SIZE = 1e6\n\tconst MSG_COUNT = 100 * 1000\n\n\tte := NewTestEnv(nil)\n\tdefer te.Close()\n\n\tdata := make([]byte, MSG_SIZE)\n\n\tout := te.NewBoundSocket(PUSH, ADDRESS1)\n\tin := te.NewConnectedSocket(PULL, ADDRESS1)\n\n\tfor i := 0; i < MSG_COUNT; i++ {\n\t\tte.Send(out, data, 0)\n\t\td2 := te.Recv(in, 0)\n\t\tif len(d2) != MSG_SIZE {\n\t\t\tt.Errorf(\"Bad message size received\")\n\t\t}\n\t}\n}\n*/\n\nfunc doBenchmarkSendReceive(b *testing.B, size int, addr string) {\n\t// since this is a benchmark it should probably call\n\t// this package's api functions directly rather than\n\t// using the testEnv wrappers\n\tb.StopTimer()\n\tdata := make([]byte, size)\n\n\tte := NewTestEnv(nil)\n\tdefer te.Close()\n\tb.StartTimer()\n\n\tout := te.NewBoundSocket(PUSH, ADDRESS1)\n\tin := te.NewConnectedSocket(PULL, ADDRESS1)\n\n\tfor i := 0; i < b.N; i++ {\n\t\tte.Send(out, data, 0)\n\t\td2 := te.Recv(in, 0)\n\t\tif len(d2) != size {\n\t\t\tpanic(\"Bad message size received\")\n\t\t}\n\t}\n}\n\nfunc BenchmarkSendReceive1Btcp(b *testing.B) {\n\tdoBenchmarkSendReceive(b, 1, ADDRESS1)\n}\n\nfunc BenchmarkSendReceive1KBtcp(b *testing.B) {\n\tdoBenchmarkSendReceive(b, 1e3, ADDRESS1)\n}\n\nfunc BenchmarkSendReceive1MBtcp(b *testing.B) {\n\tdoBenchmarkSendReceive(b, 1e6, ADDRESS1)\n}\n\nfunc BenchmarkSendReceive1Binproc(b *testing.B) {\n\tdoBenchmarkSendReceive(b, 1, ADDRESS_INPROC)\n}\n\nfunc BenchmarkSendReceive1KBinproc(b *testing.B) {\n\tdoBenchmarkSendReceive(b, 1e3, ADDRESS_INPROC)\n}\n\nfunc BenchmarkSendReceive1MBinproc(b *testing.B) {\n\tdoBenchmarkSendReceive(b, 1e6, ADDRESS_INPROC)\n}\n\n// A helper to make tests less verbose\ntype testEnv struct {\n\tcontext *Context\n\tsockets []*Socket\n\tt       *testing.T\n}\n\nfunc NewTestEnv(t *testing.T) *testEnv {\n\t// Encapsulate everything, including (unnecessarily) the context\n\t// in the same thread.\n\truntime.LockOSThread()\n\tc, err := NewContext()\n\tif err != nil {\n\t\tt.Errorf(\"failed to create context in testEnv: %v\", err)\n\t\tt.FailNow()\n\t}\n\treturn &testEnv{context: c, t: t}\n}\n\nfunc (te *testEnv) NewSocket(t SocketType) *Socket {\n\ts, err := te.context.NewSocket(t)\n\tif err != nil {\n\t\tlog.Panicf(\"Failed to Create socket of type %v: %v\", t, err)\n\t}\n\treturn s\n}\n\nfunc (te *testEnv) NewBoundSocket(t SocketType, bindAddr string) *Socket {\n\ts := te.NewSocket(t)\n\tif err := s.Bind(bindAddr); err != nil {\n\t\tlog.Panicf(\"Failed to connect to %v: %v\", bindAddr, err)\n\t}\n\tte.pushSocket(s)\n\treturn s\n}\n\nfunc (te *testEnv) NewConnectedSocket(t SocketType, connectAddr string) *Socket {\n\ts := te.NewSocket(t)\n\tif err := s.Connect(connectAddr); err != nil {\n\t\tlog.Panicf(\"Failed to connect to %v: %v\", connectAddr, err)\n\t}\n\tte.pushSocket(s)\n\treturn s\n}\n\nfunc (te *testEnv) pushSocket(s *Socket) {\n\tte.sockets = append(te.sockets, s)\n}\n\nfunc (te *testEnv) Close() {\n\tif err := recover(); err != nil {\n\t\tte.t.Errorf(\"failed in testEnv: %v\", err)\n\t}\n\n\tfor _, s := range te.sockets {\n\t\ts.Close()\n\t}\n\n\tif te.context != nil {\n\t\tte.context.Close()\n\t}\n\truntime.UnlockOSThread()\n}\n\nfunc (te *testEnv) Send(sock *Socket, data []byte, flags SendRecvOption) {\n\tif err := sock.Send(data, flags); err != nil {\n\t\tte.t.Errorf(\"Send failed\")\n\t}\n}\n\nfunc (te *testEnv) Recv(sock *Socket, flags SendRecvOption) []byte {\n\tdata, err := sock.Recv(flags)\n\tif err != nil {\n\t\tte.t.Errorf(\"Receive failed\")\n\t}\n\treturn data\n}\n\n// TODO Test various socket types. UDP, TCP, etc.\n// TODO Test NOBLOCK mode.\n// TODO Test getting/setting socket options. Probably sufficient to do just one\n// int and one string test.\n\n// TODO Test that closing a context underneath a socket behaves \"reasonably\" (ie. doesnt' crash).\n"
  },
  {
    "path": "zmq_unix.go",
    "content": "// +build darwin freebsd linux netbsd openbsd\n\n/*\n  Copyright 2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n*/\nimport \"C\"\n\ntype ZmqOsSocketType C.int\n\nfunc (self ZmqOsSocketType) ToRaw() C.int {\n\treturn C.int(self)\n}\n"
  },
  {
    "path": "zmq_windows.go",
    "content": "/*\n  Copyright 2012 Alec Thomas\n\n  Licensed under the Apache License, Version 2.0 (the \"License\");\n  you may not use this file except in compliance with the License.\n  You may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\n  Unless required by applicable law or agreed to in writing, software\n  distributed under the License is distributed on an \"AS IS\" BASIS,\n  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n  See the License for the specific language governing permissions and\n  limitations under the License.\n*/\n\npackage gozmq\n\n/*\n#cgo pkg-config: libzmq\n#include <zmq.h>\n*/\nimport \"C\"\n\ntype ZmqOsSocketType C.SOCKET\n\nfunc (self ZmqOsSocketType) ToRaw() C.SOCKET {\n\treturn C.SOCKET(self)\n}\n"
  },
  {
    "path": "zmqgen_2_1.go",
    "content": "// +build zmq_2_1\n//\n\npackage gozmq\n\nimport (\n\t\"time\"\n)\n\n// This file was generated automatically.  Changes made here will be lost.\n\n// Socket Option Getters\n\n// ZMQ_TYPE: Retrieve socket type.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc3\n//\nfunc (s *Socket) Type() (SocketType, error) {\n\tvalue, err := s.GetSockOptUInt64(TYPE)\n\treturn SocketType(value), err\n}\n\n// ZMQ_RCVMORE: More message parts to follow.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc4\n//\nfunc (s *Socket) RcvMore() (bool, error) {\n\tvalue, err := s.GetSockOptUInt64(RCVMORE)\n\treturn value != 0, err\n}\n\n// ZMQ_HWM: Retrieve high water mark.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc5\n//\nfunc (s *Socket) HWM() (uint64, error) {\n\treturn s.GetSockOptUInt64(HWM)\n}\n\n// ZMQ_SWAP: Retrieve disk offload size.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc6\n//\nfunc (s *Socket) Swap() (int64, error) {\n\treturn s.GetSockOptInt64(SWAP)\n}\n\n// ZMQ_AFFINITY: Retrieve I/O thread affinity.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc7\n//\nfunc (s *Socket) Affinity() (uint64, error) {\n\treturn s.GetSockOptUInt64(AFFINITY)\n}\n\n// ZMQ_IDENTITY: Retrieve socket identity.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc8\n//\nfunc (s *Socket) Identity() (string, error) {\n\treturn s.GetSockOptString(IDENTITY)\n}\n\n// ZMQ_RATE: Retrieve multicast data rate.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc9\n//\nfunc (s *Socket) Rate() (int64, error) {\n\treturn s.GetSockOptInt64(RATE)\n}\n\n// ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc11\n//\nfunc (s *Socket) RecoveryIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt64(RECOVERY_IVL_MSEC)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_MCAST_LOOP: Control multicast loop-back.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc12\n//\nfunc (s *Socket) McastLoop() (bool, error) {\n\tvalue, err := s.GetSockOptInt64(MCAST_LOOP)\n\treturn value != 0, err\n}\n\n// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc13\n//\nfunc (s *Socket) SndBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(SNDBUF)\n}\n\n// ZMQ_RCVBUF: Retrieve kernel receive buffer size.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc14\n//\nfunc (s *Socket) RcvBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(RCVBUF)\n}\n\n// ZMQ_LINGER: Retrieve linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc15\n//\nfunc (s *Socket) Linger() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(LINGER)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc16\n//\nfunc (s *Socket) ReconnectIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc17\n//\nfunc (s *Socket) ReconnectIvlMax() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc18\n//\nfunc (s *Socket) Backlog() (int, error) {\n\treturn s.GetSockOptInt(BACKLOG)\n}\n\n// ZMQ_EVENTS: Retrieve socket event state.\n//\n// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc20\n//\nfunc (s *Socket) Events() (uint64, error) {\n\treturn s.GetSockOptUInt64(EVENTS)\n}\n\n// Socket Option Setters\n\n// ZMQ_HWM: Set high water mark.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc3\n//\nfunc (s *Socket) SetHWM(value uint64) error {\n\treturn s.SetSockOptUInt64(HWM, value)\n}\n\n// ZMQ_SWAP: Set disk offload size.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc4\n//\nfunc (s *Socket) SetSwap(value int64) error {\n\treturn s.SetSockOptInt64(SWAP, value)\n}\n\n// ZMQ_AFFINITY: Set I/O thread affinity.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc5\n//\nfunc (s *Socket) SetAffinity(value uint64) error {\n\treturn s.SetSockOptUInt64(AFFINITY, value)\n}\n\n// ZMQ_IDENTITY: Set socket identity.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc6\n//\nfunc (s *Socket) SetIdentity(value string) error {\n\treturn s.SetSockOptString(IDENTITY, value)\n}\n\n// ZMQ_SUBSCRIBE: Establish message filter.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc7\n//\nfunc (s *Socket) SetSubscribe(value string) error {\n\treturn s.SetSockOptString(SUBSCRIBE, value)\n}\n\n// ZMQ_UNSUBSCRIBE: Remove message filter.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc8\n//\nfunc (s *Socket) SetUnsubscribe(value string) error {\n\treturn s.SetSockOptString(UNSUBSCRIBE, value)\n}\n\n// ZMQ_RATE: Set multicast data rate.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc9\n//\nfunc (s *Socket) SetRate(value int64) error {\n\treturn s.SetSockOptInt64(RATE, value)\n}\n\n// ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc11\n//\nfunc (s *Socket) SetRecoveryIvl(value time.Duration) error {\n\treturn s.SetSockOptInt64(RECOVERY_IVL_MSEC, int64(value/time.Millisecond))\n}\n\n// ZMQ_MCAST_LOOP: Control multicast loop-back.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc12\n//\nfunc (s *Socket) SetMcastLoop(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt64(MCAST_LOOP, 1)\n\t}\n\treturn s.SetSockOptInt64(MCAST_LOOP, 0)\n}\n\n// ZMQ_SNDBUF: Set kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc13\n//\nfunc (s *Socket) SetSndBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(SNDBUF, value)\n}\n\n// ZMQ_RCVBUF: Set kernel receive buffer size.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc14\n//\nfunc (s *Socket) SetRcvBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(RCVBUF, value)\n}\n\n// ZMQ_LINGER: Set linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc15\n//\nfunc (s *Socket) SetLinger(value time.Duration) error {\n\treturn s.SetSockOptInt(LINGER, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL: Set reconnection interval.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc16\n//\nfunc (s *Socket) SetReconnectIvl(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc17\n//\nfunc (s *Socket) SetReconnectIvlMax(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))\n}\n\n// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc18\n//\nfunc (s *Socket) SetBacklog(value int) error {\n\treturn s.SetSockOptInt(BACKLOG, value)\n}\n"
  },
  {
    "path": "zmqgen_2_2.go",
    "content": "// +build !zmq_2_1,!zmq_3_x,!zmq_4_x\n//\n\npackage gozmq\n\nimport (\n\t\"time\"\n)\n\n// This file was generated automatically.  Changes made here will be lost.\n\n// Socket Option Getters\n\n// ZMQ_TYPE: Retrieve socket type.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc3\n//\nfunc (s *Socket) Type() (SocketType, error) {\n\tvalue, err := s.GetSockOptUInt64(TYPE)\n\treturn SocketType(value), err\n}\n\n// ZMQ_RCVMORE: More message parts to follow.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc4\n//\nfunc (s *Socket) RcvMore() (bool, error) {\n\tvalue, err := s.GetSockOptUInt64(RCVMORE)\n\treturn value != 0, err\n}\n\n// ZMQ_HWM: Retrieve high water mark.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc5\n//\nfunc (s *Socket) HWM() (uint64, error) {\n\treturn s.GetSockOptUInt64(HWM)\n}\n\n// ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc6\n//\nfunc (s *Socket) RcvTimeout() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RCVTIMEO)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc7\n//\nfunc (s *Socket) SndTimeout() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(SNDTIMEO)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_SWAP: Retrieve disk offload size.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc8\n//\nfunc (s *Socket) Swap() (int64, error) {\n\treturn s.GetSockOptInt64(SWAP)\n}\n\n// ZMQ_AFFINITY: Retrieve I/O thread affinity.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc9\n//\nfunc (s *Socket) Affinity() (uint64, error) {\n\treturn s.GetSockOptUInt64(AFFINITY)\n}\n\n// ZMQ_IDENTITY: Retrieve socket identity.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc10\n//\nfunc (s *Socket) Identity() (string, error) {\n\treturn s.GetSockOptString(IDENTITY)\n}\n\n// ZMQ_RATE: Retrieve multicast data rate.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc11\n//\nfunc (s *Socket) Rate() (int64, error) {\n\treturn s.GetSockOptInt64(RATE)\n}\n\n// ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc13\n//\nfunc (s *Socket) RecoveryIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt64(RECOVERY_IVL_MSEC)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_MCAST_LOOP: Control multicast loop-back.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc14\n//\nfunc (s *Socket) McastLoop() (bool, error) {\n\tvalue, err := s.GetSockOptInt64(MCAST_LOOP)\n\treturn value != 0, err\n}\n\n// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc15\n//\nfunc (s *Socket) SndBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(SNDBUF)\n}\n\n// ZMQ_RCVBUF: Retrieve kernel receive buffer size.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc16\n//\nfunc (s *Socket) RcvBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(RCVBUF)\n}\n\n// ZMQ_LINGER: Retrieve linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc17\n//\nfunc (s *Socket) Linger() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(LINGER)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc18\n//\nfunc (s *Socket) ReconnectIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc19\n//\nfunc (s *Socket) ReconnectIvlMax() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc20\n//\nfunc (s *Socket) Backlog() (int, error) {\n\treturn s.GetSockOptInt(BACKLOG)\n}\n\n// ZMQ_EVENTS: Retrieve socket event state.\n//\n// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc22\n//\nfunc (s *Socket) Events() (uint64, error) {\n\treturn s.GetSockOptUInt64(EVENTS)\n}\n\n// Socket Option Setters\n\n// ZMQ_HWM: Set high water mark.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc3\n//\nfunc (s *Socket) SetHWM(value uint64) error {\n\treturn s.SetSockOptUInt64(HWM, value)\n}\n\n// ZMQ_SWAP: Set disk offload size.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc4\n//\nfunc (s *Socket) SetSwap(value int64) error {\n\treturn s.SetSockOptInt64(SWAP, value)\n}\n\n// ZMQ_AFFINITY: Set I/O thread affinity.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc5\n//\nfunc (s *Socket) SetAffinity(value uint64) error {\n\treturn s.SetSockOptUInt64(AFFINITY, value)\n}\n\n// ZMQ_IDENTITY: Set socket identity.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc6\n//\nfunc (s *Socket) SetIdentity(value string) error {\n\treturn s.SetSockOptString(IDENTITY, value)\n}\n\n// ZMQ_SUBSCRIBE: Establish message filter.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc7\n//\nfunc (s *Socket) SetSubscribe(value string) error {\n\treturn s.SetSockOptString(SUBSCRIBE, value)\n}\n\n// ZMQ_UNSUBSCRIBE: Remove message filter.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc8\n//\nfunc (s *Socket) SetUnsubscribe(value string) error {\n\treturn s.SetSockOptString(UNSUBSCRIBE, value)\n}\n\n// ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc9\n//\nfunc (s *Socket) SetRcvTimeout(value time.Duration) error {\n\treturn s.SetSockOptInt(RCVTIMEO, int(value/time.Millisecond))\n}\n\n// ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc10\n//\nfunc (s *Socket) SetSndTimeout(value time.Duration) error {\n\treturn s.SetSockOptInt(SNDTIMEO, int(value/time.Millisecond))\n}\n\n// ZMQ_RATE: Set multicast data rate.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc11\n//\nfunc (s *Socket) SetRate(value int64) error {\n\treturn s.SetSockOptInt64(RATE, value)\n}\n\n// ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc13\n//\nfunc (s *Socket) SetRecoveryIvl(value time.Duration) error {\n\treturn s.SetSockOptInt64(RECOVERY_IVL_MSEC, int64(value/time.Millisecond))\n}\n\n// ZMQ_MCAST_LOOP: Control multicast loop-back.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc14\n//\nfunc (s *Socket) SetMcastLoop(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt64(MCAST_LOOP, 1)\n\t}\n\treturn s.SetSockOptInt64(MCAST_LOOP, 0)\n}\n\n// ZMQ_SNDBUF: Set kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc15\n//\nfunc (s *Socket) SetSndBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(SNDBUF, value)\n}\n\n// ZMQ_RCVBUF: Set kernel receive buffer size.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc16\n//\nfunc (s *Socket) SetRcvBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(RCVBUF, value)\n}\n\n// ZMQ_LINGER: Set linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc17\n//\nfunc (s *Socket) SetLinger(value time.Duration) error {\n\treturn s.SetSockOptInt(LINGER, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL: Set reconnection interval.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc18\n//\nfunc (s *Socket) SetReconnectIvl(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc19\n//\nfunc (s *Socket) SetReconnectIvlMax(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))\n}\n\n// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc20\n//\nfunc (s *Socket) SetBacklog(value int) error {\n\treturn s.SetSockOptInt(BACKLOG, value)\n}\n"
  },
  {
    "path": "zmqgen_3_2.go",
    "content": "// +build zmq_3_x\n//\n\npackage gozmq\n\nimport (\n\t\"time\"\n)\n\n// This file was generated automatically.  Changes made here will be lost.\n\n// Socket Option Getters\n\n// ZMQ_TYPE: Retrieve socket type.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc3\n//\nfunc (s *Socket) Type() (SocketType, error) {\n\tvalue, err := s.GetSockOptUInt64(TYPE)\n\treturn SocketType(value), err\n}\n\n// ZMQ_RCVMORE: More message data parts to follow.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc4\n//\nfunc (s *Socket) RcvMore() (bool, error) {\n\tvalue, err := s.GetSockOptInt(RCVMORE)\n\treturn value != 0, err\n}\n\n// ZMQ_SNDHWM: Retrieves high water mark for outbound messages.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc5\n//\nfunc (s *Socket) SndHWM() (int, error) {\n\treturn s.GetSockOptInt(SNDHWM)\n}\n\n// ZMQ_RCVHWM: Retrieve high water mark for inbound messages.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc6\n//\nfunc (s *Socket) RcvHWM() (int, error) {\n\treturn s.GetSockOptInt(RCVHWM)\n}\n\n// ZMQ_AFFINITY: Retrieve I/O thread affinity.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc7\n//\nfunc (s *Socket) Affinity() (uint64, error) {\n\treturn s.GetSockOptUInt64(AFFINITY)\n}\n\n// ZMQ_IDENTITY: Set socket identity.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc8\n//\nfunc (s *Socket) Identity() (string, error) {\n\treturn s.GetSockOptString(IDENTITY)\n}\n\n// ZMQ_RATE: Retrieve multicast data rate.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc9\n//\nfunc (s *Socket) Rate() (int64, error) {\n\treturn s.GetSockOptInt64(RATE)\n}\n\n// ZMQ_RECOVERY_IVL: Get multicast recovery interval.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc10\n//\nfunc (s *Socket) RecoveryIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt64(RECOVERY_IVL)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc11\n//\nfunc (s *Socket) SndBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(SNDBUF)\n}\n\n// ZMQ_RCVBUF: Retrieve kernel receive buffer size.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc12\n//\nfunc (s *Socket) RcvBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(RCVBUF)\n}\n\n// ZMQ_LINGER: Retrieve linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc13\n//\nfunc (s *Socket) Linger() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(LINGER)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc14\n//\nfunc (s *Socket) ReconnectIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc15\n//\nfunc (s *Socket) ReconnectIvlMax() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc16\n//\nfunc (s *Socket) Backlog() (int, error) {\n\treturn s.GetSockOptInt(BACKLOG)\n}\n\n// ZMQ_MAXMSGSIZE: Maximum acceptable inbound message size.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc17\n//\nfunc (s *Socket) MaxMsgSize() (int64, error) {\n\treturn s.GetSockOptInt64(MAXMSGSIZE)\n}\n\n// ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc19\n//\nfunc (s *Socket) RcvTimeout() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RCVTIMEO)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc20\n//\nfunc (s *Socket) SndTimeout() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(SNDTIMEO)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_IPV4ONLY: Retrieve IPv4-only socket override status.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc21\n//\nfunc (s *Socket) IPv4Only() (bool, error) {\n\tvalue, err := s.GetSockOptInt(IPV4ONLY)\n\treturn value != 0, err\n}\n\n// ZMQ_DELAY_ATTACH_ON_CONNECT: Retrieve attach-on-connect value.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc22\n//\nfunc (s *Socket) DelayAttachOnConnect() (bool, error) {\n\tvalue, err := s.GetSockOptInt(DELAY_ATTACH_ON_CONNECT)\n\treturn value != 0, err\n}\n\n// ZMQ_EVENTS: Retrieve socket event state.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc24\n//\nfunc (s *Socket) Events() (uint64, error) {\n\treturn s.GetSockOptUInt64(EVENTS)\n}\n\n// ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc26\n//\nfunc (s *Socket) TCPKeepalive() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE)\n}\n\n// ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc27\n//\nfunc (s *Socket) TCPKeepaliveIdle() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE_IDLE)\n}\n\n// ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc28\n//\nfunc (s *Socket) TCPKeepaliveCnt() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE_CNT)\n}\n\n// ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.\n//\n// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc29\n//\nfunc (s *Socket) TCPKeepaliveIntvl() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE_INTVL)\n}\n\n// Socket Option Setters\n\n// ZMQ_SNDHWM: Set high water mark for outbound messages.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc3\n//\nfunc (s *Socket) SetSndHWM(value int) error {\n\treturn s.SetSockOptInt(SNDHWM, value)\n}\n\n// ZMQ_RCVHWM: Set high water mark for inbound messages.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc4\n//\nfunc (s *Socket) SetRcvHWM(value int) error {\n\treturn s.SetSockOptInt(RCVHWM, value)\n}\n\n// ZMQ_AFFINITY: Set I/O thread affinity.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc5\n//\nfunc (s *Socket) SetAffinity(value uint64) error {\n\treturn s.SetSockOptUInt64(AFFINITY, value)\n}\n\n// ZMQ_SUBSCRIBE: Establish message filter.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc6\n//\nfunc (s *Socket) SetSubscribe(value string) error {\n\treturn s.SetSockOptString(SUBSCRIBE, value)\n}\n\n// ZMQ_UNSUBSCRIBE: Remove message filter.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc7\n//\nfunc (s *Socket) SetUnsubscribe(value string) error {\n\treturn s.SetSockOptString(UNSUBSCRIBE, value)\n}\n\n// ZMQ_IDENTITY: Set socket identity.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc8\n//\nfunc (s *Socket) SetIdentity(value string) error {\n\treturn s.SetSockOptString(IDENTITY, value)\n}\n\n// ZMQ_RATE: Set multicast data rate.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc9\n//\nfunc (s *Socket) SetRate(value int64) error {\n\treturn s.SetSockOptInt64(RATE, value)\n}\n\n// ZMQ_RECOVERY_IVL: Set multicast recovery interval.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc10\n//\nfunc (s *Socket) SetRecoveryIvl(value time.Duration) error {\n\treturn s.SetSockOptInt64(RECOVERY_IVL, int64(value/time.Millisecond))\n}\n\n// ZMQ_SNDBUF: Set kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc11\n//\nfunc (s *Socket) SetSndBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(SNDBUF, value)\n}\n\n// ZMQ_RCVBUF: Set kernel receive buffer size.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc12\n//\nfunc (s *Socket) SetRcvBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(RCVBUF, value)\n}\n\n// ZMQ_LINGER: Set linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc13\n//\nfunc (s *Socket) SetLinger(value time.Duration) error {\n\treturn s.SetSockOptInt(LINGER, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL: Set reconnection interval.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc14\n//\nfunc (s *Socket) SetReconnectIvl(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc15\n//\nfunc (s *Socket) SetReconnectIvlMax(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))\n}\n\n// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc16\n//\nfunc (s *Socket) SetBacklog(value int) error {\n\treturn s.SetSockOptInt(BACKLOG, value)\n}\n\n// ZMQ_MAXMSGSIZE: Maximum acceptable inbound message size.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc17\n//\nfunc (s *Socket) SetMaxMsgSize(value int64) error {\n\treturn s.SetSockOptInt64(MAXMSGSIZE, value)\n}\n\n// ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc19\n//\nfunc (s *Socket) SetRcvTimeout(value time.Duration) error {\n\treturn s.SetSockOptInt(RCVTIMEO, int(value/time.Millisecond))\n}\n\n// ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc20\n//\nfunc (s *Socket) SetSndTimeout(value time.Duration) error {\n\treturn s.SetSockOptInt(SNDTIMEO, int(value/time.Millisecond))\n}\n\n// ZMQ_IPV4ONLY: Use IPv4-only sockets.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc21\n//\nfunc (s *Socket) SetIPv4Only(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(IPV4ONLY, 1)\n\t}\n\treturn s.SetSockOptInt(IPV4ONLY, 0)\n}\n\n// ZMQ_DELAY_ATTACH_ON_CONNECT: Accept messages only when connections are made.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc22\n//\nfunc (s *Socket) SetDelayAttachOnConnect(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(DELAY_ATTACH_ON_CONNECT, 1)\n\t}\n\treturn s.SetSockOptInt(DELAY_ATTACH_ON_CONNECT, 0)\n}\n\n// ZMQ_ROUTER_MANDATORY: accept only routable messages on ROUTER sockets.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc23\n//\nfunc (s *Socket) SetROUTERMandatory(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(ROUTER_MANDATORY, 1)\n\t}\n\treturn s.SetSockOptInt(ROUTER_MANDATORY, 0)\n}\n\n// ZMQ_XPUB_VERBOSE: provide all subscription messages on XPUB sockets.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc24\n//\nfunc (s *Socket) SetXPUBVerbose(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(XPUB_VERBOSE, 1)\n\t}\n\treturn s.SetSockOptInt(XPUB_VERBOSE, 0)\n}\n\n// ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc25\n//\nfunc (s *Socket) SetTCPKeepalive(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE, value)\n}\n\n// ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc26\n//\nfunc (s *Socket) SetTCPKeepaliveIdle(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE_IDLE, value)\n}\n\n// ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc27\n//\nfunc (s *Socket) SetTCPKeepaliveCnt(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE_CNT, value)\n}\n\n// ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc28\n//\nfunc (s *Socket) SetTCPKeepaliveIntvl(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE_INTVL, value)\n}\n\n// ZMQ_TCP_ACCEPT_FILTER: Assign filters to allow new TCP connections.\n//\n// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc29\n//\nfunc (s *Socket) SetTCPAcceptFilter(value string) error {\n\treturn s.SetSockOptString(TCP_ACCEPT_FILTER, value)\n}\n"
  },
  {
    "path": "zmqgen_4_0.go",
    "content": "// +build zmq_4_x\n//\n\npackage gozmq\n\nimport (\n\t\"time\"\n)\n\n// This file was generated automatically.  Changes made here will be lost.\n\n// Socket Option Getters\n\n// ZMQ_TYPE: Retrieve socket type.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc3\n//\nfunc (s *Socket) Type() (SocketType, error) {\n\tvalue, err := s.GetSockOptUInt64(TYPE)\n\treturn SocketType(value), err\n}\n\n// ZMQ_RCVMORE: More message data parts to follow.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc4\n//\nfunc (s *Socket) RcvMore() (bool, error) {\n\tvalue, err := s.GetSockOptInt(RCVMORE)\n\treturn value != 0, err\n}\n\n// ZMQ_SNDHWM: Retrieves high water mark for outbound messages.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc5\n//\nfunc (s *Socket) SndHWM() (int, error) {\n\treturn s.GetSockOptInt(SNDHWM)\n}\n\n// ZMQ_RCVHWM: Retrieve high water mark for inbound messages.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc6\n//\nfunc (s *Socket) RcvHWM() (int, error) {\n\treturn s.GetSockOptInt(RCVHWM)\n}\n\n// ZMQ_AFFINITY: Retrieve I/O thread affinity.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc7\n//\nfunc (s *Socket) Affinity() (uint64, error) {\n\treturn s.GetSockOptUInt64(AFFINITY)\n}\n\n// ZMQ_IDENTITY: Retrieve socket identity.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc8\n//\nfunc (s *Socket) Identity() (string, error) {\n\treturn s.GetSockOptString(IDENTITY)\n}\n\n// ZMQ_RATE: Retrieve multicast data rate.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc9\n//\nfunc (s *Socket) Rate() (int64, error) {\n\treturn s.GetSockOptInt64(RATE)\n}\n\n// ZMQ_RECOVERY_IVL: Get multicast recovery interval.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc10\n//\nfunc (s *Socket) RecoveryIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt64(RECOVERY_IVL)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc11\n//\nfunc (s *Socket) SndBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(SNDBUF)\n}\n\n// ZMQ_RCVBUF: Retrieve kernel receive buffer size.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc12\n//\nfunc (s *Socket) RcvBuf() (uint64, error) {\n\treturn s.GetSockOptUInt64(RCVBUF)\n}\n\n// ZMQ_LINGER: Retrieve linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc13\n//\nfunc (s *Socket) Linger() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(LINGER)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc14\n//\nfunc (s *Socket) ReconnectIvl() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc15\n//\nfunc (s *Socket) ReconnectIvlMax() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc16\n//\nfunc (s *Socket) Backlog() (int, error) {\n\treturn s.GetSockOptInt(BACKLOG)\n}\n\n// ZMQ_MAXMSGSIZE: Maximum acceptable inbound message size.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc17\n//\nfunc (s *Socket) MaxMsgSize() (int64, error) {\n\treturn s.GetSockOptInt64(MAXMSGSIZE)\n}\n\n// ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc19\n//\nfunc (s *Socket) RcvTimeout() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(RCVTIMEO)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc20\n//\nfunc (s *Socket) SndTimeout() (time.Duration, error) {\n\tms, err := s.GetSockOptInt(SNDTIMEO)\n\treturn time.Duration(ms) * time.Millisecond, err\n}\n\n// ZMQ_IPV6: Retrieve IPv6 socket status.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc21\n//\nfunc (s *Socket) Ipv6() (bool, error) {\n\tvalue, err := s.GetSockOptInt(IPV6)\n\treturn value != 0, err\n}\n\n// ZMQ_IPV4ONLY: Retrieve IPv4-only socket override status.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc22\n//\nfunc (s *Socket) IPv4Only() (bool, error) {\n\tvalue, err := s.GetSockOptInt(IPV4ONLY)\n\treturn value != 0, err\n}\n\n// ZMQ_IMMEDIATE: Retrieve attach-on-connect value.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc23\n//\nfunc (s *Socket) Immediate() (bool, error) {\n\tvalue, err := s.GetSockOptInt(IMMEDIATE)\n\treturn value != 0, err\n}\n\n// ZMQ_EVENTS: Retrieve socket event state.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc25\n//\nfunc (s *Socket) Events() (uint64, error) {\n\treturn s.GetSockOptUInt64(EVENTS)\n}\n\n// ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc27\n//\nfunc (s *Socket) TCPKeepalive() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE)\n}\n\n// ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc28\n//\nfunc (s *Socket) TCPKeepaliveIdle() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE_IDLE)\n}\n\n// ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc29\n//\nfunc (s *Socket) TCPKeepaliveCnt() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE_CNT)\n}\n\n// ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc30\n//\nfunc (s *Socket) TCPKeepaliveIntvl() (int, error) {\n\treturn s.GetSockOptInt(TCP_KEEPALIVE_INTVL)\n}\n\n// ZMQ_MECHANISM: Retrieve current security mechanism.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc31\n//\nfunc (s *Socket) Mechanism() (int, error) {\n\treturn s.GetSockOptInt(MECHANISM)\n}\n\n// ZMQ_PLAIN_SERVER: Retrieve current PLAIN server role.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc32\n//\nfunc (s *Socket) PlainServer() (int, error) {\n\treturn s.GetSockOptInt(PLAIN_SERVER)\n}\n\n// ZMQ_PLAIN_USERNAME: Retrieve current PLAIN username.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc33\n//\nfunc (s *Socket) PlainUsername() (string, error) {\n\treturn s.GetSockOptString(PLAIN_USERNAME)\n}\n\n// ZMQ_PLAIN_PASSWORD: Retrieve current password.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc34\n//\nfunc (s *Socket) PlainPassword() (string, error) {\n\treturn s.GetSockOptString(PLAIN_PASSWORD)\n}\n\n// ZMQ_CURVE_PUBLICKEY: Retrieve current CURVE public key.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc35\n//\nfunc (s *Socket) CurvePublickey() (string, error) {\n\treturn s.GetSockOptString(CURVE_PUBLICKEY)\n}\n\n// ZMQ_CURVE_SECRETKEY: Retrieve current CURVE secret key.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc36\n//\nfunc (s *Socket) CurveSecretkey() (string, error) {\n\treturn s.GetSockOptString(CURVE_SECRETKEY)\n}\n\n// ZMQ_CURVE_SERVERKEY: Retrieve current CURVE server key.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc37\n//\nfunc (s *Socket) CurveServerkey() (string, error) {\n\treturn s.GetSockOptString(CURVE_SERVERKEY)\n}\n\n// ZMQ_ZAP_DOMAIN: Retrieve RFC 27 authentication domain.\n//\n// See: http://api.zeromq.org/4.0:zmq-getsockopt#toc38\n//\nfunc (s *Socket) ZapDomain() (string, error) {\n\treturn s.GetSockOptString(ZAP_DOMAIN)\n}\n\n// Socket Option Setters\n\n// ZMQ_SNDHWM: Set high water mark for outbound messages.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc3\n//\nfunc (s *Socket) SetSndHWM(value int) error {\n\treturn s.SetSockOptInt(SNDHWM, value)\n}\n\n// ZMQ_RCVHWM: Set high water mark for inbound messages.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc4\n//\nfunc (s *Socket) SetRcvHWM(value int) error {\n\treturn s.SetSockOptInt(RCVHWM, value)\n}\n\n// ZMQ_AFFINITY: Set I/O thread affinity.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc5\n//\nfunc (s *Socket) SetAffinity(value uint64) error {\n\treturn s.SetSockOptUInt64(AFFINITY, value)\n}\n\n// ZMQ_SUBSCRIBE: Establish message filter.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc6\n//\nfunc (s *Socket) SetSubscribe(value string) error {\n\treturn s.SetSockOptString(SUBSCRIBE, value)\n}\n\n// ZMQ_UNSUBSCRIBE: Remove message filter.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc7\n//\nfunc (s *Socket) SetUnsubscribe(value string) error {\n\treturn s.SetSockOptString(UNSUBSCRIBE, value)\n}\n\n// ZMQ_IDENTITY: Set socket identity.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc8\n//\nfunc (s *Socket) SetIdentity(value string) error {\n\treturn s.SetSockOptString(IDENTITY, value)\n}\n\n// ZMQ_RATE: Set multicast data rate.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc9\n//\nfunc (s *Socket) SetRate(value int64) error {\n\treturn s.SetSockOptInt64(RATE, value)\n}\n\n// ZMQ_RECOVERY_IVL: Set multicast recovery interval.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc10\n//\nfunc (s *Socket) SetRecoveryIvl(value time.Duration) error {\n\treturn s.SetSockOptInt64(RECOVERY_IVL, int64(value/time.Millisecond))\n}\n\n// ZMQ_SNDBUF: Set kernel transmit buffer size.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc11\n//\nfunc (s *Socket) SetSndBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(SNDBUF, value)\n}\n\n// ZMQ_RCVBUF: Set kernel receive buffer size.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc12\n//\nfunc (s *Socket) SetRcvBuf(value uint64) error {\n\treturn s.SetSockOptUInt64(RCVBUF, value)\n}\n\n// ZMQ_LINGER: Set linger period for socket shutdown.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc13\n//\nfunc (s *Socket) SetLinger(value time.Duration) error {\n\treturn s.SetSockOptInt(LINGER, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL: Set reconnection interval.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc14\n//\nfunc (s *Socket) SetReconnectIvl(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))\n}\n\n// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc15\n//\nfunc (s *Socket) SetReconnectIvlMax(value time.Duration) error {\n\treturn s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))\n}\n\n// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc16\n//\nfunc (s *Socket) SetBacklog(value int) error {\n\treturn s.SetSockOptInt(BACKLOG, value)\n}\n\n// ZMQ_MAXMSGSIZE: Maximum acceptable inbound message size.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc17\n//\nfunc (s *Socket) SetMaxMsgSize(value int64) error {\n\treturn s.SetSockOptInt64(MAXMSGSIZE, value)\n}\n\n// ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc19\n//\nfunc (s *Socket) SetRcvTimeout(value time.Duration) error {\n\treturn s.SetSockOptInt(RCVTIMEO, int(value/time.Millisecond))\n}\n\n// ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc20\n//\nfunc (s *Socket) SetSndTimeout(value time.Duration) error {\n\treturn s.SetSockOptInt(SNDTIMEO, int(value/time.Millisecond))\n}\n\n// ZMQ_IPV6: Enable IPv6 on socket.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc21\n//\nfunc (s *Socket) SetIpv6(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(IPV6, 1)\n\t}\n\treturn s.SetSockOptInt(IPV6, 0)\n}\n\n// ZMQ_IPV4ONLY: Use IPv4-only on socket.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc22\n//\nfunc (s *Socket) SetIPv4Only(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(IPV4ONLY, 1)\n\t}\n\treturn s.SetSockOptInt(IPV4ONLY, 0)\n}\n\n// ZMQ_IMMEDIATE: Queue messages only to completed connections.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc23\n//\nfunc (s *Socket) SetImmediate(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(IMMEDIATE, 1)\n\t}\n\treturn s.SetSockOptInt(IMMEDIATE, 0)\n}\n\n// ZMQ_ROUTER_MANDATORY: accept only routable messages on ROUTER sockets.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc24\n//\nfunc (s *Socket) SetROUTERMandatory(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(ROUTER_MANDATORY, 1)\n\t}\n\treturn s.SetSockOptInt(ROUTER_MANDATORY, 0)\n}\n\n// ZMQ_ROUTER_RAW: switch ROUTER socket to raw mode.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc25\n//\nfunc (s *Socket) SetROUTERRaw(value int) error {\n\treturn s.SetSockOptInt(ROUTER_RAW, value)\n}\n\n// ZMQ_PROBE_ROUTER: bootstrap connections to ROUTER sockets.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc26\n//\nfunc (s *Socket) SetProbeROUTER(value int) error {\n\treturn s.SetSockOptInt(PROBE_ROUTER, value)\n}\n\n// ZMQ_XPUB_VERBOSE: provide all subscription messages on XPUB sockets.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc27\n//\nfunc (s *Socket) SetXPUBVerbose(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(XPUB_VERBOSE, 1)\n\t}\n\treturn s.SetSockOptInt(XPUB_VERBOSE, 0)\n}\n\n// ZMQ_REQ_CORRELATE: match replies with requests.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc28\n//\nfunc (s *Socket) SetReqCorrelate(value int) error {\n\treturn s.SetSockOptInt(REQ_CORRELATE, value)\n}\n\n// ZMQ_REQ_RELAXED: relax strict alternation between request and reply.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc29\n//\nfunc (s *Socket) SetReqRelaxed(value int) error {\n\treturn s.SetSockOptInt(REQ_RELAXED, value)\n}\n\n// ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc30\n//\nfunc (s *Socket) SetTCPKeepalive(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE, value)\n}\n\n// ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT (or TCP_KEEPALIVE on some OS).\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc31\n//\nfunc (s *Socket) SetTCPKeepaliveIdle(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE_IDLE, value)\n}\n\n// ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc32\n//\nfunc (s *Socket) SetTCPKeepaliveCnt(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE_CNT, value)\n}\n\n// ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc33\n//\nfunc (s *Socket) SetTCPKeepaliveIntvl(value int) error {\n\treturn s.SetSockOptInt(TCP_KEEPALIVE_INTVL, value)\n}\n\n// ZMQ_TCP_ACCEPT_FILTER: Assign filters to allow new TCP connections.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc34\n//\nfunc (s *Socket) SetTCPAcceptFilter(value string) error {\n\treturn s.SetSockOptString(TCP_ACCEPT_FILTER, value)\n}\n\n// ZMQ_PLAIN_SERVER: Set PLAIN server role.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc35\n//\nfunc (s *Socket) SetPlainServer(value int) error {\n\treturn s.SetSockOptInt(PLAIN_SERVER, value)\n}\n\n// ZMQ_PLAIN_USERNAME: Set PLAIN security username.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc36\n//\nfunc (s *Socket) SetPlainUsername(value string) error {\n\treturn s.SetSockOptString(PLAIN_USERNAME, value)\n}\n\n// ZMQ_PLAIN_PASSWORD: Set PLAIN security password.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc37\n//\nfunc (s *Socket) SetPlainPassword(value string) error {\n\treturn s.SetSockOptString(PLAIN_PASSWORD, value)\n}\n\n// ZMQ_CURVE_SERVER: Set CURVE server role.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc38\n//\nfunc (s *Socket) SetCurveServer(value int) error {\n\treturn s.SetSockOptInt(CURVE_SERVER, value)\n}\n\n// ZMQ_CURVE_PUBLICKEY: Set CURVE public key.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc39\n//\nfunc (s *Socket) SetCurvePublickey(value string) error {\n\treturn s.SetSockOptString(CURVE_PUBLICKEY, value)\n}\n\n// ZMQ_CURVE_SECRETKEY: Set CURVE secret key.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc40\n//\nfunc (s *Socket) SetCurveSecretkey(value string) error {\n\treturn s.SetSockOptString(CURVE_SECRETKEY, value)\n}\n\n// ZMQ_CURVE_SERVERKEY: Set CURVE server key.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc41\n//\nfunc (s *Socket) SetCurveServerkey(value string) error {\n\treturn s.SetSockOptString(CURVE_SERVERKEY, value)\n}\n\n// ZMQ_ZAP_DOMAIN: Set RFC 27 authentication domain.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc42\n//\nfunc (s *Socket) SetZapDomain(value string) error {\n\treturn s.SetSockOptString(ZAP_DOMAIN, value)\n}\n\n// ZMQ_CONFLATE: Keep only last message.\n//\n// See: http://api.zeromq.org/4.0:zmq-setsockopt#toc43\n//\nfunc (s *Socket) SetConflate(value bool) error {\n\tif value {\n\t\treturn s.SetSockOptInt(CONFLATE, 1)\n\t}\n\treturn s.SetSockOptInt(CONFLATE, 0)\n}\n"
  }
]