@@ -61,15 +61,10 @@ pub fn (mut s Server) listen_and_serve() {
61
61
eprintln ('Failed getting listener address, err: ${err} ' )
62
62
return
63
63
}
64
- mut listening_address := s.addr.clone ()
65
64
if l.family () == net.AddrFamily.unspec {
66
- if listening_address == ':0' {
67
- listening_address = 'localhost:0'
68
- }
69
- mut listen_family := net.AddrFamily.ip
70
- // $if !windows {
71
- // listen_family = net.AddrFamily.ip6
72
- // }
65
+ listening_address := if s.addr == '' || s.addr == ':0' { 'localhost:0' } else { s.addr }
66
+ listen_family := net.AddrFamily.ip
67
+ // listen_family := $if windows { net.AddrFamily.ip } $else { net.AddrFamily.ip6 }
73
68
s.listener = net.listen_tcp (listen_family, listening_address) or {
74
69
eprintln ('Listening on ${s.addr} failed, err: ${err} ' )
75
70
return
@@ -84,7 +79,6 @@ pub fn (mut s Server) listen_and_serve() {
84
79
85
80
// Create tcp connection channel
86
81
ch := chan & net.TcpConn{cap: s.pool_channel_slots}
87
-
88
82
// Create workers
89
83
mut ws := []thread{cap: s.worker_num}
90
84
for wid in 0 .. s.worker_num {
@@ -101,14 +95,10 @@ pub fn (mut s Server) listen_and_serve() {
101
95
if s.on_running != unsafe { nil } {
102
96
s.on_running (mut s)
103
97
}
104
- for {
105
- // break if we have a stop signal
106
- if s.state != .running {
107
- break
108
- }
98
+ for s.state == .running {
109
99
mut conn := s.listener.accept () or {
110
100
if err.code () == net.err_timed_out_code {
111
- // just skip network timeouts, they are normal
101
+ // Skip network timeouts, they are normal
112
102
continue
113
103
}
114
104
eprintln ('accept() failed, reason: ${err} ; skipping' )
0 commit comments