server/client_handlers.go

78 lines
2.0 KiB
Go
Raw Normal View History

2017-10-27 07:07:14 +00:00
package server
import (
"errors"
"io"
"time"
)
type ClientHandlers struct {
// Server address to connect to.
//
// The address format depends on the underlying transport provided
// by Client.Dial. The following transports are provided out of the box:
// * TCP - see NewTCPClient() and NewTCPServer().
// * TLS - see NewTLSClient() and NewTLSServer().
// * Unix sockets - see NewUnixClient() and NewUnixServer().
//
// By default TCP transport is used.
Addr string
// The maximum number of pending requests in the queue.
//
// The number of pending requsts should exceed the expected number
// of concurrent goroutines calling client's methods.
// Otherwise a lot of ClientError.Overflow errors may appear.
//
// Default is DefaultPendingMessages.
PendingRequests int
// Maximum request time.
// Default value is DefaultRequestTimeout.
RequestTimeout time.Duration
// Size of send buffer per each underlying connection in bytes.
// Default value is DefaultBufferSize.
SendBufferSize int
// Size of recv buffer per each underlying connection in bytes.
// Default value is DefaultBufferSize.
RecvBufferSize int
KeepAlivePeriod time.Duration
}
func (ch *ClientHandlers) Dial() (conn io.ReadWriteCloser, err error) {
return nil, errors.New("Client: Handler method[Dial] of Client is not implement")
}
func (ch *ClientHandlers) OnHandshake(remoteAddr string, rwc io.ReadWriteCloser) error {
return nil
}
func (ch *ClientHandlers) Handle(rwc io.ReadWriteCloser, stopChan chan struct{}) {
}
func (ch *ClientHandlers) GetAddr() string {
return ch.Addr
}
func (ch *ClientHandlers) Validate() {
if ch.PendingRequests <= 0 {
ch.PendingRequests = DefaultPendingMessages
}
if ch.RequestTimeout <= 0 {
ch.RequestTimeout = DefaultRequestTimeout
}
if ch.SendBufferSize <= 0 {
ch.SendBufferSize = DefaultBufferSize
}
if ch.RecvBufferSize <= 0 {
ch.RecvBufferSize = DefaultBufferSize
}
if ch.KeepAlivePeriod <= 0 {
ch.KeepAlivePeriod = DefaultKeepAlivePeriod
}
}