ing
This commit is contained in:
parent
868080cba5
commit
58bfd4b982
|
@ -1,6 +1,8 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
@ -12,14 +14,16 @@ type SocketHandler interface {
|
||||||
SocketContext(parent cuc.Context) SocketContext
|
SocketContext(parent cuc.Context) SocketContext
|
||||||
|
|
||||||
GetURL() *url.URL
|
GetURL() *url.URL
|
||||||
|
GetRequestCookie() http.CookieJar
|
||||||
GetRequestHeader() http.Header
|
GetRequestHeader() http.Header
|
||||||
|
GetSubProtocols() []string
|
||||||
GetMaxMessageSize() int64
|
EnableCompression() bool
|
||||||
GetWriteTimeout() time.Duration
|
UseProxy(req *http.Request) (*url.URL, error)
|
||||||
GetReadTimeout() time.Duration
|
GetHandshakeTimeout() time.Duration
|
||||||
GetPongTimeout() time.Duration
|
Dial(network, addr string) (net.Conn, error)
|
||||||
GetPingTimeout() time.Duration
|
GetTLSConfig() *tls.Config
|
||||||
GetPingPeriod() time.Duration
|
GetReadBufferSize() int
|
||||||
|
GetWriteBufferSize() int
|
||||||
|
|
||||||
// Validate is check handler value
|
// Validate is check handler value
|
||||||
// If you override ths method, must call
|
// If you override ths method, must call
|
||||||
|
|
|
@ -1,66 +1,75 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
cuc "git.loafle.net/commons_go/util/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SocketHandlers struct {
|
type SocketHandlers struct {
|
||||||
// MaxMessageSize is the maximum size for a message read from the peer. If a
|
URL *url.URL
|
||||||
// message exceeds the limit, the connection sends a close frame to the peer
|
RequestCookie http.CookieJar
|
||||||
// and returns ErrReadLimit to the application.
|
RequestHeader http.Header
|
||||||
MaxMessageSize int64
|
SubProtocols []string
|
||||||
// WriteTimeout is the write deadline on the underlying network
|
EnableCompression bool
|
||||||
// connection. After a write has timed out, the websocket state is corrupt and
|
HandshakeTimeout time.Duration
|
||||||
// all future writes will return an error. A zero value for t means writes will
|
TLSConfig *tls.Config
|
||||||
// not time out.
|
ReadBufferSize int
|
||||||
WriteTimeout time.Duration
|
WriteBufferSize int
|
||||||
// ReadTimeout is the read deadline on the underlying network connection.
|
|
||||||
// After a read has timed out, the websocket connection state is corrupt and
|
|
||||||
// all future reads will return an error. A zero value for t means reads will
|
|
||||||
// not time out.
|
|
||||||
ReadTimeout time.Duration
|
|
||||||
|
|
||||||
PongTimeout time.Duration
|
|
||||||
PingTimeout time.Duration
|
|
||||||
PingPeriod time.Duration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) GetMaxMessageSize() int64 {
|
func (sh *SocketHandlers) SocketContext(parent cuc.Context) SocketContext {
|
||||||
return sh.MaxMessageSize
|
return newSocketContext(parent)
|
||||||
}
|
}
|
||||||
func (sh *SocketHandlers) GetWriteTimeout() time.Duration {
|
|
||||||
return sh.WriteTimeout
|
func (sh *SocketHandlers) GetURL() *url.URL {
|
||||||
|
return sh.URL
|
||||||
}
|
}
|
||||||
func (sh *SocketHandlers) GetReadTimeout() time.Duration {
|
|
||||||
return sh.ReadTimeout
|
func (sh *SocketHandlers) GetRequestCookie() http.CookieJar {
|
||||||
|
return sh.RequestCookie
|
||||||
}
|
}
|
||||||
func (sh *SocketHandlers) GetPongTimeout() time.Duration {
|
|
||||||
return sh.PongTimeout
|
func (sh *SocketHandlers) GetRequestHeader() http.Header {
|
||||||
|
return sh.RequestHeader
|
||||||
}
|
}
|
||||||
func (sh *SocketHandlers) GetPingTimeout() time.Duration {
|
|
||||||
return sh.PingTimeout
|
func (sh *SocketHandlers) GetSubProtocols() []string {
|
||||||
|
return sh.SubProtocols
|
||||||
}
|
}
|
||||||
func (sh *SocketHandlers) GetPingPeriod() time.Duration {
|
|
||||||
return sh.PingPeriod
|
func (sh *SocketHandlers) EnableCompression() bool {
|
||||||
|
return sh.EnableCompression
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) UseProxy(req *http.Request) (*url.URL, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) GetHandshakeTimeout() time.Duration {
|
||||||
|
return sh.HandshakeTimeout
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) Dial(network, addr string) (net.Conn, error) {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) GetTLSConfig() *tls.Config {
|
||||||
|
return sh.TLSConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) GetReadBufferSize() int {
|
||||||
|
return sh.ReadBufferSize
|
||||||
|
}
|
||||||
|
|
||||||
|
func (sh *SocketHandlers) GetWriteBufferSize() int {
|
||||||
|
return sh.WriteBufferSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sh *SocketHandlers) Validate() {
|
func (sh *SocketHandlers) Validate() {
|
||||||
if sh.MaxMessageSize <= 0 {
|
|
||||||
sh.MaxMessageSize = DefaultMaxMessageSize
|
|
||||||
}
|
|
||||||
if sh.WriteTimeout <= 0 {
|
|
||||||
sh.WriteTimeout = DefaultWriteTimeout
|
|
||||||
}
|
|
||||||
if sh.ReadTimeout <= 0 {
|
|
||||||
sh.ReadTimeout = DefaultReadTimeout
|
|
||||||
}
|
|
||||||
if sh.PongTimeout <= 0 {
|
|
||||||
sh.PongTimeout = DefaultPongTimeout
|
|
||||||
}
|
|
||||||
if sh.PingTimeout <= 0 {
|
|
||||||
sh.PingTimeout = DefaultPingTimeout
|
|
||||||
}
|
|
||||||
if sh.PingPeriod <= 0 {
|
|
||||||
sh.PingPeriod = DefaultPingPeriod
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user