Skip to content

Commit

Permalink
Rework write deadline logic
Browse files Browse the repository at this point in the history
  • Loading branch information
edsrzf committed May 9, 2017
1 parent 2abb4ae commit 691ec98
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,13 @@ func (mc *mysqlConn) writePacket(ctx mysqlContext, data []byte) error {
data[3] = mc.sequence

// Write packet
var timeNow = time.Now()
var deadline = timeNow
if mc.writeTimeout > 0 {
deadline = timeNow.Add(mc.writeTimeout)
if isCtxDeadlineSet && deadline.After(ctxDeadline) {
deadline = ctxDeadline
}
var deadline time.Time
if ctxDeadline, ok := ctx.Deadline(); ok {
deadline = ctxDeadline
} else if mc.writeTimeout > 0 {
deadline = time.Now().Add(mc.writeTimeout)
}
if deadline.After(timeNow) {
if !deadline.IsZero() {
if err := mc.netConn.SetWriteDeadline(deadline); err != nil {
return err
}
Expand Down

0 comments on commit 691ec98

Please sign in to comment.