diff --git a/client.go b/client.go index a975178a..8ee73615 100644 --- a/client.go +++ b/client.go @@ -30,6 +30,8 @@ func NewDialer(host string, configs ...DialerConfig) (dialer *Ws) { readingWait: 15 * time.Second, connected: false, quit: make(chan struct{}), + readBufSize: 8192, + writeBufSize: 8192, } for _, conf := range configs { diff --git a/configuration.go b/configuration.go index dd7fdae5..4820e94d 100644 --- a/configuration.go +++ b/configuration.go @@ -40,3 +40,11 @@ func SetReadingWait(seconds int) DialerConfig { c.readingWait = time.Duration(seconds) * time.Second } } + +//SetBufferSize sets the read/write buffer size +func SetBufferSize(readBufferSize int, writeBufferSize int) DialerConfig { + return func(c *Ws) { + c.readBufSize = readBufferSize + c.writeBufSize = writeBufferSize + } +} diff --git a/connection.go b/connection.go index 4e64d375..ff103a4d 100644 --- a/connection.go +++ b/connection.go @@ -38,6 +38,8 @@ type Ws struct { writingWait time.Duration readingWait time.Duration timeout time.Duration + readBufSize int + writeBufSize int quit chan struct{} sync.RWMutex } @@ -50,8 +52,8 @@ type auth struct { func (ws *Ws) connect() (err error) { d := websocket.Dialer{ - WriteBufferSize: 8192, - ReadBufferSize: 8192, + WriteBufferSize: ws.writeBufSize, + ReadBufferSize: ws.readBufSize, HandshakeTimeout: ws.timeout, // Timeout or else we'll hang forever and never fail on bad hosts. } ws.conn, _, err = d.Dial(ws.host, http.Header{})