Reputation: 293
Can someone please give me a few scenarios where I might use SetWriteDeadline? I know that SetReadDeadline helps a developer to determine whether the connected endpoint is still reachable or not (with the help of PING/PONG frames), but I can't figure out why I might use SetWriteDeadline.
Upvotes: 4
Views: 2151
Reputation: 1324178
A robust application will set both read and write deadlines
But preferable with Go 1.12 (Q1 2019).
See golang/go issue 25729: net: SetDeadline
performance is poor
That has recently been fixed:
Both the improvements in throughput and latency are far less affected by -cpu values. Nice job!
Upvotes: 0
Reputation: 120951
Write to a connection returns an error when the write operation does not complete by the last set deadline.
The typical use of a write deadline is to detect a peer that is not reading data or is not reading data at an acceptable rate.
A robust application will set both read and write deadlines (but usually not to the same value).
Upvotes: 4