Skip to content

Commit

Permalink
Make Conn.Write obey io.Write interface contract.
Browse files Browse the repository at this point in the history
  • Loading branch information
cyfdecyf committed Jun 15, 2016
1 parent d5dda7f commit 932ea6a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions shadowsocks/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const (
type Conn struct {
net.Conn
*Cipher
readBuf []byte
writeBuf []byte
chunkId uint32
readBuf []byte
writeBuf []byte
chunkId uint32
}

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

func (c *Conn) Write(b []byte) (n int, err error) {
nn := len(b)
if c.ota {
chunkId := c.GetAndIncrChunkId()
b = otaReqChunkAuth(c.iv, chunkId, b)
}
return c.write(b)
headerLen := len(b) - nn

n, err = c.write(b)
// Make sure <= 0 <= len(b), where b is the slice passed in.
if n >= headerLen {
n -= headerLen
}
return
}

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

0 comments on commit 932ea6a

Please sign in to comment.