Skip to content

Commit

Permalink
websocket: fix bug for body length parsing
Browse files Browse the repository at this point in the history
kqueue: opt write event
  • Loading branch information
lesismal committed Apr 17, 2024
1 parent 7e75f32 commit c3c7638
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
8 changes: 1 addition & 7 deletions nbhttp/websocket/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,11 @@ func (c *Conn) nextFrame(data []byte) ([]byte, MessageType, []byte, bool, bool,

ok = true
data = data[total:l]
err = c.validFrame(opcode, fin, res1, res2, res3, c.expectingFragments)
}
} else {
ok = true
data = data[headLen:l]
}
}

if ok {
err = c.validFrame(opcode, fin, res1, res2, res3, c.expectingFragments)
}

return data, opcode, body, ok, fin, res1, err
}

Expand Down
7 changes: 5 additions & 2 deletions nbio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
var addr = "127.0.0.1:8888"
var testfile = "test_tmp.file"
var gopher *Engine
var testFileSize = 1024 * 200
var testFileSize = 1024 * 1024 * 32

func init() {
if err := os.WriteFile(testfile, make([]byte, testFileSize), 0600); err != nil {
Expand Down Expand Up @@ -181,10 +181,13 @@ func TestSendfile(t *testing.T) {
log.Panicf("write 'sendfile' failed: %v", err)
}

_, err := io.ReadFull(conn, buf)
n, err := io.ReadFull(conn, buf)
if err != nil {
log.Panicf("read file failed: %v", err)
}
if n != testFileSize {
log.Panicf("read wrong file size: %v != %v", n, testFileSize)
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions poller_kqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (p *poller) readWrite(ev *syscall.Kevent_t) {
fd := int(ev.Ident)
c := p.getConn(fd)
if c != nil {
if ev.Filter&syscall.EVFILT_READ == syscall.EVFILT_READ {
if ev.Filter == syscall.EVFILT_READ {
if c.onConnected != nil {
c.onConnected(c, nil)
}
Expand Down Expand Up @@ -172,9 +172,13 @@ func (p *poller) readWrite(ev *syscall.Kevent_t) {
} else {
p.g.onRead(c)
}

if ev.Flags&syscall.EV_EOF != 0 {
c.flush()
}
}

if ev.Filter&syscall.EVFILT_WRITE == syscall.EVFILT_WRITE {
if ev.Filter == syscall.EVFILT_WRITE {
c.flush()
}
}
Expand Down

0 comments on commit c3c7638

Please sign in to comment.