Skip to content

Commit

Permalink
Merge pull request #51 from vearne/develop
Browse files Browse the repository at this point in the history
update http2/processor.go
  • Loading branch information
vearne authored Sep 19, 2024
2 parents 5bce1e4 + 5884a0f commit 471d44b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions http2/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (p *Processor) ProcessTCPPkg() {

// SYN/ACK/FIN
if len(payload) <= 0 {
if pkg.TCP.FIN {
hc.TCPBuffer.Close()
delete(p.ConnRepository, dc)
}
continue
}

Expand Down
18 changes: 15 additions & 3 deletions http2/tcp_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/huandu/skiplist"
slog "github.com/vearne/simplelog"
"math"
"net"
)

type TCPBuffer struct {
Expand All @@ -19,6 +20,7 @@ type TCPBuffer struct {

//There is at most one reader to read
dataChannel chan []byte
closeChan chan struct{}
}

func NewTCPBuffer() *TCPBuffer {
Expand All @@ -29,15 +31,25 @@ func NewTCPBuffer() *TCPBuffer {
sb.expectedSeq = -1
sb.leftPointer = -1
sb.dataChannel = make(chan []byte, 10)
sb.closeChan = make(chan struct{})
return &sb
}

func (sb *TCPBuffer) Close() {
close(sb.closeChan)
}

// may block
func (sb *TCPBuffer) Read(p []byte) (n int, err error) {
data := <-sb.dataChannel
n = copy(p, data)
var data []byte
select {
case <-sb.closeChan:
err = net.ErrClosed
case data = <-sb.dataChannel:
n = copy(p, data)
}
slog.Debug("SocketBuffer.Read, got:%v bytes", n)
return n, nil
return n, err
}

func (sb *TCPBuffer) AddTCP(tcpPkg *layers.TCP) {
Expand Down

0 comments on commit 471d44b

Please sign in to comment.