Always explicitly configure socket blocking behavior when creating TCP connections, and provide compile-time flags for backwards compatibility when changing default behaviors.
Always explicitly configure socket blocking behavior when creating TCP connections, and provide compile-time flags for backwards compatibility when changing default behaviors.
When establishing TCP connections, don’t rely on implicit socket blocking settings. Instead, explicitly set the blocking mode after connection creation. When changing default socket behavior, use compile-time conditional compilation to allow users to opt into the previous behavior if needed.
Example implementation:
mut conn := &TcpConn{
sock: s
read_timeout: net.tcp_default_read_timeout
write_timeout: net.tcp_default_write_timeout
}
$if !net_nonblocking_sockets ? {
conn.set_blocking(true)!
}
This pattern ensures that:
-d net_nonblocking_sockets
Apply this approach consistently across all TCP connection creation points including dial_tcp()
, dial_tcp_with_bind()
, and TcpListener.accept()
.
Enter the URL of a public GitHub repository