Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/gorilla/websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergio Andres Virviescas Santana committed Mar 20, 2020
2 parents 6c44d30 + b65e629 commit 1554a54
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This fork adds [fasthttp](https://github.com/valyala/fasthttp) support to the la

### Documentation

* [API Reference](http://godoc.org/github.com/fasthttp/websocket)
* [API Reference](https://pkg.go.dev/github.com/fasthttp/websocket?tab=doc)
* [Chat example](https://github.com/fasthttp/websocket/tree/master/examples/chat)
* [Command example](https://github.com/fasthttp/websocket/tree/master/examples/command)
* [Client and server example](https://github.com/fasthttp/websocket/tree/master/examples/echo)
Expand Down
2 changes: 1 addition & 1 deletion client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func TestHost(t *testing.T) {
server *httptest.Server // server to use
url string // host for request URI
header string // optional request host header
tls string // optiona host for tls ServerName
tls string // optional host for tls ServerName
wantAddr string // expected host for dial
wantHeader string // expected request header on server
insecureSkipVerify bool
Expand Down
14 changes: 7 additions & 7 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ type Conn struct {
subprotocol string

// Write fields
mu chan bool // used as mutex to protect write to conn
writeBuf []byte // frame is constructed in this buffer.
mu chan struct{} // used as mutex to protect write to conn
writeBuf []byte // frame is constructed in this buffer.
writePool BufferPool
writeBufSize int
writeDeadline time.Time
Expand Down Expand Up @@ -302,8 +302,8 @@ func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int,
writeBuf = make([]byte, writeBufferSize)
}

mu := make(chan bool, 1)
mu <- true
mu := make(chan struct{}, 1)
mu <- struct{}{}
c := &Conn{
isServer: isServer,
br: br,
Expand Down Expand Up @@ -377,7 +377,7 @@ func (c *Conn) read(n int) ([]byte, error) {

func (c *Conn) write(frameType int, deadline time.Time, buf0, buf1 []byte) error {
<-c.mu
defer func() { c.mu <- true }()
defer func() { c.mu <- struct{}{} }()

c.writeErrMu.Lock()
err := c.writeErr
Expand Down Expand Up @@ -429,7 +429,7 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
maskBytes(key, 0, buf[6:])
}

d := time.Hour * 1000
d := 1000 * time.Hour
if !deadline.IsZero() {
d = deadline.Sub(time.Now())
if d < 0 {
Expand All @@ -444,7 +444,7 @@ func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) er
case <-timer.C:
return errWriteTimeout
}
defer func() { c.mu <- true }()
defer func() { c.mu <- struct{}{} }()

c.writeErrMu.Lock()
err := c.writeErr
Expand Down
6 changes: 3 additions & 3 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@
// than the largest message do not provide any benefit.
//
// Depending on the distribution of message sizes, setting the buffer size to
// to a value less than the maximum expected message size can greatly reduce
// memory use with a small impact on performance. Here's an example: If 99% of
// the messages are smaller than 256 bytes and the maximum message size is 512
// a value less than the maximum expected message size can greatly reduce memory
// use with a small impact on performance. Here's an example: If 99% of the
// messages are smaller than 256 bytes and the maximum message size is 512
// bytes, then a buffer size of 256 bytes will result in 1.01 more system calls
// than a buffer size of 512 bytes. The memory savings is 50%.
//
Expand Down
7 changes: 3 additions & 4 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ var (
// This server application works with a client application running in the
// browser. The client application does not explicitly close the websocket. The
// only expected close message from the client has the code
// websocket.CloseGoingAway. All other other close messages are likely the
// websocket.CloseGoingAway. All other close messages are likely the
// result of an application or protocol error and are logged to aid debugging.
func ExampleIsUnexpectedCloseError() {

for {
messageType, p, err := c.ReadMessage()
if err != nil {
Expand All @@ -35,11 +34,11 @@ func ExampleIsUnexpectedCloseError() {
}
return
}
processMesage(messageType, p)
processMessage(messageType, p)
}
}

func processMesage(mt int, p []byte) {}
func processMessage(mt int, p []byte) {}

// TestX prevents godoc from showing this entire file in the example. Remove
// this function when a second example is added.
Expand Down
2 changes: 1 addition & 1 deletion examples/chat/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<div id="log"></div>
<form id="form">
<input type="submit" value="Send" />
<input type="text" id="msg" size="64"/>
<input type="text" id="msg" size="64" autofocus />
</form>
</body>
</html>
2 changes: 1 addition & 1 deletion examples/echo/fasthttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ window.addEventListener("load", function(evt) {
var print = function(message) {
var d = document.createElement("div");
d.innerHTML = message;
d.textContent = message;
output.appendChild(d);
};
Expand Down
4 changes: 2 additions & 2 deletions examples/echo/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var homeTemplate = template.Must(template.New("").Parse(`
<html>
<head>
<meta charset="utf-8">
<script>
<script>
window.addEventListener("load", function(evt) {
var output = document.getElementById("output");
Expand All @@ -67,7 +67,7 @@ window.addEventListener("load", function(evt) {
var print = function(message) {
var d = document.createElement("div");
d.innerHTML = message;
d.textContent = message;
output.appendChild(d);
};
Expand Down
4 changes: 2 additions & 2 deletions prepared.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ func (pm *PreparedMessage) frame(key prepareKey) (int, []byte, error) {
// Prepare a frame using a 'fake' connection.
// TODO: Refactor code in conn.go to allow more direct construction of
// the frame.
mu := make(chan bool, 1)
mu <- true
mu := make(chan struct{}, 1)
mu <- struct{}{}
var nc prepareConn
c := &Conn{
conn: &nc,
Expand Down

0 comments on commit 1554a54

Please sign in to comment.