Documentation
¶
Index ¶
- Constants
- Variables
- type BusSocket
- type Domain
- type Endpoint
- type Errno
- type PairSocket
- type PollItem
- type Poller
- type Protocol
- type PubSocket
- type PullSocket
- type PushSocket
- type RepSocket
- type ReqSocket
- type RespondentSocket
- type Socket
- func (s *Socket) Bind(address string) (*Endpoint, error)
- func (s *Socket) Close() error
- func (s *Socket) Connect(address string) (*Endpoint, error)
- func (s *Socket) Domain() (Domain, error)
- func (s *Socket) IPv4Only() (bool, error)
- func (s *Socket) Linger() (time.Duration, error)
- func (s *Socket) Name() (string, error)
- func (s *Socket) Protocol() (Protocol, error)
- func (s *Socket) ReconnectInterval() (time.Duration, error)
- func (s *Socket) ReconnectIntervalMax() (time.Duration, error)
- func (s *Socket) Recv(flags int) ([]byte, error)
- func (s *Socket) RecvBuffer() (int64, error)
- func (s *Socket) RecvFd() (uintptr, error)
- func (s *Socket) RecvMaxSize() (int64, error)
- func (s *Socket) RecvPrio() (int, error)
- func (s *Socket) RecvTimeout() (time.Duration, error)
- func (s *Socket) Send(data []byte, flags int) (int, error)
- func (s *Socket) SendBuffer() (int64, error)
- func (s *Socket) SendFd() (uintptr, error)
- func (s *Socket) SendPrio() (int, error)
- func (s *Socket) SendTimeout() (time.Duration, error)
- func (s *Socket) SetIPv4Only(onlyIPv4 bool) error
- func (s *Socket) SetLinger(linger time.Duration) error
- func (s *Socket) SetName(name string) error
- func (s *Socket) SetReconnectInterval(interval time.Duration) error
- func (s *Socket) SetReconnectIntervalMax(interval time.Duration) error
- func (s *Socket) SetRecvBuffer(rcvBuf int64) error
- func (s *Socket) SetRecvMaxSize(size int64) error
- func (s *Socket) SetRecvPrio(prio int) error
- func (s *Socket) SetRecvTimeout(timeout time.Duration) error
- func (s *Socket) SetSendBuffer(sndBuf int64) error
- func (s *Socket) SetSendPrio(prio int) error
- func (s *Socket) SetSendTimeout(timeout time.Duration) error
- func (s *Socket) SetSockOptBool(level, option C.int, b bool) error
- func (s *Socket) SetSockOptDuration(level, option C.int, unit, value time.Duration) error
- func (s *Socket) SetSockOptInt(level, option C.int, value int) error
- func (s *Socket) SetSockOptString(level, option C.int, value string) error
- func (s *Socket) SetTCPNoDelay(noDelay bool) error
- func (s *Socket) Shutdown(endpoint *Endpoint) error
- func (s *Socket) SockOptBool(level, option C.int) (bool, error)
- func (s *Socket) SockOptDuration(level, option C.int, unit time.Duration) (time.Duration, error)
- func (s *Socket) SockOptInt(level, option C.int) (int, error)
- func (s *Socket) SockOptString(level, option C.int, maxSize int) (string, error)
- func (s *Socket) TCPNoDelay() (bool, error)
- type SubSocket
- type SurveyorSocket
Constants ¶
const ( // Nanomsg specific errors ETERM = Errno(int(C.ETERM)) EFSM = Errno(int(C.EFSM)) )
const ( SURVEYOR = Protocol(C.NN_SURVEYOR) RESPONDENT = Protocol(C.NN_RESPONDENT) )
const (
BUS = Protocol(C.NN_BUS)
)
const ( // Specifies that the operation should be performed in non-blocking mode. // If the message cannot be received or sent straight away, the function // will fail with error EAGAIN. DontWait = int(C.NN_DONTWAIT) )
Sending and receiving can be controlled with these flags.
const (
PAIR = Protocol(C.NN_PAIR)
)
Variables ¶
var Version = struct { Current int Revision int Age int }{ int(C.NN_VERSION_CURRENT), int(C.NN_VERSION_REVISION), int(C.NN_VERSION_AGE), }
Version holds the nanomsg version which is used. nanomsg uses libtool's versioning system.
Functions ¶
This section is empty.
Types ¶
type BusSocket ¶
type BusSocket struct {
*Socket
}
func NewBusSocket ¶
NewBusSocket creates a socket where sent messages are distributed to all nodes in the topology. Incoming messages from all other nodes in the topology are fair-queued in the socket.
type Errno ¶
Errno defines specific nanomsg errors
The errors returned from operations on the nanomsg library and the Go bindings for it tries to return all errors using the errors already found in Go like syscall.EADDRINUSE. There are some errors that only exists in nanomsg and these are defined as Errno.
type PairSocket ¶
type PairSocket struct {
*Socket
}
func NewPairSocket ¶
func NewPairSocket() (*PairSocket, error)
NewPairSocket creates a socket for communication with exactly one peer. Each party can send messages at any time. If the peer is not available or send buffer is full, subsequent calls to Send will block until it’s possible to send the message.
type PollItem ¶
type PollItem struct {
// contains filtered or unexported fields
}
PollItem represents a socket and what events to poll for.
type Poller ¶
type Poller struct {
// contains filtered or unexported fields
}
Poller is used to poll a set of sockets for readability and/or writability.
func (*Poller) Add ¶
Add puts the given socket into the poller to check when it's available for sending or receiving. Use the returned PollItem to check what state the socket is in or to modify what events to wait for.
func (*Poller) Poll ¶
Poll returns as soon as any of the sockets are available for sending and/or receiving, depending on how the poll item is setup. The timeout is used to specify how long the function should block if there are no events.
This function returns the number of events and error. If the poller timed out before any event was received, the number of events will be 0.
type PubSocket ¶
type PubSocket struct {
*Socket
}
func NewPubSocket ¶
NewPubSocket creates a new socket which is used to distribute messages to multiple destinations. Receive operation is not defined.
type PullSocket ¶
type PullSocket struct {
*Socket
}
func NewPullSocket ¶
func NewPullSocket() (*PullSocket, error)
NewPullSocket creates a socket which is used to receive a message from a cluster of nodes. Send operation is not implemented on this socket type.
type PushSocket ¶
type PushSocket struct {
*Socket
}
func NewPushSocket ¶
func NewPushSocket() (*PushSocket, error)
NewPushSocket creates a socket which is used to send messages to a cluster of load-balanced nodes. Receive operation is not implemented on this socket type.
type RepSocket ¶
type RepSocket struct {
*Socket
}
func NewRepSocket ¶
NewRepSocket creates a reply socket used to implement the stateless worker that receives requests and sends replies.
type ReqSocket ¶
type ReqSocket struct {
*Socket
}
func NewReqSocket ¶
NewReqSocket creates a request socket used to implement the client application that sends requests and receives replies.
func (*ReqSocket) ResendInterval ¶
ResendInterval returns the resend interval. If reply is not received in specified amount of time, the request will be automatically resent. Default value is 1 minute.
type RespondentSocket ¶
type RespondentSocket struct {
*Socket
}
func NewRespondentSocket ¶
func NewRespondentSocket() (*RespondentSocket, error)
NewRespondentSocket creates a respondent socket used to respond to the survey. Survey is received using receive function, response is sent using send function. This socket can be connected to at most one peer.
type Socket ¶
type Socket struct {
// contains filtered or unexported fields
}
func (*Socket) Bind ¶
Bind adds a local endpoint to the socket. The endpoint can be then used by other applications to connect to.
The address argument consists of two parts as follows: 'transport'://'address'. The 'transport' specifies the underlying transport protocol to use. The meaning of the 'address' part is specific to the underlying transport protocol.
Endpoint is returned and can be used to unbind.
func (*Socket) Close ¶
Close closes the socket. Any buffered inbound messages that were not yet received by the application will be discarded. The library will try to deliver any outstanding outbound messages for the time specified by the linger socket option. The call will block in the meantime.
func (*Socket) IPv4Only ¶
IPv4Only returns true if only IPv4 addresses are used. If false, both IPv4 and IPv6 addresses are used.
func (*Socket) Linger ¶
Linger returns how long the socket should try to send pending outbound messages after Close() have been called. Negative value means infinite linger.
func (*Socket) Name ¶
Name returns the socket name for error reporting and statistics. Default value is "N" where N is socket integer. This option is experimental.
func (*Socket) ReconnectInterval ¶
ReconnectInterval, for connection-based transports such as TCP, this option specifies how long to wait, when connection is broken before trying to re-establish it. Note that actual reconnect interval may be randomised to some extent to prevent severe reconnection storms. Default value is 0.1 second.
func (*Socket) ReconnectIntervalMax ¶
ReconnectIntervalMax, together with ReconnectInterval, specifies maximum reconnection interval. On each reconnect attempt, the previous interval is doubled until this value is reached. Value of zero means that no exponential backoff is performed and reconnect interval is based only on the reconnect interval. If this value is less than the reconnect interval, it is ignored. Default value is 0.
func (*Socket) Recv ¶
Recv receives a message from the socket. The flags argument can be zero or DontWait.
func (*Socket) RecvBuffer ¶
RecvBuffer returns the size of the receive buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the receive buffer. Default value is 128kB.
func (*Socket) RecvMaxSize ¶
RecvMaxSize returns the maximum message size that can be received, in bytes. Negative value means that the received size is limited only by available addressable memory.
func (*Socket) RecvPrio ¶
RecvPrio sets inbound priority for endpoints subsequently added to the socket. This option has no effect on socket types that are not able to receive messages. When receiving a message, messages from peer with higher priority are received before messages from peer with lower priority. The type of the option is int. Highest priority is 1, lowest priority is 16. Default value is 8.
func (*Socket) RecvTimeout ¶
RecvTimeout returns the timeout for recv operation on the socket. If message cannot be received within the specified timeout, EAGAIN error is returned. Negative value means infinite timeout. Default value is infinite.
func (*Socket) Send ¶
Send sends a message containing the data. The flags argument can be zero or DontWait.
func (*Socket) SendBuffer ¶
SendBuffer returns the size of the send buffer, in bytes. To prevent blocking for messages larger than the buffer, exactly one message may be buffered in addition to the data in the send buffer. Default value is 128kB.
func (*Socket) SendPrio ¶
SendPrio sets outbound priority for endpoints subsequently added to the socket. This option has no effect on socket types that send messages to all the peers. However, if the socket type sends each message to a single peer (or a limited set of peers), peers with high priority take precedence over peers with low priority. The type of the option is int. Highest priority is 1, lowest priority is 16. Default value is 8.
func (*Socket) SendTimeout ¶
SendTimeout returns the timeout for send operation on the socket. If message cannot be sent within the specified timeout, ETIMEDOUT error is returned. Negative value means infinite timeout. Default value is infinite.
func (*Socket) SetIPv4Only ¶
SetIPv4Only sets the IPv4 mode. If onlyIPv4 is true, only IPv4 addresses are used. If false, both IPv4 and IPv4 addresses are used.
func (*Socket) SetLinger ¶
SetLinger sets how long the socket should try to send pending outbound messages after Close() have been called, in nanoseconds (as defined by time.Duration). Negative value means infinite linger.
Default value is 1 second.
func (*Socket) SetReconnectInterval ¶
SetReconnectInterval sets the reconnect interval.
func (*Socket) SetReconnectIntervalMax ¶
SetReconnectIntervalMax sets the maximum reconnect interval.
func (*Socket) SetRecvBuffer ¶
SetRecvBuffer sets the receive buffer size.
func (*Socket) SetRecvMaxSize ¶
SetRecvMaxSize sets the maximum message size that can be received, in bytes. Negative value means that the received size is limited only by available addressable memory. Default is 1024kB.
func (*Socket) SetRecvPrio ¶
SetRecvPrio sets the receiving priority.
func (*Socket) SetRecvTimeout ¶
SetRecvTimeout sets the timeout for recv operations.
func (*Socket) SetSendBuffer ¶
SetSendBuffer sets the send buffer size.
func (*Socket) SetSendPrio ¶
SetSendPrio sets the sending priority.
func (*Socket) SetSendTimeout ¶
SetSendTimeout sets the timeout for send operations.
func (*Socket) SetSockOptDuration ¶
SetSockOptDuration sets the socket option as duration. unit is used to specify the unit which nanomsg exposes the option as.
func (*Socket) SetSockOptString ¶
SetSockOptString sets the value of the option.
func (*Socket) SetTCPNoDelay ¶
SetTCPNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm).
func (*Socket) Shutdown ¶
Removes an endpoint from the socket. This call will return immediately, however, the library will try to deliver any outstanding outbound messages to the endpoint for the time specified by the linger socket option.
func (*Socket) SockOptDuration ¶
SockOptDuration retrieves the socket option as duration. unit is used to specify the unit which nanomsg exposes the option as.
func (*Socket) SockOptString ¶
SockOptString returns the value of the option as string.
func (*Socket) TCPNoDelay ¶
TCPNoDelay returns the current value of TCP no delay.
type SubSocket ¶
type SubSocket struct {
*Socket
}
func NewSubSocket ¶
NewSubSocket creates a new socket which receives messages from the publisher. Only messages that the socket is subscribed to are received. When the socket is created there are no subscriptions and thus no messages will be received. Send operation is not defined on this socket. The socket can be connected to at most one peer.
func (*SubSocket) Unsubscribe ¶
Unsubscribe unsubscribes from a particular topic.
type SurveyorSocket ¶
type SurveyorSocket struct {
*Socket
}
func NewSurveyorSocket ¶
func NewSurveyorSocket() (*SurveyorSocket, error)
NewSurveyorSocket creates a socket used to send the survey. The survey is delivered to all the connected respondents. Once the query is sent, the socket can be used to receive the responses. When the survey deadline expires, receive will return ETIMEDOUT error.
func (*SurveyorSocket) Deadline ¶
func (s *SurveyorSocket) Deadline() (time.Duration, error)
Deadline returns the deadline for the surveyor. Default value is 1 second.
func (*SurveyorSocket) SetDeadline ¶
func (s *SurveyorSocket) SetDeadline(deadline time.Duration) error
SetDeadline specifies how long to wait for responses to the survey. Once the deadline expires, receive function will return ETIMEDOUT error and all subsequent responses to the survey will be silently dropped.