Skip to content
This repository was archived by the owner on Apr 9, 2020. It is now read-only.

Commit 5c9897e

Browse files
committed
Merge branch 'develop'
2 parents e8095ee + 932ea6a commit 5c9897e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

shadowsocks/conn.go

+12-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const (
1616
type Conn struct {
1717
net.Conn
1818
*Cipher
19-
readBuf []byte
20-
writeBuf []byte
21-
chunkId uint32
19+
readBuf []byte
20+
writeBuf []byte
21+
chunkId uint32
2222
}
2323

2424
func NewConn(c net.Conn, cipher *Cipher) *Conn {
@@ -142,11 +142,19 @@ func (c *Conn) Read(b []byte) (n int, err error) {
142142
}
143143

144144
func (c *Conn) Write(b []byte) (n int, err error) {
145+
nn := len(b)
145146
if c.ota {
146147
chunkId := c.GetAndIncrChunkId()
147148
b = otaReqChunkAuth(c.iv, chunkId, b)
148149
}
149-
return c.write(b)
150+
headerLen := len(b) - nn
151+
152+
n, err = c.write(b)
153+
// Make sure <= 0 <= len(b), where b is the slice passed in.
154+
if n >= headerLen {
155+
n -= headerLen
156+
}
157+
return
150158
}
151159

152160
func (c *Conn) write(b []byte) (n int, err error) {

0 commit comments

Comments
 (0)