Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move cs_vSend lock into SocketSendData
SocketSendData requires cs_vSend to be locked, but it places this responsibility with the caller. This is unnecessary, unclear, and has caused us to accidentally add RecordBytesSent under the lock. This commit fixes both problems. Justification is needed in the case of PushMessage. It is ok that we let go of cs_vSend for a moment before locking it again and calling SocketSendData. In the case where optimistic_send == false, this lock is let go of for a long time between adding messages to vSendMsg and the call to SocketSendData (in SocketHandler). As corrected in the comment change, optimistic_send represents whether vSendMsg *was* empty, not *is* empty (as, of course, we've just added to it). If SocketHandler grabs cs_vSend in the middle then SocketSendData will be empty when we call it in PushMessage. As suggested by the "if (bytes_sent)" check, this is fine.
- Loading branch information