Skip to content

Commit

Permalink
chore: mini refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
nange committed Nov 19, 2024
1 parent 9ce91cd commit 909224b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
20 changes: 8 additions & 12 deletions cipherstream/cipherstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,7 @@ func (cs *CipherStream) Read(b []byte) (int, error) {
return cn, nil
}

var frame *Frame
for frame = range cs.frameIter.Iter() {
for frame := range cs.frameIter.Iter() {
if cs.frameIter.Error() != nil {
if timeout(cs.frameIter.Error()) {
return 0, errors.Join(cs.frameIter.Error(), ErrTimeout)
Expand All @@ -204,19 +203,16 @@ func (cs *CipherStream) Read(b []byte) (int, error) {
continue
}

break
}
rawData := frame.RawDataPayload()
cn := copy(b, rawData)
if cn < len(rawData) {
cs.leftover = rawData[cn:]
}

if frame == nil {
panic("frame must not be nil")
}
rawData := frame.RawDataPayload()
cn := copy(b, rawData)
if cn < len(rawData) {
cs.leftover = rawData[cn:]
return cn, nil
}

return cn, nil
return 0, io.ErrUnexpectedEOF
}

func (cs *CipherStream) ReadFrame() (*Frame, error) {
Expand Down
1 change: 0 additions & 1 deletion cipherstream/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ var (
ErrACKRSTStream = errors.New("receive ACK_RST_STREAM frame")
ErrTimeout = errors.New("net: io timeout error")
ErrPayloadSize = errors.New("payload size is invalid")
ErrPingHook = errors.New("ping hook error")
)

0 comments on commit 909224b

Please sign in to comment.