fix mss calculation

pull/432/merge
Darien Raymond 2017-04-18 21:31:14 +02:00
parent 83920a091e
commit 09398989b6
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 3 additions and 8 deletions

View File

@ -334,19 +334,14 @@ func (v *Connection) Write(b []byte) (int, error) {
func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) { func (c *Connection) WriteMultiBuffer(mb buf.MultiBuffer) (int, error) {
defer mb.Release() defer mb.Release()
if len(mb) == 0 {
return 0, nil
}
if len(mb) == 1 {
return c.Write(mb[0].Bytes())
}
buffer := buf.New() buffer := buf.New()
defer buffer.Release() defer buffer.Release()
totalBytes := 0 totalBytes := 0
for !mb.IsEmpty() { for !mb.IsEmpty() {
buffer.Reset(buf.ReadFrom(&mb)) buffer.Reset(func(b []byte) (int, error) {
return mb.Read(b[:c.mss])
})
nBytes, err := c.Write(buffer.Bytes()) nBytes, err := c.Write(buffer.Bytes())
totalBytes += nBytes totalBytes += nBytes
if err != nil { if err != nil {