Skip to content

Commit

Permalink
Merge pull request #9 from weinbergm/master
Browse files Browse the repository at this point in the history
Make Read/Write Buffer Size configurable
  • Loading branch information
schwartzmx committed Dec 13, 2019
2 parents a6aabc9 + 5e34861 commit 4953989
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
6 changes: 4 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{})
Expand Down

0 comments on commit 4953989

Please sign in to comment.