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) OnStart() { // no op } func (ch *ClientHandlers) OnStop() { // no op } 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{}) { // no op } func (ch *ClientHandlers) GetAddr() string { return ch.Addr } func (ch *ClientHandlers) GetPendingRequests() int { return ch.PendingRequests } func (ch *ClientHandlers) GetRequestTimeout() time.Duration { return ch.RequestTimeout } func (ch *ClientHandlers) GetSendBufferSize() int { return ch.SendBufferSize } func (ch *ClientHandlers) GetRecvBufferSize() int { return ch.RecvBufferSize } func (ch *ClientHandlers) GetKeepAlivePeriod() time.Duration { return ch.KeepAlivePeriod } 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 } }