Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Read/Write Buffer Size configurable #9

Merged
merged 7 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,12 @@ 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,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to have them still default to 8192? Otherwise I think this is good.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, added defaults of 8192

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