wangjun
wangjun

Reputation: 709

SetDeadline for golang tcp connection

If I set a deadline to a tcp connection, and I read and write it successfully, and I keep it alive for subsequence communction, does the deadline affect the next reading/writing? Should I set deadline to 0 for a connection after reading from/writing to it?

Upvotes: 2

Views: 5283

Answers (1)

Kyslik
Kyslik

Reputation: 8385

The Conn interface also has deadline settings; either for the connection as a whole (SetDeadLine()) or specific to read or write calls (SetReadDeadLine() and SetWriteDeadLine()).

Note that the deadlines are fixed points in (wallclock) time. Unlike timeouts, they don’t reset after a new activity. Each activity on the connection must therefore set a new deadline.

Emphasis mine.

From https://appliedgo.net/networking/ (second google search result).

Upvotes: 4

Related Questions