Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use code generation for socket option methods.

Future commits that changes files under ./gozmqgen should include any
consequent changes in the zmqgen_*.go files.
  • Loading branch information...
commit 24093b4014ca12d0fcd8db1cb0d60f82ca5c40dd 1 parent 67d0eb0
@jtacoma jtacoma authored
View
3  .gitignore
@@ -11,4 +11,5 @@ _cgo_export.*
_obj
_test
_testmain.go
-*.exe
+*.exe
+.cache
View
423 README.md
@@ -433,6 +433,24 @@ type Socket struct {
```
+#### func (*Socket) Affinity
+
+```go
+func (s *Socket) Affinity() (uint64, error)
+```
+ZMQ_AFFINITY: Retrieve I/O thread affinity.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc7
+
+#### func (*Socket) Backlog
+
+```go
+func (s *Socket) Backlog() (int, error)
+```
+ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc18
+
#### func (*Socket) Bind
```go
@@ -455,6 +473,15 @@ func (s *Socket) Connect(address string) error
```
Connect the socket to an address. int zmq_connect (void *s, const char *addr);
+#### func (*Socket) Events
+
+```go
+func (s *Socket) Events() (uint64, error)
+```
+ZMQ_EVENTS: Retrieve socket event state.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc20
+
#### func (*Socket) GetSockOptBool
```go
@@ -493,6 +520,114 @@ func (s *Socket) GetSockOptUInt64(option UInt64SocketOption) (value uint64, err
Get a uint64 option from the socket. int zmq_getsockopt (void *s, int option,
void *optval, size_t *optvallen);
+#### func (*Socket) HWM
+
+```go
+func (s *Socket) HWM() (uint64, error)
+```
+ZMQ_HWM: Retrieve high water mark.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc5
+
+#### func (*Socket) Identity
+
+```go
+func (s *Socket) Identity() (string, error)
+```
+ZMQ_IDENTITY: Retrieve socket identity.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc8
+
+#### func (*Socket) Linger
+
+```go
+func (s *Socket) Linger() (time.Duration, error)
+```
+ZMQ_LINGER: Retrieve linger period for socket shutdown.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc15
+
+#### func (*Socket) McastLoop
+
+```go
+func (s *Socket) McastLoop() (bool, error)
+```
+ZMQ_MCAST_LOOP: Control multicast loop-back.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc12
+
+#### func (*Socket) Rate
+
+```go
+func (s *Socket) Rate() (int64, error)
+```
+ZMQ_RATE: Retrieve multicast data rate.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc9
+
+#### func (*Socket) RcvHWM
+
+```go
+func (s *Socket) RcvHWM() (int, error)
+```
+ZMQ_RCVHWM: Retrieve high water mark for inbound messages.
+
+See: http://api.zeromq.org/3.2:zmq-getsockopt#toc6
+
+#### func (*Socket) RcvMore
+
+```go
+func (s *Socket) RcvMore() (bool, error)
+```
+ZMQ_RCVMORE: More message parts to follow.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc4
+
+#### func (*Socket) RcvTimeout
+
+```go
+func (s *Socket) RcvTimeout() (time.Duration, error)
+```
+ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.
+
+See: http://api.zeromq.org/2.2:zmq-getsockopt#toc6
+
+#### func (*Socket) Rcvbuf
+
+```go
+func (s *Socket) Rcvbuf() (uint64, error)
+```
+ZMQ_RCVBUF: Retrieve kernel receive buffer size.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc14
+
+#### func (*Socket) ReconnectIvl
+
+```go
+func (s *Socket) ReconnectIvl() (time.Duration, error)
+```
+ZMQ_RECONNECT_IVL: Retrieve reconnection interval.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc16
+
+#### func (*Socket) ReconnectIvlMax
+
+```go
+func (s *Socket) ReconnectIvlMax() (time.Duration, error)
+```
+ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc17
+
+#### func (*Socket) RecoveryIvl
+
+```go
+func (s *Socket) RecoveryIvl() (time.Duration, error)
+```
+ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc11
+
#### func (*Socket) Recv
```go
@@ -522,6 +657,150 @@ func (s *Socket) SendMultipart(parts [][]byte, flags SendRecvOption) (err error)
```
Send a multipart message.
+#### func (*Socket) SetAffinity
+
+```go
+func (s *Socket) SetAffinity(value uint64) error
+```
+ZMQ_AFFINITY: Set I/O thread affinity.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc5
+
+#### func (*Socket) SetBacklog
+
+```go
+func (s *Socket) SetBacklog(value int) error
+```
+ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc18
+
+#### func (*Socket) SetHWM
+
+```go
+func (s *Socket) SetHWM(value uint64) error
+```
+ZMQ_HWM: Set high water mark.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc3
+
+#### func (*Socket) SetIdentity
+
+```go
+func (s *Socket) SetIdentity(value string) error
+```
+ZMQ_IDENTITY: Set socket identity.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc6
+
+#### func (*Socket) SetLinger
+
+```go
+func (s *Socket) SetLinger(value time.Duration) error
+```
+ZMQ_LINGER: Set linger period for socket shutdown.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc15
+
+#### func (*Socket) SetMcastLoop
+
+```go
+func (s *Socket) SetMcastLoop(value bool) error
+```
+ZMQ_MCAST_LOOP: Control multicast loop-back.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc12
+
+#### func (*Socket) SetRate
+
+```go
+func (s *Socket) SetRate(value int64) error
+```
+ZMQ_RATE: Set multicast data rate.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc9
+
+#### func (*Socket) SetRcvHWM
+
+```go
+func (s *Socket) SetRcvHWM(value int) error
+```
+ZMQ_RCVHWM: Set high water mark for inbound messages.
+
+See: http://api.zeromq.org/3.2:zmq-setsockopt#toc4
+
+#### func (*Socket) SetRcvTimeout
+
+```go
+func (s *Socket) SetRcvTimeout(value time.Duration) error
+```
+ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.
+
+See: http://api.zeromq.org/2.2:zmq-setsockopt#toc9
+
+#### func (*Socket) SetRcvbuf
+
+```go
+func (s *Socket) SetRcvbuf(value uint64) error
+```
+ZMQ_RCVBUF: Set kernel receive buffer size.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc14
+
+#### func (*Socket) SetReconnectIvl
+
+```go
+func (s *Socket) SetReconnectIvl(value time.Duration) error
+```
+ZMQ_RECONNECT_IVL: Set reconnection interval.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc16
+
+#### func (*Socket) SetReconnectIvlMax
+
+```go
+func (s *Socket) SetReconnectIvlMax(value time.Duration) error
+```
+ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc17
+
+#### func (*Socket) SetRecoveryIvl
+
+```go
+func (s *Socket) SetRecoveryIvl(value time.Duration) error
+```
+ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc11
+
+#### func (*Socket) SetSndHWM
+
+```go
+func (s *Socket) SetSndHWM(value int) error
+```
+ZMQ_SNDHWM: Set high water mark for outbound messages.
+
+See: http://api.zeromq.org/3.2:zmq-setsockopt#toc3
+
+#### func (*Socket) SetSndTimeout
+
+```go
+func (s *Socket) SetSndTimeout(value time.Duration) error
+```
+ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.
+
+See: http://api.zeromq.org/2.2:zmq-setsockopt#toc10
+
+#### func (*Socket) SetSndbuf
+
+```go
+func (s *Socket) SetSndbuf(value uint64) error
+```
+ZMQ_SNDBUF: Set kernel transmit buffer size.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc13
+
#### func (*Socket) SetSockOptInt
```go
@@ -562,6 +841,150 @@ func (s *Socket) SetSockOptUInt64(option UInt64SocketOption, value uint64) error
Set a uint64 option on the socket. int zmq_setsockopt (void *s, int option,
const void *optval, size_t optvallen);
+#### func (*Socket) SetSubscribe
+
+```go
+func (s *Socket) SetSubscribe(value string) error
+```
+ZMQ_SUBSCRIBE: Establish message filter.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc7
+
+#### func (*Socket) SetSwap
+
+```go
+func (s *Socket) SetSwap(value int64) error
+```
+ZMQ_SWAP: Set disk offload size.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc4
+
+#### func (*Socket) SetTCPKeepalive
+
+```go
+func (s *Socket) SetTCPKeepalive(value int) error
+```
+ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.
+
+See: http://api.zeromq.org/3.2:zmq-setsockopt#toc25
+
+#### func (*Socket) SetTCPKeepaliveCnt
+
+```go
+func (s *Socket) SetTCPKeepaliveCnt(value int) error
+```
+ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.
+
+See: http://api.zeromq.org/3.2:zmq-setsockopt#toc27
+
+#### func (*Socket) SetTCPKeepaliveIdle
+
+```go
+func (s *Socket) SetTCPKeepaliveIdle(value int) error
+```
+ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).
+
+See: http://api.zeromq.org/3.2:zmq-setsockopt#toc26
+
+#### func (*Socket) SetTCPKeepaliveIntvl
+
+```go
+func (s *Socket) SetTCPKeepaliveIntvl(value int) error
+```
+ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.
+
+See: http://api.zeromq.org/3.2:zmq-setsockopt#toc28
+
+#### func (*Socket) SetUnsubscribe
+
+```go
+func (s *Socket) SetUnsubscribe(value string) error
+```
+ZMQ_UNSUBSCRIBE: Remove message filter.
+
+See: http://api.zeromq.org/2.1:zmq-setsockopt#toc8
+
+#### func (*Socket) SndHWM
+
+```go
+func (s *Socket) SndHWM() (int, error)
+```
+ZMQ_SNDHWM: Retrieves high water mark for outbound messages.
+
+See: http://api.zeromq.org/3.2:zmq-getsockopt#toc5
+
+#### func (*Socket) SndTimeout
+
+```go
+func (s *Socket) SndTimeout() (time.Duration, error)
+```
+ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.
+
+See: http://api.zeromq.org/2.2:zmq-getsockopt#toc7
+
+#### func (*Socket) Sndbuf
+
+```go
+func (s *Socket) Sndbuf() (uint64, error)
+```
+ZMQ_SNDBUF: Retrieve kernel transmit buffer size.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc13
+
+#### func (*Socket) Swap
+
+```go
+func (s *Socket) Swap() (int64, error)
+```
+ZMQ_SWAP: Retrieve disk offload size.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc6
+
+#### func (*Socket) TCPKeepalive
+
+```go
+func (s *Socket) TCPKeepalive() (int, error)
+```
+ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.
+
+See: http://api.zeromq.org/3.2:zmq-getsockopt#toc26
+
+#### func (*Socket) TCPKeepaliveCnt
+
+```go
+func (s *Socket) TCPKeepaliveCnt() (int, error)
+```
+ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.
+
+See: http://api.zeromq.org/3.2:zmq-getsockopt#toc28
+
+#### func (*Socket) TCPKeepaliveIdle
+
+```go
+func (s *Socket) TCPKeepaliveIdle() (int, error)
+```
+ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).
+
+See: http://api.zeromq.org/3.2:zmq-getsockopt#toc27
+
+#### func (*Socket) TCPKeepaliveIntvl
+
+```go
+func (s *Socket) TCPKeepaliveIntvl() (int, error)
+```
+ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.
+
+See: http://api.zeromq.org/3.2:zmq-getsockopt#toc29
+
+#### func (*Socket) Type
+
+```go
+func (s *Socket) Type() (SocketType, error)
+```
+ZMQ_TYPE: Retrieve socket type.
+
+See: http://api.zeromq.org/2.1:zmq-getsockopt#toc3
+
#### type SocketType
```go
View
11 gozmqgen/README.md
@@ -0,0 +1,11 @@
+# gozmqgen
+
+Intended use is:
+
+ cd gozmq
+ go run ./gozmqgen/main.go
+
+In case the template isn't quite right, you should also:
+
+ go fmt *.go
+
View
0  gozmqgen/header.txt
No changes.
View
521 gozmqgen/main.go
@@ -0,0 +1,521 @@
+package main
+
+import (
+ "encoding/xml"
+ "flag"
+ "fmt"
+ "io"
+ "io/ioutil"
+ "net/http"
+ "os"
+ "path"
+ "strings"
+ "text/template"
+)
+
+type Args struct {
+ zversion string
+ pages string
+ comment_width uint
+ templsource string
+ headersource string
+}
+
+var args = Args{
+ zversion: "2.1,2.2,3.2",
+ pages: "getsockopt,setsockopt",
+ comment_width: 72,
+ templsource: "./gozmqgen/template.txt",
+ headersource: "./gozmqgen/header.txt",
+}
+
+func main() {
+ flag.StringVar(&args.zversion, "zversion", args.zversion, "version of zmq")
+ flag.StringVar(&args.pages, "pages", args.pages, "comma-delimited man page names")
+ flag.UintVar(&args.comment_width, "comment-width", args.comment_width, "maximum width of comment text")
+ flag.StringVar(&args.templsource, "template", args.templsource, "Name of template file or - to read STDIN.")
+ flag.StringVar(&args.headersource, "header", args.headersource, "Name of header file.")
+ flag.Parse()
+
+ if len(args.templsource) == 0 {
+ panic("'template' is required.")
+ }
+
+ data := map[string]interface{}{
+ "copyright": string(mustRead(args.headersource)),
+ }
+ for _, version := range strings.Split(args.zversion, ",") {
+ data["build"] = buildtags[version]
+ data["version"] = version
+ for _, page := range strings.Split(args.pages, ",") {
+ manual, err := LoadManual(version, "zmq_"+page)
+ if err != nil {
+ panic(err.Error())
+ }
+ defer manual.Close()
+ cite := "http://api.zeromq.org/" + version + ":zmq-" + page
+ var options []map[string]interface{}
+ optlist, err := ParseOptions(version, manual)
+ if err != nil {
+ panic(err.Error())
+ }
+ for _, o := range optlist {
+ o.SetCitation(cite + "#" + o.anchor)
+ if !ignore[""][o.shortname] && !ignore[version][o.shortname] {
+ options = append(options, o.Pod())
+ }
+ }
+ data[page] = map[string]interface{}{
+ "cite": cite,
+ "options": options,
+ }
+ }
+ raw_template := mustRead(args.templsource)
+ t, err := template.New("main").Parse(string(raw_template))
+ if err != nil {
+ panic(err.Error())
+ }
+ out, err := os.Create("zmqgen_" + strings.Replace(version, ".", "_", -1) + ".go")
+ if err != nil {
+ panic(err.Error())
+ } else if err = t.Execute(out, data); err != nil {
+ panic(err.Error())
+ }
+ }
+}
+
+var (
+ gotypes = map[string]map[string]string{
+ "binary data": map[string]string{"": "string"},
+ "character string": map[string]string{"": "string"},
+ "int": map[string]string{
+ "": "int",
+ "boolean": "bool",
+ "milliseconds": "time.Duration",
+ },
+ "int on POSIX systems, SOCKET on Windows": map[string]string{"": "int"},
+ "int64_t": map[string]string{
+ "": "int64",
+ "boolean": "bool",
+ "milliseconds": "time.Duration",
+ },
+ "uint32_t": map[string]string{"": "uint32"},
+ "uint64_t": map[string]string{
+ "": "uint64",
+ "boolean": "bool",
+ },
+ }
+
+ ztypes = map[string]map[string]string{
+ "binary data": map[string]string{"": "String"},
+ "character string": map[string]string{"": "String"},
+ "int": map[string]string{"": "Int"},
+ "int on POSIX systems, SOCKET on Windows": map[string]string{"": "Int"},
+ "int64_t": map[string]string{"": "Int64"},
+ "uint32_t": map[string]string{"": "UInt32"},
+ "uint64_t": map[string]string{"": "UInt64"},
+ }
+
+ lowtypes = map[string]string{
+ "int32_t": "int32",
+ "int64_t": "int64",
+ "uint32_t": "uint32",
+ "uint64_t": "uint64",
+ }
+
+ replacements = map[string]string{
+ "buf": "Buf",
+ "Hwm": "HWM",
+ "hwm": "HWM",
+ "Ipv4only": "IPV4Only",
+ "more": "More",
+ "msg": "Msg",
+ "pub": "PUB",
+ "size": "Size",
+ "Tcp": "TCP",
+ "timeo": "Timeout",
+ }
+
+ cachedir = path.Join(".cache", "codegen")
+
+ // version : shortname : C type
+ fixedtypes = map[string]map[string]string{
+ "": map[string]string{
+ "EVENTS": "uint64_t",
+ "FD": "int",
+ "RATE": "int64_t",
+ "RCVBUF": "uint64_t",
+ "RECOVERY_IVL": "int64_t",
+ "SNDBUF": "uint64_t",
+ "TYPE": "uint64_t",
+ },
+ "2.1": map[string]string{
+ "RCVMORE": "uint64_t",
+ },
+ "2.2": map[string]string{
+ "RCVMORE": "uint64_t",
+ },
+ }
+
+ fixedgotypes = map[string]string{
+ "TYPE": "SocketType",
+ }
+
+ // shortname : unit
+ fixedunits = map[string]string{
+ "XPUB_VERBOSE": "boolean",
+ }
+
+ // version : shortname
+ ignore = map[string]map[string]bool{
+ "": map[string]bool{
+ "DELAY_ATTACH_ON_CONNECT": true,
+ "FD": true,
+ "IPV4ONLY": true,
+ "LAST_ENDPOINT": true,
+ "MAXMSGSIZE": true,
+ "MULTICAST_HOPS": true,
+ "ROUTER_MANDATORY": true,
+ "TCP_ACCEPT_FILTER": true,
+ "XPUB_VERBOSE": true,
+ },
+ "2.1": map[string]bool{
+ "RECOVERY_IVL": true,
+ },
+ "2.2": map[string]bool{
+ "RECOVERY_IVL": true,
+ },
+ "3.2": map[string]bool{},
+ }
+
+ // shortname : shortname
+ rename = map[string]string{
+ "RECOVERY_IVL_MSEC": "RECOVERY_IVL",
+ }
+
+ buildtags = map[string]string{
+ "2.1": "zmq_2_1",
+ "2.2": "!zmq_2_1,!zmq_3_x",
+ "3.2": "zmq_3_x",
+ }
+)
+
+func fix(s string) string {
+ for key, value := range replacements {
+ s = strings.Replace(s, key, value, -1)
+ }
+ return s
+}
+
+func LoadManual(version string, funcname string) (io.ReadCloser, error) {
+ pagename := version + ":" + funcname
+ pagename = strings.Replace(pagename, ".", "-", -1)
+ pagename = strings.Replace(pagename, "_", "-", -1)
+ cachepath := path.Join(cachedir, pagename)
+ cachefile, err := os.Open(cachepath)
+ if err == nil {
+ return cachefile, nil
+ }
+ os.MkdirAll(cachedir, 0755)
+ url := "http://api.zeromq.org/" + pagename
+ resp, err := http.Get(url)
+ if err != nil {
+ return nil, err
+ }
+ defer resp.Body.Close()
+ if resp.StatusCode != 200 {
+ return nil, fmt.Errorf("%s -> %s", url, resp.Status)
+ }
+ if cachefile, err = os.Create(cachepath); err != nil {
+ return nil, err
+ }
+ if _, err := io.Copy(cachefile, resp.Body); err != nil {
+ return nil, err
+ }
+ return os.Open(cachepath)
+}
+
+type Option struct {
+ typ string // type as listed in source documentation
+ unit string // unit as listed source documentation
+ fullname string // e.g. "ZMQ_RCVMORE"
+ shortname string // e.g. "RCVMORE"
+ desc []string // one or more paragraphs
+ cite string // URL to source documentation
+ ctype string // C type e.g. "uint64_t"
+ gotype string // Go type e.g. "SocketType"
+ ztype string // option method suffix e.g. "Int64"
+ lowtype string // go equivalent of C type e.g. "uint64"
+ anchor string // id in source documentation
+ duration bool // true if gotype=="time.Duration"
+ gounit string // e.g. "time.Millisecond"
+ cast bool // true if gotype needs casting
+}
+
+func NewOption(fullname string) *Option {
+ return &Option{
+ fullname: fullname,
+ shortname: fullname[4:],
+ }
+}
+
+func (o *Option) Name() (name string) {
+ shortname, ok := rename[o.shortname]
+ if !ok {
+ shortname = o.shortname
+ }
+ for _, part := range strings.Split(shortname, "_") {
+ name = name + string(part[0]) + strings.ToLower(part[1:])
+ }
+ return fix(name)
+}
+
+func (o *Option) AppendDescription(line string) {
+ line = strings.TrimSpace(line)
+ if len(line) > 0 {
+ o.desc = append(o.desc, line)
+ }
+}
+
+func (o *Option) SetCitation(cite string) {
+ o.cite = cite
+}
+
+func (o *Option) Comment() (comment string) {
+ desc := o.desc[1:]
+ if len(o.cite) > 0 {
+ desc = append([]string{o.cite, ""}, desc...)
+ }
+ for _, line := range desc {
+ if len(line) > 0 && line[0] == ' ' {
+ comment = comment + strings.TrimRight(line, "\n") + "\n"
+ } else {
+ // TODO: wrap line to width chars
+ //wrapped = textwrap.wrap(line, width)
+ //"\n".join(wrapped) + "\n%s\n" % wrapped
+ comment = comment + line
+ }
+ }
+ return
+}
+
+func (o *Option) Summary() string {
+ return o.fullname + ": " + o.desc[0] + "."
+}
+
+func (o *Option) Pod() map[string]interface{} {
+ return map[string]interface{}{
+ "fullname": o.fullname,
+ "shortname": o.shortname,
+ "nicename": o.Name(),
+ "summary": o.Summary(),
+ "description": strings.Split(o.Comment(), "\n"),
+ "ctype": o.typ,
+ "gotype": o.gotype,
+ "ztype": o.ztype,
+ "lowtype": o.lowtype,
+ "anchor": o.anchor,
+ "duration": o.duration,
+ "citation": o.cite,
+ "boolean": o.gotype == "bool",
+ "gounit": o.gounit,
+ "cast": o.cast,
+ }
+}
+
+func (o *Option) String() string { return o.Name() }
+
+type OptionsBuilder struct {
+ options []*Option
+ version string
+}
+
+func (b *OptionsBuilder) Add(name string, info string) bool {
+ if !strings.HasPrefix(name, "ZMQ_") {
+ return false
+ }
+ option := NewOption(name)
+ b.options = append(b.options, option)
+ option.AppendDescription(info)
+ return true
+}
+
+func (b *OptionsBuilder) Describe(info string) {
+ if len(b.options) > 0 {
+ b.options[len(b.options)-1].AppendDescription(info)
+ }
+}
+
+func (b *OptionsBuilder) SetAnchor(anchor string) {
+ if len(b.options) > 0 {
+ b.options[len(b.options)-1].anchor = anchor
+ }
+}
+
+func (b *OptionsBuilder) SetProperty(name string, value string) {
+ if len(b.options) > 0 {
+ option := b.options[len(b.options)-1]
+ name = strings.TrimSpace(name)
+ switch name {
+ case "Option value type":
+ option.typ = value
+ break
+ case "Option value unit":
+ option.unit = value
+ break
+ }
+ if len(option.typ) > 0 && len(option.unit) > 0 {
+ if val, ok := fixedtypes[""][option.shortname]; ok {
+ option.typ = val
+ } else if val, ok := fixedtypes[b.version][option.shortname]; ok {
+ option.typ = val
+ }
+ if val, ok := lowtypes[option.typ]; ok {
+ option.lowtype = val
+ } else {
+ option.lowtype = option.typ
+ }
+ gomap := gotypes[option.typ]
+ if val, ok := gomap[option.unit]; ok {
+ option.gotype = val
+ } else {
+ option.gotype = gomap[""]
+ }
+ if val, ok := fixedgotypes[option.shortname]; ok {
+ option.gotype = val
+ option.cast = true
+ }
+ zmap := ztypes[option.typ]
+ if val, ok := zmap[option.unit]; ok {
+ option.ztype = val
+ } else {
+ option.ztype = zmap[""]
+ }
+ if option.gotype == "time.Duration" {
+ option.duration = true
+ switch option.unit {
+ case "milliseconds":
+ option.gounit = "time.Millisecond"
+ case "seconds":
+ option.gounit = "time.Second"
+ }
+ }
+ }
+ option.AppendDescription(fmt.Sprintf(" %-25s %s\n", name, value))
+ }
+}
+
+func ParseOptions(version string, r io.Reader) ([]*Option, error) {
+ d := xml.NewDecoder(r)
+ d.Strict = false
+ d.AutoClose = xml.HTMLAutoClose
+ d.Entity = xml.HTMLEntity
+ b := &OptionsBuilder{version: version}
+ var state, text, text2 string
+ for {
+ t, err := d.Token()
+ if err == io.EOF {
+ break
+ } else if err != nil {
+ return nil, err
+ } else {
+ switch token := t.(type) {
+ case xml.StartElement:
+ switch token.Name.Local {
+ case "h3":
+ state = "title"
+ text = ""
+ text2 = "unknown"
+ for _, attr := range token.Attr {
+ switch attr.Name.Local {
+ case "id":
+ text2 = attr.Value
+ }
+ }
+ case "table":
+ switch state {
+ case "describing":
+ for _, attr := range token.Attr {
+ switch attr.Name.Local {
+ case "class":
+ if attr.Value == "wiki-content-table" {
+ b.Describe(text)
+ text = ""
+ state = "properties"
+ }
+ }
+ }
+ }
+ case "td":
+ switch state {
+ case "properties":
+ state = "property-name"
+ case "property-name":
+ state = "property-value"
+ }
+ }
+ case xml.EndElement:
+ switch state {
+ case "title":
+ switch token.Name.Local {
+ case "h3":
+ parts := strings.SplitN(text, ": ", 2)
+ if b.Add(parts[0], parts[1]) {
+ state = "describing"
+ b.SetAnchor(text2)
+ } else {
+ state = ""
+ }
+ text = ""
+ text2 = ""
+ }
+ case "describing":
+ switch token.Name.Local {
+ case "p", "li":
+ b.Describe(text)
+ text = ""
+ }
+ case "properties":
+ switch token.Name.Local {
+ case "table":
+ state = ""
+ }
+ case "property-value":
+ switch token.Name.Local {
+ case "td":
+ b.SetProperty(text, text2)
+ state = "properties"
+ text = ""
+ text2 = ""
+ }
+ }
+ case xml.CharData:
+ switch state {
+ case "title":
+ text += string(token)
+ case "describing":
+ text += string(token)
+ case "property-name":
+ text += string(token)
+ case "property-value":
+ text2 += string(token)
+ }
+ }
+ }
+ }
+ return b.options, nil
+}
+
+func mustRead(name string) []byte {
+ var raw []byte
+ var err error
+ if name == "-" {
+ raw, err = ioutil.ReadAll(os.Stdin)
+ } else {
+ raw, err = ioutil.ReadFile(name)
+ }
+ if err != nil {
+ panic(err.Error())
+ }
+ return raw
+}
View
14 gozmqgen/main_test.go
@@ -0,0 +1,14 @@
+package main
+
+import (
+ "testing"
+)
+
+// This test depends on a remote HTTP service that may not even be available.
+func TestLoadManual(t *testing.T) {
+ if m, err := LoadManual("3.2", "zmq-setsockopt"); err != nil {
+ t.Errorf(err.Error())
+ } else if m == nil {
+ t.Errorf("no error yet nil reader.")
+ }
+}
View
36 gozmqgen/template.txt
@@ -0,0 +1,36 @@
+// +build {{.build}}
+//
+{{if .copyright}}{{.copyright}}
+{{end}}
+package gozmq
+
+import (
+ "time"
+)
+
+// This file was {{/*NOT */}}generated automatically. Changes made here will {{/*NOT */}}be lost.
+
+// Socket Option Getters{{with .getsockopt}}{{range .options}}
+
+// {{.summary}}
+//
+// See: {{.citation}}
+//
+func (s *Socket) {{.nicename}}() ({{.gotype}}, error) {
+ {{if .duration}}ms, err := s.GetSockOpt{{.ztype}}({{.shortname}})
+ return time.Duration(ms) * {{.gounit}}, err{{else}}{{if .boolean}}value, err := s.GetSockOpt{{.ztype}}({{.shortname}})
+ return value != 0, err{{else}}return {{if .cast}}{{.gotype}}({{end}}s.GetSockOpt{{.ztype}}({{.shortname}}){{if .cast}}){{end}}{{end}}{{end}}
+}{{end}}{{end}}
+
+// Socket Option Setters{{with .setsockopt}}{{range .options}}
+
+// {{.summary}}
+//
+// See: {{.citation}}
+//
+func (s *Socket) Set{{.nicename}}(value {{.gotype}}) error {
+ {{if .duration}}return s.SetSockOpt{{.ztype}}({{.shortname}}, {{.lowtype}}(value/{{.gounit}})){{else}}{{if .boolean}}if value {
+ return s.SetSockOpt{{.ztype}}({{.shortname}}, 1)
+ }
+ return s.SetSockOpt{{.ztype}}({{.shortname}}, 0){{else}}return s.SetSockOpt{{.ztype}}({{.shortname}}, {{if .cast}}{{.lowtype}}({{end}}value{{if .cast}}){{end}}){{end}}{{end}}
+}{{end}}{{end}}
View
9 zmq_3_x.go
@@ -96,6 +96,15 @@ func (c *Context) SetMaxSockets(value int) error {
return c.set(C.ZMQ_MAX_SOCKETS, value)
}
+func (s *Socket) SetHWM(value int) error {
+ snd := s.SetSndHWM(value)
+ rcv := s.SetRcvHWM(value)
+ if snd != nil {
+ return snd
+ }
+ return rcv
+}
+
// Send a message to the socket.
// int zmq_send (void *s, zmq_msg_t *msg, int flags);
func (s *Socket) Send(data []byte, flags SendRecvOption) error {
View
6 zmq_test.go
@@ -190,6 +190,12 @@ func TestSetSockOptString(t *testing.T) {
if rc := s.SetSockOptString(SUBSCRIBE, "TEST"); rc != nil {
t.Errorf("Failed to subscribe; %v", rc)
}
+ if rc := s.SetSubscribe("TEST"); rc != nil {
+ t.Errorf("Failed to subscribe; %v", rc)
+ }
+ if rc := s.SetUnsubscribe("TEST"); rc != nil {
+ t.Errorf("Failed to unsubscribe; %v", rc)
+ }
}
func TestMultipart(t *testing.T) {
View
271 zmqgen_2_1.go
@@ -0,0 +1,271 @@
+// +build zmq_2_1
+//
+
+package gozmq
+
+import (
+ "time"
+)
+
+// This file was generated automatically. Changes made here will be lost.
+
+// Socket Option Getters
+
+// ZMQ_TYPE: Retrieve socket type.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc3
+//
+func (s *Socket) Type() (SocketType, error) {
+ return SocketType(s.GetSockOptUInt64(TYPE))
+}
+
+// ZMQ_RCVMORE: More message parts to follow.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc4
+//
+func (s *Socket) RcvMore() (bool, error) {
+ value, err := s.GetSockOptUInt64(RCVMORE)
+ return value != 0, err
+}
+
+// ZMQ_HWM: Retrieve high water mark.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc5
+//
+func (s *Socket) HWM() (uint64, error) {
+ return s.GetSockOptUInt64(HWM)
+}
+
+// ZMQ_SWAP: Retrieve disk offload size.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc6
+//
+func (s *Socket) Swap() (int64, error) {
+ return s.GetSockOptInt64(SWAP)
+}
+
+// ZMQ_AFFINITY: Retrieve I/O thread affinity.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc7
+//
+func (s *Socket) Affinity() (uint64, error) {
+ return s.GetSockOptUInt64(AFFINITY)
+}
+
+// ZMQ_IDENTITY: Retrieve socket identity.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc8
+//
+func (s *Socket) Identity() (string, error) {
+ return s.GetSockOptString(IDENTITY)
+}
+
+// ZMQ_RATE: Retrieve multicast data rate.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc9
+//
+func (s *Socket) Rate() (int64, error) {
+ return s.GetSockOptInt64(RATE)
+}
+
+// ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc11
+//
+func (s *Socket) RecoveryIvl() (time.Duration, error) {
+ ms, err := s.GetSockOptInt64(RECOVERY_IVL_MSEC)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_MCAST_LOOP: Control multicast loop-back.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc12
+//
+func (s *Socket) McastLoop() (bool, error) {
+ value, err := s.GetSockOptInt64(MCAST_LOOP)
+ return value != 0, err
+}
+
+// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc13
+//
+func (s *Socket) SndBuf() (uint64, error) {
+ return s.GetSockOptUInt64(SNDBUF)
+}
+
+// ZMQ_RCVBUF: Retrieve kernel receive buffer size.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc14
+//
+func (s *Socket) RcvBuf() (uint64, error) {
+ return s.GetSockOptUInt64(RCVBUF)
+}
+
+// ZMQ_LINGER: Retrieve linger period for socket shutdown.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc15
+//
+func (s *Socket) Linger() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(LINGER)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc16
+//
+func (s *Socket) ReconnectIvl() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RECONNECT_IVL)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc17
+//
+func (s *Socket) ReconnectIvlMax() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc18
+//
+func (s *Socket) Backlog() (int, error) {
+ return s.GetSockOptInt(BACKLOG)
+}
+
+// ZMQ_EVENTS: Retrieve socket event state.
+//
+// See: http://api.zeromq.org/2.1:zmq-getsockopt#toc20
+//
+func (s *Socket) Events() (uint64, error) {
+ return s.GetSockOptUInt64(EVENTS)
+}
+
+// Socket Option Setters
+
+// ZMQ_HWM: Set high water mark.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc3
+//
+func (s *Socket) SetHWM(value uint64) error {
+ return s.SetSockOptUInt64(HWM, value)
+}
+
+// ZMQ_SWAP: Set disk offload size.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc4
+//
+func (s *Socket) SetSwap(value int64) error {
+ return s.SetSockOptInt64(SWAP, value)
+}
+
+// ZMQ_AFFINITY: Set I/O thread affinity.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc5
+//
+func (s *Socket) SetAffinity(value uint64) error {
+ return s.SetSockOptUInt64(AFFINITY, value)
+}
+
+// ZMQ_IDENTITY: Set socket identity.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc6
+//
+func (s *Socket) SetIdentity(value string) error {
+ return s.SetSockOptString(IDENTITY, value)
+}
+
+// ZMQ_SUBSCRIBE: Establish message filter.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc7
+//
+func (s *Socket) SetSubscribe(value string) error {
+ return s.SetSockOptString(SUBSCRIBE, value)
+}
+
+// ZMQ_UNSUBSCRIBE: Remove message filter.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc8
+//
+func (s *Socket) SetUnsubscribe(value string) error {
+ return s.SetSockOptString(UNSUBSCRIBE, value)
+}
+
+// ZMQ_RATE: Set multicast data rate.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc9
+//
+func (s *Socket) SetRate(value int64) error {
+ return s.SetSockOptInt64(RATE, value)
+}
+
+// ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc11
+//
+func (s *Socket) SetRecoveryIvl(value time.Duration) error {
+ return s.SetSockOptInt64(RECOVERY_IVL_MSEC, int64(value/time.Millisecond))
+}
+
+// ZMQ_MCAST_LOOP: Control multicast loop-back.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc12
+//
+func (s *Socket) SetMcastLoop(value bool) error {
+ if value {
+ return s.SetSockOptInt64(MCAST_LOOP, 1)
+ }
+ return s.SetSockOptInt64(MCAST_LOOP, 0)
+}
+
+// ZMQ_SNDBUF: Set kernel transmit buffer size.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc13
+//
+func (s *Socket) SetSndBuf(value uint64) error {
+ return s.SetSockOptUInt64(SNDBUF, value)
+}
+
+// ZMQ_RCVBUF: Set kernel receive buffer size.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc14
+//
+func (s *Socket) SetRcvBuf(value uint64) error {
+ return s.SetSockOptUInt64(RCVBUF, value)
+}
+
+// ZMQ_LINGER: Set linger period for socket shutdown.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc15
+//
+func (s *Socket) SetLinger(value time.Duration) error {
+ return s.SetSockOptInt(LINGER, int(value/time.Millisecond))
+}
+
+// ZMQ_RECONNECT_IVL: Set reconnection interval.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc16
+//
+func (s *Socket) SetReconnectIvl(value time.Duration) error {
+ return s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))
+}
+
+// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc17
+//
+func (s *Socket) SetReconnectIvlMax(value time.Duration) error {
+ return s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))
+}
+
+// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.
+//
+// See: http://api.zeromq.org/2.1:zmq-setsockopt#toc18
+//
+func (s *Socket) SetBacklog(value int) error {
+ return s.SetSockOptInt(BACKLOG, value)
+}
View
305 zmqgen_2_2.go
@@ -0,0 +1,305 @@
+// +build !zmq_2_1,!zmq_3_x
+//
+
+package gozmq
+
+import (
+ "time"
+)
+
+// This file was generated automatically. Changes made here will be lost.
+
+// Socket Option Getters
+
+// ZMQ_TYPE: Retrieve socket type.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc3
+//
+func (s *Socket) Type() (SocketType, error) {
+ return SocketType(s.GetSockOptUInt64(TYPE))
+}
+
+// ZMQ_RCVMORE: More message parts to follow.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc4
+//
+func (s *Socket) RcvMore() (bool, error) {
+ value, err := s.GetSockOptUInt64(RCVMORE)
+ return value != 0, err
+}
+
+// ZMQ_HWM: Retrieve high water mark.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc5
+//
+func (s *Socket) HWM() (uint64, error) {
+ return s.GetSockOptUInt64(HWM)
+}
+
+// ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc6
+//
+func (s *Socket) RcvTimeout() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RCVTIMEO)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc7
+//
+func (s *Socket) SndTimeout() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(SNDTIMEO)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_SWAP: Retrieve disk offload size.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc8
+//
+func (s *Socket) Swap() (int64, error) {
+ return s.GetSockOptInt64(SWAP)
+}
+
+// ZMQ_AFFINITY: Retrieve I/O thread affinity.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc9
+//
+func (s *Socket) Affinity() (uint64, error) {
+ return s.GetSockOptUInt64(AFFINITY)
+}
+
+// ZMQ_IDENTITY: Retrieve socket identity.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc10
+//
+func (s *Socket) Identity() (string, error) {
+ return s.GetSockOptString(IDENTITY)
+}
+
+// ZMQ_RATE: Retrieve multicast data rate.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc11
+//
+func (s *Socket) Rate() (int64, error) {
+ return s.GetSockOptInt64(RATE)
+}
+
+// ZMQ_RECOVERY_IVL_MSEC: Get multicast recovery interval in milliseconds.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc13
+//
+func (s *Socket) RecoveryIvl() (time.Duration, error) {
+ ms, err := s.GetSockOptInt64(RECOVERY_IVL_MSEC)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_MCAST_LOOP: Control multicast loop-back.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc14
+//
+func (s *Socket) McastLoop() (bool, error) {
+ value, err := s.GetSockOptInt64(MCAST_LOOP)
+ return value != 0, err
+}
+
+// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc15
+//
+func (s *Socket) SndBuf() (uint64, error) {
+ return s.GetSockOptUInt64(SNDBUF)
+}
+
+// ZMQ_RCVBUF: Retrieve kernel receive buffer size.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc16
+//
+func (s *Socket) RcvBuf() (uint64, error) {
+ return s.GetSockOptUInt64(RCVBUF)
+}
+
+// ZMQ_LINGER: Retrieve linger period for socket shutdown.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc17
+//
+func (s *Socket) Linger() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(LINGER)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc18
+//
+func (s *Socket) ReconnectIvl() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RECONNECT_IVL)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc19
+//
+func (s *Socket) ReconnectIvlMax() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc20
+//
+func (s *Socket) Backlog() (int, error) {
+ return s.GetSockOptInt(BACKLOG)
+}
+
+// ZMQ_EVENTS: Retrieve socket event state.
+//
+// See: http://api.zeromq.org/2.2:zmq-getsockopt#toc22
+//
+func (s *Socket) Events() (uint64, error) {
+ return s.GetSockOptUInt64(EVENTS)
+}
+
+// Socket Option Setters
+
+// ZMQ_HWM: Set high water mark.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc3
+//
+func (s *Socket) SetHWM(value uint64) error {
+ return s.SetSockOptUInt64(HWM, value)
+}
+
+// ZMQ_SWAP: Set disk offload size.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc4
+//
+func (s *Socket) SetSwap(value int64) error {
+ return s.SetSockOptInt64(SWAP, value)
+}
+
+// ZMQ_AFFINITY: Set I/O thread affinity.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc5
+//
+func (s *Socket) SetAffinity(value uint64) error {
+ return s.SetSockOptUInt64(AFFINITY, value)
+}
+
+// ZMQ_IDENTITY: Set socket identity.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc6
+//
+func (s *Socket) SetIdentity(value string) error {
+ return s.SetSockOptString(IDENTITY, value)
+}
+
+// ZMQ_SUBSCRIBE: Establish message filter.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc7
+//
+func (s *Socket) SetSubscribe(value string) error {
+ return s.SetSockOptString(SUBSCRIBE, value)
+}
+
+// ZMQ_UNSUBSCRIBE: Remove message filter.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc8
+//
+func (s *Socket) SetUnsubscribe(value string) error {
+ return s.SetSockOptString(UNSUBSCRIBE, value)
+}
+
+// ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc9
+//
+func (s *Socket) SetRcvTimeout(value time.Duration) error {
+ return s.SetSockOptInt(RCVTIMEO, int(value/time.Millisecond))
+}
+
+// ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc10
+//
+func (s *Socket) SetSndTimeout(value time.Duration) error {
+ return s.SetSockOptInt(SNDTIMEO, int(value/time.Millisecond))
+}
+
+// ZMQ_RATE: Set multicast data rate.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc11
+//
+func (s *Socket) SetRate(value int64) error {
+ return s.SetSockOptInt64(RATE, value)
+}
+
+// ZMQ_RECOVERY_IVL_MSEC: Set multicast recovery interval in milliseconds.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc13
+//
+func (s *Socket) SetRecoveryIvl(value time.Duration) error {
+ return s.SetSockOptInt64(RECOVERY_IVL_MSEC, int64(value/time.Millisecond))
+}
+
+// ZMQ_MCAST_LOOP: Control multicast loop-back.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc14
+//
+func (s *Socket) SetMcastLoop(value bool) error {
+ if value {
+ return s.SetSockOptInt64(MCAST_LOOP, 1)
+ }
+ return s.SetSockOptInt64(MCAST_LOOP, 0)
+}
+
+// ZMQ_SNDBUF: Set kernel transmit buffer size.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc15
+//
+func (s *Socket) SetSndBuf(value uint64) error {
+ return s.SetSockOptUInt64(SNDBUF, value)
+}
+
+// ZMQ_RCVBUF: Set kernel receive buffer size.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc16
+//
+func (s *Socket) SetRcvBuf(value uint64) error {
+ return s.SetSockOptUInt64(RCVBUF, value)
+}
+
+// ZMQ_LINGER: Set linger period for socket shutdown.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc17
+//
+func (s *Socket) SetLinger(value time.Duration) error {
+ return s.SetSockOptInt(LINGER, int(value/time.Millisecond))
+}
+
+// ZMQ_RECONNECT_IVL: Set reconnection interval.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc18
+//
+func (s *Socket) SetReconnectIvl(value time.Duration) error {
+ return s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))
+}
+
+// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc19
+//
+func (s *Socket) SetReconnectIvlMax(value time.Duration) error {
+ return s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))
+}
+
+// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.
+//
+// See: http://api.zeromq.org/2.2:zmq-setsockopt#toc20
+//
+func (s *Socket) SetBacklog(value int) error {
+ return s.SetSockOptInt(BACKLOG, value)
+}
View
349 zmqgen_3_2.go
@@ -0,0 +1,349 @@
+// +build zmq_3_x
+//
+
+package gozmq
+
+import (
+ "time"
+)
+
+// This file was generated automatically. Changes made here will be lost.
+
+// Socket Option Getters
+
+// ZMQ_TYPE: Retrieve socket type.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc3
+//
+func (s *Socket) Type() (SocketType, error) {
+ return SocketType(s.GetSockOptUInt64(TYPE))
+}
+
+// ZMQ_RCVMORE: More message data parts to follow.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc4
+//
+func (s *Socket) RcvMore() (bool, error) {
+ value, err := s.GetSockOptInt(RCVMORE)
+ return value != 0, err
+}
+
+// ZMQ_SNDHWM: Retrieves high water mark for outbound messages.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc5
+//
+func (s *Socket) SndHWM() (int, error) {
+ return s.GetSockOptInt(SNDHWM)
+}
+
+// ZMQ_RCVHWM: Retrieve high water mark for inbound messages.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc6
+//
+func (s *Socket) RcvHWM() (int, error) {
+ return s.GetSockOptInt(RCVHWM)
+}
+
+// ZMQ_AFFINITY: Retrieve I/O thread affinity.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc7
+//
+func (s *Socket) Affinity() (uint64, error) {
+ return s.GetSockOptUInt64(AFFINITY)
+}
+
+// ZMQ_IDENTITY: Set socket identity.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc8
+//
+func (s *Socket) Identity() (string, error) {
+ return s.GetSockOptString(IDENTITY)
+}
+
+// ZMQ_RATE: Retrieve multicast data rate.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc9
+//
+func (s *Socket) Rate() (int64, error) {
+ return s.GetSockOptInt64(RATE)
+}
+
+// ZMQ_RECOVERY_IVL: Get multicast recovery interval.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc10
+//
+func (s *Socket) RecoveryIvl() (time.Duration, error) {
+ ms, err := s.GetSockOptInt64(RECOVERY_IVL)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_SNDBUF: Retrieve kernel transmit buffer size.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc11
+//
+func (s *Socket) SndBuf() (uint64, error) {
+ return s.GetSockOptUInt64(SNDBUF)
+}
+
+// ZMQ_RCVBUF: Retrieve kernel receive buffer size.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc12
+//
+func (s *Socket) RcvBuf() (uint64, error) {
+ return s.GetSockOptUInt64(RCVBUF)
+}
+
+// ZMQ_LINGER: Retrieve linger period for socket shutdown.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc13
+//
+func (s *Socket) Linger() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(LINGER)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_RECONNECT_IVL: Retrieve reconnection interval.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc14
+//
+func (s *Socket) ReconnectIvl() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RECONNECT_IVL)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_RECONNECT_IVL_MAX: Retrieve maximum reconnection interval.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc15
+//
+func (s *Socket) ReconnectIvlMax() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RECONNECT_IVL_MAX)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_BACKLOG: Retrieve maximum length of the queue of outstanding connections.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc16
+//
+func (s *Socket) Backlog() (int, error) {
+ return s.GetSockOptInt(BACKLOG)
+}
+
+// ZMQ_RCVTIMEO: Maximum time before a socket operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc19
+//
+func (s *Socket) RcvTimeout() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(RCVTIMEO)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_SNDTIMEO: Maximum time before a socket operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc20
+//
+func (s *Socket) SndTimeout() (time.Duration, error) {
+ ms, err := s.GetSockOptInt(SNDTIMEO)
+ return time.Duration(ms) * time.Millisecond, err
+}
+
+// ZMQ_EVENTS: Retrieve socket event state.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc24
+//
+func (s *Socket) Events() (uint64, error) {
+ return s.GetSockOptUInt64(EVENTS)
+}
+
+// ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc26
+//
+func (s *Socket) TCPKeepalive() (int, error) {
+ return s.GetSockOptInt(TCP_KEEPALIVE)
+}
+
+// ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc27
+//
+func (s *Socket) TCPKeepaliveIdle() (int, error) {
+ return s.GetSockOptInt(TCP_KEEPALIVE_IDLE)
+}
+
+// ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc28
+//
+func (s *Socket) TCPKeepaliveCnt() (int, error) {
+ return s.GetSockOptInt(TCP_KEEPALIVE_CNT)
+}
+
+// ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.
+//
+// See: http://api.zeromq.org/3.2:zmq-getsockopt#toc29
+//
+func (s *Socket) TCPKeepaliveIntvl() (int, error) {
+ return s.GetSockOptInt(TCP_KEEPALIVE_INTVL)
+}
+
+// Socket Option Setters
+
+// ZMQ_SNDHWM: Set high water mark for outbound messages.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc3
+//
+func (s *Socket) SetSndHWM(value int) error {
+ return s.SetSockOptInt(SNDHWM, value)
+}
+
+// ZMQ_RCVHWM: Set high water mark for inbound messages.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc4
+//
+func (s *Socket) SetRcvHWM(value int) error {
+ return s.SetSockOptInt(RCVHWM, value)
+}
+
+// ZMQ_AFFINITY: Set I/O thread affinity.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc5
+//
+func (s *Socket) SetAffinity(value uint64) error {
+ return s.SetSockOptUInt64(AFFINITY, value)
+}
+
+// ZMQ_SUBSCRIBE: Establish message filter.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc6
+//
+func (s *Socket) SetSubscribe(value string) error {
+ return s.SetSockOptString(SUBSCRIBE, value)
+}
+
+// ZMQ_UNSUBSCRIBE: Remove message filter.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc7
+//
+func (s *Socket) SetUnsubscribe(value string) error {
+ return s.SetSockOptString(UNSUBSCRIBE, value)
+}
+
+// ZMQ_IDENTITY: Set socket identity.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc8
+//
+func (s *Socket) SetIdentity(value string) error {
+ return s.SetSockOptString(IDENTITY, value)
+}
+
+// ZMQ_RATE: Set multicast data rate.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc9
+//
+func (s *Socket) SetRate(value int64) error {
+ return s.SetSockOptInt64(RATE, value)
+}
+
+// ZMQ_RECOVERY_IVL: Set multicast recovery interval.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc10
+//
+func (s *Socket) SetRecoveryIvl(value time.Duration) error {
+ return s.SetSockOptInt64(RECOVERY_IVL, int64(value/time.Millisecond))
+}
+
+// ZMQ_SNDBUF: Set kernel transmit buffer size.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc11
+//
+func (s *Socket) SetSndBuf(value uint64) error {
+ return s.SetSockOptUInt64(SNDBUF, value)
+}
+
+// ZMQ_RCVBUF: Set kernel receive buffer size.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc12
+//
+func (s *Socket) SetRcvBuf(value uint64) error {
+ return s.SetSockOptUInt64(RCVBUF, value)
+}
+
+// ZMQ_LINGER: Set linger period for socket shutdown.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc13
+//
+func (s *Socket) SetLinger(value time.Duration) error {
+ return s.SetSockOptInt(LINGER, int(value/time.Millisecond))
+}
+
+// ZMQ_RECONNECT_IVL: Set reconnection interval.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc14
+//
+func (s *Socket) SetReconnectIvl(value time.Duration) error {
+ return s.SetSockOptInt(RECONNECT_IVL, int(value/time.Millisecond))
+}
+
+// ZMQ_RECONNECT_IVL_MAX: Set maximum reconnection interval.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc15
+//
+func (s *Socket) SetReconnectIvlMax(value time.Duration) error {
+ return s.SetSockOptInt(RECONNECT_IVL_MAX, int(value/time.Millisecond))
+}
+
+// ZMQ_BACKLOG: Set maximum length of the queue of outstanding connections.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc16
+//
+func (s *Socket) SetBacklog(value int) error {
+ return s.SetSockOptInt(BACKLOG, value)
+}
+
+// ZMQ_RCVTIMEO: Maximum time before a recv operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc19
+//
+func (s *Socket) SetRcvTimeout(value time.Duration) error {
+ return s.SetSockOptInt(RCVTIMEO, int(value/time.Millisecond))
+}
+
+// ZMQ_SNDTIMEO: Maximum time before a send operation returns with EAGAIN.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc20
+//
+func (s *Socket) SetSndTimeout(value time.Duration) error {
+ return s.SetSockOptInt(SNDTIMEO, int(value/time.Millisecond))
+}
+
+// ZMQ_TCP_KEEPALIVE: Override SO_KEEPALIVE socket option.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc25
+//
+func (s *Socket) SetTCPKeepalive(value int) error {
+ return s.SetSockOptInt(TCP_KEEPALIVE, value)
+}
+
+// ZMQ_TCP_KEEPALIVE_IDLE: Override TCP_KEEPCNT(or TCP_KEEPALIVE on some OS).
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc26
+//
+func (s *Socket) SetTCPKeepaliveIdle(value int) error {
+ return s.SetSockOptInt(TCP_KEEPALIVE_IDLE, value)
+}
+
+// ZMQ_TCP_KEEPALIVE_CNT: Override TCP_KEEPCNT socket option.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc27
+//
+func (s *Socket) SetTCPKeepaliveCnt(value int) error {
+ return s.SetSockOptInt(TCP_KEEPALIVE_CNT, value)
+}
+
+// ZMQ_TCP_KEEPALIVE_INTVL: Override TCP_KEEPINTVL socket option.
+//
+// See: http://api.zeromq.org/3.2:zmq-setsockopt#toc28
+//
+func (s *Socket) SetTCPKeepaliveIntvl(value int) error {
+ return s.SetSockOptInt(TCP_KEEPALIVE_INTVL, value)
+}
Please sign in to comment.
Something went wrong with that request. Please try again.