/README.md
Markdown | 1024 lines | 711 code | 313 blank | 0 comment | 0 complexity | 82597b58500a8b84e1c4ad8a646efda7 MD5 | raw file
1# _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). 2 3## Go (golang) Bindings for 0mq (zmq, zeromq) 4 5[](https://travis-ci.org/alecthomas/gozmq) 6 7This package implements [Go](http://golang.org) (golang) bindings for 8the [0mq](http://zeromq.org) C API. 9 10GoZMQ [does not](#zero-copy) support zero-copy. 11 12A full list of examples is included in the [zguide](https://github.com/imatix/zguide/tree/master/examples/Go). 13 14Note that this is *not* the same as [this 15implementation](http://github.com/boggle/gozero) or [this 16implementation](http://code.google.com/p/gozmq/). 17 18## Upgrading 19 20GoZMQ 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): 21 22 go get github.com/alecthomas/gozmq/gozmqfix 23 cd $YOUR_SOURCE_DIR 24 gozmqfix . 25 26## Installing 27 28GoZMQ currently supports ZMQ 2.1.x, 2.2.x, 3.x and 4.x. Following are instructions on how to compile against these versions. 29 30For ZeroMQ 2.2.x install with: 31 32 go get github.com/alecthomas/gozmq 33 34For 2.1.x install with: 35 36 go get -tags zmq_2_1 github.com/alecthomas/gozmq 37 38For 3.x install with: 39 40 go get -tags zmq_3_x github.com/alecthomas/gozmq 41 42For 4.x install with: 43 44 go get -tags zmq_4_x github.com/alecthomas/gozmq 45 46### Troubleshooting 47 48#### Go can't find ZMQ 49 50If the go tool can't find zmq and you know it is installed, you may need to override the C compiler/linker flags. 51 52eg. If you installed zmq into `/opt/zmq` you might try: 53 54 CGO_CFLAGS=-I/opt/zmq/include CGO_LDFLAGS=-L/opt/zmq/lib \ 55 go get github.com/alecthomas/gozmq 56 57#### Mismatch in version of ZMQ 58 59If you get errors like this with 'go get' or 'go build': 60 61 1: error: 'ZMQ_FOO' undeclared (first use in this function) 62 63There are two possibilities: 64 651. Your version of zmq is *very* old. In this case you will need to download and build zmq yourself. 662. You are building gozmq against the wrong version of zmq. See the [installation](#installation) instructions for details on how to target the correct version. 67 68## Differences from the C API 69 70The API implemented by this package does not attempt to expose 71`zmq_msg_t` at all. Instead, `Recv()` and `Send()` both operate on byte 72slices, allocating and freeing the memory automatically. Currently this 73requires copying to/from C malloced memory, but a future implementation 74may be able to avoid this to a certain extent. 75 76All major features are supported: contexts, sockets, devices, and polls. 77 78## Example 79 80Here are direct translations of some of the examples from [this blog 81post](http://nichol.as/zeromq-an-introduction). 82 83A simple echo server: 84 85```go 86package main 87 88import zmq "github.com/alecthomas/gozmq" 89 90func main() { 91 context, _ := zmq.NewContext() 92 socket, _ := context.NewSocket(zmq.REP) 93 socket.Bind("tcp://127.0.0.1:5000") 94 socket.Bind("tcp://127.0.0.1:6000") 95 96 for { 97 msg, _ := socket.Recv(0) 98 println("Got", string(msg)) 99 socket.Send(msg, 0) 100 } 101} 102``` 103 104A simple client for the above server: 105 106```go 107package main 108 109import "fmt" 110import zmq "github.com/alecthomas/gozmq" 111 112func main() { 113 context, _ := zmq.NewContext() 114 socket, _ := context.NewSocket(zmq.REQ) 115 socket.Connect("tcp://127.0.0.1:5000") 116 socket.Connect("tcp://127.0.0.1:6000") 117 118 for i := 0; i < 10; i++ { 119 msg := fmt.Sprintf("msg %d", i) 120 socket.Send([]byte(msg), 0) 121 println("Sending", msg) 122 socket.Recv(0) 123 } 124} 125``` 126 127## Caveats 128 129### Zero-copy 130 131GoZMQ does not support zero-copy. 132 133GoZMQ does not attempt to expose `zmq_msg_t` at all. Instead, `Recv()` and `Send()` 134both operate on byte slices, allocating and freeing the memory automatically. 135Currently this requires copying to/from C malloced memory, but a future 136implementation may be able to avoid this to a certain extent. 137 138 139### Memory management 140 141It's not entirely clear from the 0mq documentation how memory for 142`zmq_msg_t` and packet data is managed once 0mq takes ownership. After 143digging into the source a little, this package operates under the 144following (educated) assumptions: 145 146- References to `zmq_msg_t` structures are not held by the C API 147 beyond the duration of any function call. 148- Packet data is reference counted internally by the C API. The count 149 is incremented when a packet is queued for delivery to a destination 150 (the inference being that for delivery to N destinations, the 151 reference count will be incremented N times) and decremented once 152 the packet has either been delivered or errored. 153 154## Usage 155 156```go 157const ( 158 // NewSocket types 159 PAIR = SocketType(C.ZMQ_PAIR) 160 PUB = SocketType(C.ZMQ_PUB) 161 SUB = SocketType(C.ZMQ_SUB) 162 REQ = SocketType(C.ZMQ_REQ) 163 REP = SocketType(C.ZMQ_REP) 164 DEALER = SocketType(C.ZMQ_DEALER) 165 ROUTER = SocketType(C.ZMQ_ROUTER) 166 PULL = SocketType(C.ZMQ_PULL) 167 PUSH = SocketType(C.ZMQ_PUSH) 168 XPUB = SocketType(C.ZMQ_XPUB) 169 XSUB = SocketType(C.ZMQ_XSUB) 170 171 // Deprecated aliases 172 XREQ = DEALER 173 XREP = ROUTER 174 UPSTREAM = PULL 175 DOWNSTREAM = PUSH 176 177 // NewSocket options 178 AFFINITY = UInt64SocketOption(C.ZMQ_AFFINITY) 179 IDENTITY = StringSocketOption(C.ZMQ_IDENTITY) 180 SUBSCRIBE = StringSocketOption(C.ZMQ_SUBSCRIBE) 181 UNSUBSCRIBE = StringSocketOption(C.ZMQ_UNSUBSCRIBE) 182 RATE = Int64SocketOption(C.ZMQ_RATE) 183 RECOVERY_IVL = Int64SocketOption(C.ZMQ_RECOVERY_IVL) 184 SNDBUF = UInt64SocketOption(C.ZMQ_SNDBUF) 185 RCVBUF = UInt64SocketOption(C.ZMQ_RCVBUF) 186 FD = Int64SocketOption(C.ZMQ_FD) 187 EVENTS = UInt64SocketOption(C.ZMQ_EVENTS) 188 TYPE = UInt64SocketOption(C.ZMQ_TYPE) 189 LINGER = IntSocketOption(C.ZMQ_LINGER) 190 RECONNECT_IVL = IntSocketOption(C.ZMQ_RECONNECT_IVL) 191 RECONNECT_IVL_MAX = IntSocketOption(C.ZMQ_RECONNECT_IVL_MAX) 192 BACKLOG = IntSocketOption(C.ZMQ_BACKLOG) 193 194 // Send/recv options 195 SNDMORE = SendRecvOption(C.ZMQ_SNDMORE) 196) 197``` 198 199```go 200const ( 201 POLLIN = PollEvents(C.ZMQ_POLLIN) 202 POLLOUT = PollEvents(C.ZMQ_POLLOUT) 203 POLLERR = PollEvents(C.ZMQ_POLLERR) 204) 205``` 206 207```go 208const ( 209 STREAMER = DeviceType(C.ZMQ_STREAMER) 210 FORWARDER = DeviceType(C.ZMQ_FORWARDER) 211 QUEUE = DeviceType(C.ZMQ_QUEUE) 212) 213``` 214 215```go 216const ( 217 RCVTIMEO = IntSocketOption(C.ZMQ_RCVTIMEO) 218 SNDTIMEO = IntSocketOption(C.ZMQ_SNDTIMEO) 219) 220``` 221 222```go 223const ( 224 RCVMORE = UInt64SocketOption(C.ZMQ_RCVMORE) 225 RECOVERY_IVL_MSEC = Int64SocketOption(C.ZMQ_RECOVERY_IVL_MSEC) 226 SWAP = Int64SocketOption(C.ZMQ_SWAP) 227 MCAST_LOOP = Int64SocketOption(C.ZMQ_MCAST_LOOP) 228 HWM = UInt64SocketOption(C.ZMQ_HWM) 229 NOBLOCK = SendRecvOption(C.ZMQ_NOBLOCK) 230 231 // Forwards-compatible aliases: 232 DONTWAIT = NOBLOCK 233) 234``` 235 236```go 237const ( 238 RCVMORE = IntSocketOption(C.ZMQ_RCVMORE) 239 SNDHWM = IntSocketOption(C.ZMQ_SNDHWM) 240 RCVHWM = IntSocketOption(C.ZMQ_RCVHWM) 241 242 // TODO Not documented in the man page... 243 //LAST_ENDPOINT = UInt64SocketOption(C.ZMQ_LAST_ENDPOINT) 244 FAIL_UNROUTABLE = BoolSocketOption(C.ZMQ_FAIL_UNROUTABLE) 245 TCP_KEEPALIVE = IntSocketOption(C.ZMQ_TCP_KEEPALIVE) 246 TCP_KEEPALIVE_CNT = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_CNT) 247 TCP_KEEPALIVE_IDLE = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_IDLE) 248 TCP_KEEPALIVE_INTVL = IntSocketOption(C.ZMQ_TCP_KEEPALIVE_INTVL) 249 TCP_ACCEPT_FILTER = StringSocketOption(C.ZMQ_TCP_ACCEPT_FILTER) 250 251 // Message options 252 MORE = MessageOption(C.ZMQ_MORE) 253 254 // Send/recv options 255 DONTWAIT = SendRecvOption(C.ZMQ_DONTWAIT) 256 257 // Deprecated aliases 258 NOBLOCK = DONTWAIT 259) 260``` 261 262```go 263var ( 264 // Additional ZMQ errors 265 ENOTSOCK error = zmqErrno(C.ENOTSOCK) 266 EFSM error = zmqErrno(C.EFSM) 267 EINVAL error = zmqErrno(C.EINVAL) 268 ENOCOMPATPROTO error = zmqErrno(C.ENOCOMPATPROTO) 269 ETERM error = zmqErrno(C.ETERM) 270 EMTHREAD error = zmqErrno(C.EMTHREAD) 271) 272``` 273 274#### func Device 275 276```go 277func Device(t DeviceType, in, out *Socket) error 278``` 279run a zmq_device passing messages between in and out 280 281#### func Poll 282 283```go 284func Poll(items []PollItem, timeout time.Duration) (count int, err error) 285``` 286Poll ZmqSockets and file descriptors for I/O readiness. Timeout is in 287time.Duration. The smallest possible timeout is time.Millisecond for ZeroMQ 288version 3 and above, and time.Microsecond for earlier versions. 289 290#### func Proxy 291 292```go 293func Proxy(in, out, capture *Socket) error 294``` 295run a zmq_proxy with in, out and capture sockets 296 297#### func Version 298 299```go 300func Version() (int, int, int) 301``` 302void zmq_version (int *major, int *minor, int *patch); 303 304#### type BoolSocketOption 305 306```go 307type BoolSocketOption int 308``` 309 310 311#### type Context 312 313```go 314type Context struct { 315} 316``` 317 318* A context handles socket creation and asynchronous message delivery. * There 319should generally be one context per application. 320 321#### func NewContext 322 323```go 324func NewContext() (*Context, error) 325``` 326Create a new context. 327 328#### func (*Context) Close 329 330```go 331func (c *Context) Close() 332``` 333 334#### func (*Context) IOThreads 335 336```go 337func (c *Context) IOThreads() (int, error) 338``` 339Get a context option. 340 341#### func (*Context) MaxSockets 342 343```go 344func (c *Context) MaxSockets() (int, error) 345``` 346 347#### func (*Context) NewSocket 348 349```go 350func (c *Context) NewSocket(t SocketType) (*Socket, error) 351``` 352Create a new socket. void *zmq_socket (void *context, int type); 353 354#### func (*Context) SetIOThreads 355 356```go 357func (c *Context) SetIOThreads(value int) error 358``` 359Set a context option. 360 361#### func (*Context) SetMaxSockets 362 363```go 364func (c *Context) SetMaxSockets(value int) error 365``` 366 367#### type DeviceType 368 369```go 370type DeviceType int 371``` 372 373 374#### type Int64SocketOption 375 376```go 377type Int64SocketOption int 378``` 379 380 381#### type IntSocketOption 382 383```go 384type IntSocketOption int 385``` 386 387 388#### type MessageOption 389 390```go 391type MessageOption int 392``` 393 394 395#### type PollEvents 396 397```go 398type PollEvents C.short 399``` 400 401 402#### type PollItem 403 404```go 405type PollItem struct { 406 Socket *Socket // socket to poll for events on 407 Fd ZmqOsSocketType // fd to poll for events on as returned from os.File.Fd() 408 Events PollEvents // event set to poll for 409 REvents PollEvents // events that were present 410} 411``` 412 413Item to poll for read/write events on, either a *Socket or a file descriptor 414 415#### type PollItems 416 417```go 418type PollItems []PollItem 419``` 420 421a set of items to poll for events on 422 423#### type SendRecvOption 424 425```go 426type SendRecvOption int 427``` 428 429 430#### type Socket 431 432```go 433type Socket struct { 434} 435``` 436 437 438#### func (*Socket) Affinity 439 440```go 441func (s *Socket) Affinity() (uint64, error) 442``` 443ZMQ_AFFINITY: Retrieve I/O thread affinity. 444 445See: http://api.zeromq.org/2.1:zmq-getsockopt#toc7 446 447#### func (*Socket) Backlog 448 449```go 450func (s *Socket) Backlog() (int, error) 451``` 452ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections. 453 454See: http://api.zeromq.org/2.1:zmq-getsockopt#toc18 455 456#### func (*Socket) Bind 457 458```go 459func (s *Socket) Bind(address string) error 460``` 461Bind the socket to a listening address. int zmq_bind (void *s, const char 462*addr); 463 464#### func (*Socket) Close 465 466```go 467func (s *Socket) Close() error 468``` 469Shutdown the socket. int zmq_close (void *s); 470 471#### func (*Socket) Connect 472 473```go 474func (s *Socket) Connect(address string) error 475``` 476Connect the socket to an address. int zmq_connect (void *s, const char *addr); 477 478#### func (*Socket) Events 479 480```go 481func (s *Socket) Events() (uint64, error) 482``` 483ZMQ_EVENTS: Retrieve socket event state. 484 485See: http://api.zeromq.org/2.1:zmq-getsockopt#toc20 486 487#### func (*Socket) GetSockOptBool 488 489```go 490func (s *Socket) GetSockOptBool(option BoolSocketOption) (value bool, err error) 491``` 492 493#### func (*Socket) GetSockOptInt 494 495```go 496func (s *Socket) GetSockOptInt(option IntSocketOption) (value int, err error) 497``` 498Get an int option from the socket. int zmq_getsockopt (void *s, int option, void 499*optval, size_t *optvallen); 500 501#### func (*Socket) GetSockOptInt64 502 503```go 504func (s *Socket) GetSockOptInt64(option Int64SocketOption) (value int64, err error) 505``` 506Get an int64 option from the socket. int zmq_getsockopt (void *s, int option, 507void *optval, size_t *optvallen); 508 509#### func (*Socket) GetSockOptString 510 511```go 512func (s *Socket) GetSockOptString(option StringSocketOption) (value string, err error) 513``` 514Get a string option from the socket. int zmq_getsockopt (void *s, int option, 515void *optval, size_t *optvallen); 516 517#### func (*Socket) GetSockOptUInt64 518 519```go 520func (s *Socket) GetSockOptUInt64(option UInt64SocketOption) (value uint64, err error) 521``` 522Get a uint64 option from the socket. int zmq_getsockopt (void *s, int option, 523void *optval, size_t *optvallen); 524 525#### func (*Socket) HWM 526 527```go 528func (s *Socket) HWM() (uint64, error) 529``` 530ZMQ_HWM: Retrieve high water mark. 531 532See: http://api.zeromq.org/2.1:zmq-getsockopt#toc5 533 534#### func (*Socket) Identity 535 536```go 537func (s *Socket) Identity() (string, error) 538``` 539ZMQ_IDENTITY: Retrieve socket identity. 540 541See: http://api.zeromq.org/2.1:zmq-getsockopt#toc8 542 543#### func (*Socket) Linger 544 545```go 546func (s *Socket) Linger() (time.Duration, error) 547``` 548ZMQ_LINGER: Retrieve linger period for socket shutdown. 549 550See: http://api.zeromq.org/2.1:zmq-getsockopt#toc15 551 552#### func (*Socket) McastLoop 553 554```go 555func (s *Socket) McastLoop() (bool, error) 556``` 557ZMQ_MCAST_LOOP: Control multicast loop-back. 558 559See: http://api.zeromq.org/2.1:zmq-getsockopt#toc12 560 561#### func (*Socket) Rate 562 563```go 564func (s *Socket) Rate() (int64, error) 565``` 566ZMQ_RATE: Retrieve multicast data rate. 567 568See: http://api.zeromq.org/2.1:zmq-getsockopt#toc9 569 570#### func (*Socket) RcvBuf 571 572```go 573func (s *Socket) RcvBuf() (uint64, error) 574``` 575ZMQ_RCVBUF: Retrieve kernel receive buffer size. 576 577See: http://api.zeromq.org/2.1:zmq-getsockopt#toc14 578 579#### func (*Socket) RcvHWM 580 581```go 582func (s *Socket) RcvHWM() (int, error) 583``` 584ZMQ_RCVHWM: Retrieve high water mark for inbound messages. 585 586See: http://api.zeromq.org/3.2:zmq-getsockopt#toc6 587 588#### func (*Socket) RcvMore 589 590```go 591func (s *Socket) RcvMore() (bool, error) 592``` 593ZMQ_RCVMORE: More message parts to follow. 594 595See: http://api.zeromq.org/2.1:zmq-getsockopt#toc4 596 597#### func (*Socket) RcvTimeout 598 599```go 600func (s *Socket) RcvTimeout() (time.Duration, error) 601``` 602ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN. 603 604See: http://api.zeromq.org/2.2:zmq-getsockopt#toc6 605 606#### func (*Socket) ReconnectIvl 607 608```go 609func (s *Socket) ReconnectIvl() (time.Duration, error) 610``` 611ZMQ_RECONNECT_IVL: Retrieve reconnection interval. 612 613See: http://api.zeromq.org/2.1:zmq-getsockopt#toc16 614 615#### func (*Socket) ReconnectIvlMax 616 617```go 618func (s *Socket) ReconnectIvlMax() (time.Duration, error) 619``` 620ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval. 621 622See: http://api.zeromq.org/2.1:zmq-getsockopt#toc17 623 624#### func (*Socket) RecoveryIvl 625 626```go 627func (s *Socket) RecoveryIvl() (time.Duration, error) 628``` 629ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds. 630 631See: http://api.zeromq.org/2.1:zmq-getsockopt#toc11 632 633#### func (*Socket) Recv 634 635```go 636func (s *Socket) Recv(flags SendRecvOption) (data []byte, err error) 637``` 638Receive a message from the socket. int zmq_recv (void *s, zmq_msg_t *msg, int 639flags); 640 641#### func (*Socket) RecvMultipart 642 643```go 644func (s *Socket) RecvMultipart(flags SendRecvOption) (parts [][]byte, err error) 645``` 646Receive a multipart message. 647 648#### func (*Socket) Send 649 650```go 651func (s *Socket) Send(data []byte, flags SendRecvOption) error 652``` 653Send a message to the socket. int zmq_send (void *s, zmq_msg_t *msg, int flags); 654 655#### func (*Socket) SendMultipart 656 657```go 658func (s *Socket) SendMultipart(parts [][]byte, flags SendRecvOption) (err error) 659``` 660Send a multipart message. 661 662#### func (*Socket) SetAffinity 663 664```go 665func (s *Socket) SetAffinity(value uint64) error 666``` 667ZMQ_AFFINITY: Set I/O thread affinity. 668 669See: http://api.zeromq.org/2.1:zmq-setsockopt#toc5 670 671#### func (*Socket) SetBacklog 672 673```go 674func (s *Socket) SetBacklog(value int) error 675``` 676ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections. 677 678See: http://api.zeromq.org/2.1:zmq-setsockopt#toc18 679 680#### func (*Socket) SetHWM 681 682```go 683func (s *Socket) SetHWM(value uint64) error 684``` 685ZMQ_HWM: Set high water mark. 686 687See: http://api.zeromq.org/2.1:zmq-setsockopt#toc3 688 689#### func (*Socket) SetIdentity 690 691```go 692func (s *Socket) SetIdentity(value string) error 693``` 694ZMQ_IDENTITY: Set socket identity. 695 696See: http://api.zeromq.org/2.1:zmq-setsockopt#toc6 697 698#### func (*Socket) SetLinger 699 700```go 701func (s *Socket) SetLinger(value time.Duration) error 702``` 703ZMQ_LINGER: Set linger period for socket shutdown. 704 705See: http://api.zeromq.org/2.1:zmq-setsockopt#toc15 706 707#### func (*Socket) SetMcastLoop 708 709```go 710func (s *Socket) SetMcastLoop(value bool) error 711``` 712ZMQ_MCAST_LOOP: Control multicast loop-back. 713 714See: http://api.zeromq.org/2.1:zmq-setsockopt#toc12 715 716#### func (*Socket) SetRate 717 718```go 719func (s *Socket) SetRate(value int64) error 720``` 721ZMQ_RATE: Set multicast data rate. 722 723See: http://api.zeromq.org/2.1:zmq-setsockopt#toc9 724 725#### func (*Socket) SetRcvBuf 726 727```go 728func (s *Socket) SetRcvBuf(value uint64) error 729``` 730ZMQ_RCVBUF: Set kernel receive buffer size. 731 732See: http://api.zeromq.org/2.1:zmq-setsockopt#toc14 733 734#### func (*Socket) SetRcvHWM 735 736```go 737func (s *Socket) SetRcvHWM(value int) error 738``` 739ZMQ_RCVHWM: Set high water mark for inbound messages. 740 741See: http://api.zeromq.org/3.2:zmq-setsockopt#toc4 742 743#### func (*Socket) SetRcvTimeout 744 745```go 746func (s *Socket) SetRcvTimeout(value time.Duration) error 747``` 748ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN. 749 750See: http://api.zeromq.org/2.2:zmq-setsockopt#toc9 751 752#### func (*Socket) SetReconnectIvl 753 754```go 755func (s *Socket) SetReconnectIvl(value time.Duration) error 756``` 757ZMQ_RECONNECT_IVL: Set reconnection interval. 758 759See: http://api.zeromq.org/2.1:zmq-setsockopt#toc16 760 761#### func (*Socket) SetReconnectIvlMax 762 763```go 764func (s *Socket) SetReconnectIvlMax(value time.Duration) error 765``` 766ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval. 767 768See: http://api.zeromq.org/2.1:zmq-setsockopt#toc17 769 770#### func (*Socket) SetRecoveryIvl 771 772```go 773func (s *Socket) SetRecoveryIvl(value time.Duration) error 774``` 775ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds. 776 777See: http://api.zeromq.org/2.1:zmq-setsockopt#toc11 778 779#### func (*Socket) SetSndBuf 780 781```go 782func (s *Socket) SetSndBuf(value uint64) error 783``` 784ZMQ_SNDBUF: Set kernel transmit buffer size. 785 786See: http://api.zeromq.org/2.1:zmq-setsockopt#toc13 787 788#### func (*Socket) SetSndHWM 789 790```go 791func (s *Socket) SetSndHWM(value int) error 792``` 793ZMQ_SNDHWM: Set high water mark for outbound messages. 794 795See: http://api.zeromq.org/3.2:zmq-setsockopt#toc3 796 797#### func (*Socket) SetSndTimeout 798 799```go 800func (s *Socket) SetSndTimeout(value time.Duration) error 801``` 802ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN. 803 804See: http://api.zeromq.org/2.2:zmq-setsockopt#toc10 805 806#### func (*Socket) SetSockOptInt 807 808```go 809func (s *Socket) SetSockOptInt(option IntSocketOption, value int) error 810``` 811Set an int option on the socket. int zmq_setsockopt (void *s, int option, const 812void *optval, size_t optvallen); 813 814#### func (*Socket) SetSockOptInt64 815 816```go 817func (s *Socket) SetSockOptInt64(option Int64SocketOption, value int64) error 818``` 819Set an int64 option on the socket. int zmq_setsockopt (void *s, int option, 820const void *optval, size_t optvallen); 821 822#### func (*Socket) SetSockOptString 823 824```go 825func (s *Socket) SetSockOptString(option StringSocketOption, value string) error 826``` 827Set a string option on the socket. int zmq_setsockopt (void *s, int option, 828const void *optval, size_t optvallen); 829 830#### func (*Socket) SetSockOptStringNil 831 832```go 833func (s *Socket) SetSockOptStringNil(option StringSocketOption) error 834``` 835Set a string option on the socket to nil. int zmq_setsockopt (void *s, int 836option, const void *optval, size_t optvallen); 837 838#### func (*Socket) SetSockOptUInt64 839 840```go 841func (s *Socket) SetSockOptUInt64(option UInt64SocketOption, value uint64) error 842``` 843Set a uint64 option on the socket. int zmq_setsockopt (void *s, int option, 844const void *optval, size_t optvallen); 845 846#### func (*Socket) SetSubscribe 847 848```go 849func (s *Socket) SetSubscribe(value string) error 850``` 851ZMQ_SUBSCRIBE: Establish message filter. 852 853See: http://api.zeromq.org/2.1:zmq-setsockopt#toc7 854 855#### func (*Socket) SetSwap 856 857```go 858func (s *Socket) SetSwap(value int64) error 859``` 860ZMQ_SWAP: Set disk offload size. 861 862See: http://api.zeromq.org/2.1:zmq-setsockopt#toc4 863 864#### func (*Socket) SetTCPKeepalive 865 866```go 867func (s *Socket) SetTCPKeepalive(value int) error 868``` 869ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option. 870 871See: http://api.zeromq.org/3.2:zmq-setsockopt#toc25 872 873#### func (*Socket) SetTCPKeepaliveCnt 874 875```go 876func (s *Socket) SetTCPKeepaliveCnt(value int) error 877``` 878ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option. 879 880See: http://api.zeromq.org/3.2:zmq-setsockopt#toc27 881 882#### func (*Socket) SetTCPKeepaliveIdle 883 884```go 885func (s *Socket) SetTCPKeepaliveIdle(value int) error 886``` 887ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS). 888 889See: http://api.zeromq.org/3.2:zmq-setsockopt#toc26 890 891#### func (*Socket) SetTCPKeepaliveIntvl 892 893```go 894func (s *Socket) SetTCPKeepaliveIntvl(value int) error 895``` 896ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option. 897 898See: http://api.zeromq.org/3.2:zmq-setsockopt#toc28 899 900#### func (*Socket) SetUnsubscribe 901 902```go 903func (s *Socket) SetUnsubscribe(value string) error 904``` 905ZMQ_UNSUBSCRIBE: Remove message filter. 906 907See: http://api.zeromq.org/2.1:zmq-setsockopt#toc8 908 909#### func (*Socket) SndBuf 910 911```go 912func (s *Socket) SndBuf() (uint64, error) 913``` 914ZMQ_SNDBUF: Retrieve kernel transmit buffer size. 915 916See: http://api.zeromq.org/2.1:zmq-getsockopt#toc13 917 918#### func (*Socket) SndHWM 919 920```go 921func (s *Socket) SndHWM() (int, error) 922``` 923ZMQ_SNDHWM: Retrieves high water mark for outbound messages. 924 925See: http://api.zeromq.org/3.2:zmq-getsockopt#toc5 926 927#### func (*Socket) SndTimeout 928 929```go 930func (s *Socket) SndTimeout() (time.Duration, error) 931``` 932ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN. 933 934See: http://api.zeromq.org/2.2:zmq-getsockopt#toc7 935 936#### func (*Socket) Swap 937 938```go 939func (s *Socket) Swap() (int64, error) 940``` 941ZMQ_SWAP: Retrieve disk offload size. 942 943See: http://api.zeromq.org/2.1:zmq-getsockopt#toc6 944 945#### func (*Socket) TCPKeepalive 946 947```go 948func (s *Socket) TCPKeepalive() (int, error) 949``` 950ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option. 951 952See: http://api.zeromq.org/3.2:zmq-getsockopt#toc26 953 954#### func (*Socket) TCPKeepaliveCnt 955 956```go 957func (s *Socket) TCPKeepaliveCnt() (int, error) 958``` 959ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option. 960 961See: http://api.zeromq.org/3.2:zmq-getsockopt#toc28 962 963#### func (*Socket) TCPKeepaliveIdle 964 965```go 966func (s *Socket) TCPKeepaliveIdle() (int, error) 967``` 968ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS). 969 970See: http://api.zeromq.org/3.2:zmq-getsockopt#toc27 971 972#### func (*Socket) TCPKeepaliveIntvl 973 974```go 975func (s *Socket) TCPKeepaliveIntvl() (int, error) 976``` 977ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option. 978 979See: http://api.zeromq.org/3.2:zmq-getsockopt#toc29 980 981#### func (*Socket) Type 982 983```go 984func (s *Socket) Type() (SocketType, error) 985``` 986ZMQ_TYPE: Retrieve socket type. 987 988See: http://api.zeromq.org/2.1:zmq-getsockopt#toc3 989 990#### type SocketType 991 992```go 993type SocketType int 994``` 995 996 997#### type StringSocketOption 998 999```go 1000type StringSocketOption int 1001``` 1002 1003 1004#### type UInt64SocketOption 1005 1006```go 1007type UInt64SocketOption int 1008``` 1009 1010 1011#### type ZmqOsSocketType 1012 1013```go 1014type ZmqOsSocketType C.SOCKET 1015``` 1016 1017 1018#### func (ZmqOsSocketType) ToRaw 1019 1020```go 1021func (self ZmqOsSocketType) ToRaw() C.SOCKET 1022``` 1023 1024*(generated from .[godocdown](https://github.com/robertkrimen/godocdown).md with `godocdown github.com/alecthomas/gozmq > README.md`)*