Skip to content

Commit

Permalink
ws_acceptor i/o buffer size = handler buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
felipejfc committed Dec 17, 2019
1 parent 49ccf90 commit da73816
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
8 changes: 4 additions & 4 deletions acceptor/ws_acceptor.go
Expand Up @@ -106,8 +106,8 @@ func (w *WSAcceptor) ListenAndServe() {
}

var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
ReadBufferSize: constants.IOBufferBytesSize,
WriteBufferSize: constants.IOBufferBytesSize,
CheckOrigin: func(r *http.Request) bool {
return true
},
Expand All @@ -125,8 +125,8 @@ func (w *WSAcceptor) ListenAndServe() {
// ListenAndServeTLS listens and serve in the specified addr using tls
func (w *WSAcceptor) ListenAndServeTLS(cert, key string) {
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
ReadBufferSize: constants.IOBufferBytesSize,
WriteBufferSize: constants.IOBufferBytesSize,
}

crt, err := tls.LoadX509KeyPair(cert, key)
Expand Down
3 changes: 3 additions & 0 deletions constants/const.go
Expand Up @@ -99,3 +99,6 @@ const (
IPv4 = "ipv4"
IPv6 = "ipv6"
)

// IOBufferBytesSize will be used when reading messages from clients
var IOBufferBytesSize = 4096
2 changes: 1 addition & 1 deletion service/handler.go
Expand Up @@ -180,7 +180,7 @@ func (h *HandlerService) Handle(conn net.Conn) {
}()

// read loop
data := make([]byte, 4096)
data := make([]byte, constants.IOBufferBytesSize)
buf := bytes.NewBuffer(nil)
for {
totalLen := 0
Expand Down

0 comments on commit da73816

Please sign in to comment.