Skip to content

Commit

Permalink
Remove short write checking:
Browse files Browse the repository at this point in the history
See the code for bufio.Writer.  Short writes can not be recovered from.
The removed code attempted to recover, but actually went in to a
hard loop.
  • Loading branch information
gmallard committed Apr 26, 2017
1 parent daf72f9 commit 285c436
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ func (f *Frame) writeFrame(w *bufio.Writer, c *Connection) error {
// Write the body
if len(f.Body) != 0 { // Foolish to write 0 length data
// fmt.Println("WRBDY", f.Body)
e := c.writeBody(f)
if c.dld.wde && c.dld.dns {
_ = c.netconn.SetWriteDeadline(time.Now().Add(c.dld.wdld))
}
_, e = w.Write(f.Body)
if c.checkWriteError(e) != nil {
return e
}
Expand Down Expand Up @@ -214,35 +217,3 @@ func (c *Connection) checkWriteError(e error) error {
}
return e
}

func (c *Connection) writeBody(f *Frame) error {
// fmt.Printf("WDBG99 body:%v bodystring: %v\n", f.Body, string(f.Body))
var n = 0
var e error
for {
if c.dld.wde && c.dld.dns {
_ = c.netconn.SetWriteDeadline(time.Now().Add(c.dld.wdld))
}
n, e = c.wtr.Write(f.Body)
if n == len(f.Body) {
return e
}
c.log("SHORT WRITE", n, len(f.Body))
if c.dld.wde && c.dld.dns && isErrorTimeout(e) {
c.log("invoking write deadline callback 2")
c.dld.dlnotify(e, true)
}
f.Body = f.Body[n:]
}
}

func isErrorTimeout(e error) bool {
if e == nil {
return false
}
_, ok := e.(net.Error)
if !ok {
return false
}
return true
}

0 comments on commit 285c436

Please sign in to comment.