Documentation ¶
Index ¶
- Variables
- type Channel
- func (ct *Channel) Close() error
- func (ct *Channel) Connect(network, addr string) error
- func (ct *Channel) ConnectTo(conn net.Conn) error
- func (ct *Channel) IsClosed() (st bool)
- func (ct *Channel) ListenAndServe(network, addr string) error
- func (ct *Channel) Recv(block bool) (id []byte, val interface{}, st ChannelStatus)
- func (ct *Channel) Send(block bool, val interface{}) (st ChannelStatus)
- func (ct *Channel) SendAll(block bool, val interface{}) (st []ChannelStatus)
- func (ct *Channel) SendTo(id []byte, val interface{}) (st ChannelStatus)
- func (ct *Channel) Serve(l net.Listener) error
- func (ct *Channel) SetLogger(l *log.Logger)
- func (ct *Channel) Stats() (activeConnections, activeListeners int)
- func (ct *Channel) String() string
- type ChannelStatus
- type Error
- type Interface
- type LocalReceiver
- type LocalSender
- type Receiver
- type Sender
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidResponse is returned when the client or server sent something // unexpected during the handshake. ErrInvalidResponse = errors.New("invalid response") )
Functions ¶
This section is empty.
Types ¶
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
func ListenAndServe ¶
ListenAndServe is an alias for New(initialCap).ListenAndServe(network, addr)
func (*Channel) Connect ¶
Connect connects to a remote channel it can be called multiple times with different addresses (or really the same one if you're that kind of a person)
func (*Channel) ListenAndServe ¶
ListenAndServe listens on the specific network and address waiting for remote channels it can be called multiple times with different addresses
func (*Channel) Recv ¶
func (ct *Channel) Recv(block bool) (id []byte, val interface{}, st ChannelStatus)
Recv returns who sent the message, the message and the status of the channel optionally blocks until there's a message to receive.
func (*Channel) Send ¶
func (ct *Channel) Send(block bool, val interface{}) (st ChannelStatus)
Send sends a message over the network, optionally blocks until it finds a receiver.
func (*Channel) SendAll ¶
func (ct *Channel) SendAll(block bool, val interface{}) (st []ChannelStatus)
func (*Channel) SendTo ¶
func (ct *Channel) SendTo(id []byte, val interface{}) (st ChannelStatus)
SendTo like send but tries to send to a specific client, returns StatusNotFound if the client doesn't exist anymore. note that SendTo always blocks until the message is sent or it errors out
type ChannelStatus ¶
type ChannelStatus byte
ChannelStatus defines the return values from Send/Recv
const ( // StatusNotFound returned when a valid receiver (or sender) coudln't be found StatusNotFound ChannelStatus = iota // StatusNotReady means all channel buffers were full, try again later StatusNotReady // StatusClosed means the channel is closed and should no longer be used StatusClosed // StatusOK means the message was received (or sent) successfully StatusOK )
func (ChannelStatus) String ¶
func (i ChannelStatus) String() string
type Interface ¶
type Interface interface { Sender Receiver io.Closer // ConnectTo conencts to a remote channel using the specific net.Conn ConnectTo(conn net.Conn) error // Serve well, serves a listener. // it blocks until the server is terminated. Serve(l net.Listener) error // IsClosed returns true if the channel is not usable anymore IsClosed() bool }
Interface is the common interface for all network channels
type LocalReceiver ¶
type LocalReceiver <-chan interface{}
LocalReceiver wraps a local channel as a receiver interface, the id will always be nil
func (LocalReceiver) Recv ¶
func (lr LocalReceiver) Recv(block bool) (id []byte, val interface{}, st ChannelStatus)
type LocalSender ¶
type LocalSender chan<- interface{}
LocalSender wraps a local channel as a Sender interface, keep in mind that it will use defer to prevent panics. SendTo will always return StatusNotFound
func (LocalSender) Send ¶
func (ls LocalSender) Send(block bool, val interface{}) (st ChannelStatus)
func (LocalSender) SendTo ¶
func (ls LocalSender) SendTo(id []byte, val interface{}) (st ChannelStatus)
type Receiver ¶
type Receiver interface { // Recv returns who sent the message, the message and the status of the channel // optionally blocks until there's a message to receive. Recv(block bool) (id []byte, val interface{}, st ChannelStatus) }
Receiver defines a read-only channel
func SelectRecv ¶
SelectRecv loops on multiple receivers until it gets a value, it blocks until a value is returned or all channels are closed. this function doesn't panic.
type Sender ¶
type Sender interface { // Send sends a message over the network, optionally blocks until it finds a receiver. Send(block bool, val interface{}) (st ChannelStatus) // SendTo like send but tries to send to a specific client, // returns StatusNotFound if the client doesn't exist anymore. // note that SendTo always blocks until the message is sent or it errors out SendTo(id []byte, val interface{}) (st ChannelStatus) }
Sender defines a write-only channel
func SelectSend ¶
SelectSend loops on multiple senders and returns the first channel that was able to send. it returns the target that sent the value or returns nil if all channels were closed this function doesn't panic.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
pingpong
this is a simple ping/pong example run one instance as a server with: go run pingpong.go -s [-addr 10101] then run one (or more) clients with: go run pingpong [-addr 10101]
|
this is a simple ping/pong example run one instance as a server with: go run pingpong.go -s [-addr 10101] then run one (or more) clients with: go run pingpong [-addr 10101] |