net: add tcp_default_read_timeout and tcp_default_write_timeout and use them consistently

This commit is contained in:
Delyan Angelov 2020-12-15 17:39:11 +02:00
parent 560c21629e
commit e3a1756b11
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED
9 changed files with 80 additions and 130 deletions

View file

@ -3,10 +3,6 @@ import time
fn echo_server(_c net.UdpConn) {
mut c := _c
// arbitrary timeouts to ensure that it doesnt
// instantly throw its hands in the air and give up
c.set_read_timeout(10 * time.second)
c.set_write_timeout(10 * time.second)
for {
mut buf := []byte{ len: 100, init: 0 }
read, addr := c.read(mut buf) or {
@ -23,12 +19,6 @@ fn echo_server(_c net.UdpConn) {
fn echo() ? {
mut c := net.dial_udp('127.0.0.1:40003', '127.0.0.1:40001')?
defer { c.close() or { } }
// arbitrary timeouts to ensure that it doesnt
// instantly throw its hands in the air and give up
c.set_read_timeout(10 * time.second)
c.set_write_timeout(10 * time.second)
data := 'Hello from vlib/net!'
c.write_str(data)?