Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type mongoSocket struct {
gotNonce sync.Cond
dead error
serverInfo *mongoServerInfo
writeLock sync.Mutex
}

type queryOpFlags uint32
Expand Down Expand Up @@ -522,11 +523,31 @@ func (socket *mongoSocket) Query(ops ...interface{}) (err error) {
stats.sentOps(len(ops))

socket.updateDeadline(writeDeadline)
_, err = socket.conn.Write(buf)
socket.Unlock()

bufLen := len(buf)
writeCount := 0
socket.writeLock.Lock()
for writeCount < bufLen {
n, err := socket.conn.Write(buf[writeCount:])
if err != nil {
socket.writeLock.Unlock()
if !wasWaiting && requestCount > 0 {
socket.Lock()
socket.updateDeadline(readDeadline)
socket.Unlock()
}
return err
}
writeCount += n
}
socket.writeLock.Unlock()

if !wasWaiting && requestCount > 0 {
socket.Lock()
socket.updateDeadline(readDeadline)
socket.Unlock()
}
socket.Unlock()
return err
}

Expand Down