nanomsg

package
Version: v0.0.0-...-fd4faf2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2016 License: MIT, MIT Imports: 7 Imported by: 0

README

Golang nanomsg bindings

Package nanomsg adds language bindings for nanomsg in Go. nanomsg is a high-performance implementation of several "scalability protocols". See http://nanomsg.org/ for more information.

This is a work in progress. nanomsg is still in a beta stage. Expect its API, or this binding, to change.

Installing

Using go get

$ go get github.com/op/go-nanomsg

After this command go-nanomsg is ready to use. Its source will be in:

$GOROOT/src/pkg/github.com/op/go-nanomsg

You can use go get -u -a to update all installed packages.

Documentation

For docs, see http://godoc.org/github.com/op/go-nanomsg or run:

$ go doc github.com/op/go-nanomsg

Alternatives

There is now also an implementation of nanomsg in pure Go. See https://bitbucket.org/gdamore/mangos for more details.

Documentation

Index

Constants

View Source
const (

	// Nanomsg specific errors
	ETERM = Errno(int(C.ETERM))
	EFSM  = Errno(int(C.EFSM))
)
View Source
const (
	AF_SP     = Domain(C.AF_SP)
	AF_SP_RAW = Domain(C.AF_SP_RAW)
)
View Source
const (
	PUSH = Protocol(C.NN_PUSH)
	PULL = Protocol(C.NN_PULL)
)
View Source
const (
	PUB = Protocol(C.NN_PUB)
	SUB = Protocol(C.NN_SUB)
)
View Source
const (
	REQ = Protocol(C.NN_REQ)
	REP = Protocol(C.NN_REP)
)
View Source
const (
	SURVEYOR   = Protocol(C.NN_SURVEYOR)
	RESPONDENT = Protocol(C.NN_RESPONDENT)
)
View Source
const (
	BUS = Protocol(C.NN_BUS)
)
View Source
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.

View Source
const (
	PAIR = Protocol(C.NN_PAIR)
)

Variables

View Source
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

func NewBusSocket() (*BusSocket, error)

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 Domain

type Domain int

SP address families.

type Endpoint

type Endpoint struct {
	Address string
	// contains filtered or unexported fields
}

func (*Endpoint) String

func (e *Endpoint) String() string

type Errno

type Errno syscall.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.

func (Errno) Error

func (e Errno) Error() string

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.

func (*PollItem) CanRecv

func (pi *PollItem) CanRecv() bool

CanRecv returns true if the socket is ready to receive data from.

func (*PollItem) CanSend

func (pi *PollItem) CanSend() bool

CanSend returns true if the socket is ready to send data on.

func (*PollItem) PollRecv

func (pi *PollItem) PollRecv(recv bool)

PollRecv is used to specify if the poller should return as soon as the socket is ready to receive data from.

func (*PollItem) PollSend

func (pi *PollItem) PollSend(send bool)

PollSend is used to specify if the poller should return as soon as the socket is ready to send data on.

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

func (p *Poller) Add(s *Socket, recv, send bool) *PollItem

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

func (p *Poller) Poll(timeout time.Duration) (int, error)

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 Protocol

type Protocol int

type PubSocket

type PubSocket struct {
	*Socket
}

func NewPubSocket

func NewPubSocket() (*PubSocket, error)

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

func NewRepSocket() (*RepSocket, error)

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

func NewReqSocket() (*ReqSocket, error)

NewReqSocket creates a request socket used to implement the client application that sends requests and receives replies.

func (*ReqSocket) ResendInterval

func (req *ReqSocket) ResendInterval() (time.Duration, error)

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.

func (*ReqSocket) SetResendInterval

func (req *ReqSocket) SetResendInterval(interval time.Duration) error

SetResendInterval sets the resend interval for requests.

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 NewSocket

func NewSocket(domain Domain, protocol Protocol) (*Socket, error)

Create a socket.

func (*Socket) Bind

func (s *Socket) Bind(address string) (*Endpoint, error)

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

func (s *Socket) Close() error

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) Connect

func (s *Socket) Connect(address string) (*Endpoint, error)

Add a remote endpoint to the socket.

func (*Socket) Domain

func (s *Socket) Domain() (Domain, error)

Domain returns the domain constant used when the socket was created.

func (*Socket) IPv4Only

func (s *Socket) IPv4Only() (bool, error)

IPv4Only returns true if only IPv4 addresses are used. If false, both IPv4 and IPv6 addresses are used.

func (*Socket) Linger

func (s *Socket) Linger() (time.Duration, error)

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

func (s *Socket) Name() (string, error)

Name returns the socket name for error reporting and statistics. Default value is "N" where N is socket integer.

func (*Socket) Protocol

func (s *Socket) Protocol() (Protocol, error)

Protocol returns the protocol constant used when the socket was created.

func (*Socket) ReconnectInterval

func (s *Socket) ReconnectInterval() (time.Duration, error)

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

func (s *Socket) ReconnectIntervalMax() (time.Duration, error)

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

func (s *Socket) Recv(flags int) ([]byte, error)

Recv receives a message from the socket. The flags argument can be zero or DontWait.

func (*Socket) RecvBuffer

func (s *Socket) RecvBuffer() (int64, error)

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) RecvFd

func (s *Socket) RecvFd() (uintptr, error)

func (*Socket) RecvPrio

func (s *Socket) RecvPrio() (int, error)

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

func (s *Socket) RecvTimeout() (time.Duration, error)

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

func (s *Socket) Send(data []byte, flags int) (int, error)

Send sends a message containing the data. The flags argument can be zero or DontWait.

func (*Socket) SendBuffer

func (s *Socket) SendBuffer() (int64, error)

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) SendFd

func (s *Socket) SendFd() (uintptr, error)

func (*Socket) SendPrio

func (s *Socket) SendPrio() (int, error)

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

func (s *Socket) SendTimeout() (time.Duration, error)

SendTimeout returns the timeout for send operation on the socket. If message cannot be sent within the specified timeout, EAGAIN error is returned. Negative value means infinite timeout. Default value is infinite.

func (*Socket) SetIPv4Only

func (s *Socket) SetIPv4Only(onlyIPv4 bool) error

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

func (s *Socket) SetLinger(linger time.Duration) error

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) SetName

func (s *Socket) SetName(name string) error

SetName sets the socket name for error reporting and statistics.

func (*Socket) SetReconnectInterval

func (s *Socket) SetReconnectInterval(interval time.Duration) error

SetReconnectInterval sets the reconnect interval.

func (*Socket) SetReconnectIntervalMax

func (s *Socket) SetReconnectIntervalMax(interval time.Duration) error

SetReconnectIntervalMax sets the maximum reconnect interval.

func (*Socket) SetRecvBuffer

func (s *Socket) SetRecvBuffer(rcvBuf int64) error

SetRecvBuffer sets the receive buffer size.

func (*Socket) SetRecvPrio

func (s *Socket) SetRecvPrio(prio int) error

SetRecvPrio sets the receiving priority.

func (*Socket) SetRecvTimeout

func (s *Socket) SetRecvTimeout(timeout time.Duration) error

SetRecvTimeout sets the timeout for recv operations.

func (*Socket) SetSendBuffer

func (s *Socket) SetSendBuffer(sndBuf int64) error

SetSendBuffer sets the send buffer size.

func (*Socket) SetSendPrio

func (s *Socket) SetSendPrio(prio int) error

SetSendPrio sets the sending priority.

func (*Socket) SetSendTimeout

func (s *Socket) SetSendTimeout(timeout time.Duration) error

SetSendTimeout sets the timeout for send operations.

func (*Socket) SetSockOptBool

func (s *Socket) SetSockOptBool(level, option C.int, b bool) error

func (*Socket) SetSockOptDuration

func (s *Socket) SetSockOptDuration(level, option C.int, unit, value time.Duration) error

SetSockOptDuration sets the socket option as duration. unit is used to specify the unit which nanomsg exposes the option as.

func (*Socket) SetSockOptInt

func (s *Socket) SetSockOptInt(level, option C.int, value int) error

func (*Socket) SetSockOptString

func (s *Socket) SetSockOptString(level, option C.int, value string) error

SetSockOptString sets the value of the option.

func (*Socket) SetTCPNoDelay

func (s *Socket) SetTCPNoDelay(noDelay bool) error

SetTCPNoDelay controls whether the operating system should delay packet transmission in hopes of sending fewer packets (Nagle's algorithm).

func (*Socket) Shutdown

func (s *Socket) Shutdown(endpoint *Endpoint) error

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) SockOptBool

func (s *Socket) SockOptBool(level, option C.int) (bool, error)

func (*Socket) SockOptDuration

func (s *Socket) SockOptDuration(level, option C.int, unit time.Duration) (time.Duration, error)

SockOptDuration retrieves the socket option as duration. unit is used to specify the unit which nanomsg exposes the option as.

func (*Socket) SockOptInt

func (s *Socket) SockOptInt(level, option C.int) (int, error)

func (*Socket) SockOptString

func (s *Socket) SockOptString(level, option C.int, maxSize int) (string, error)

SockOptString returns the value of the option as string.

func (*Socket) TCPNoDelay

func (s *Socket) TCPNoDelay() (bool, error)

TCPNoDelay returns the current value of TCP no delay.

type SubSocket

type SubSocket struct {
	*Socket
}

func NewSubSocket

func NewSubSocket() (*SubSocket, error)

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) Subscribe

func (sub *SubSocket) Subscribe(topic string) error

Subscribe subscribes to a particular topic.

func (*SubSocket) Unsubscribe

func (sub *SubSocket) Unsubscribe(topic string) error

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.

Directories

Path Synopsis
perf

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL