… | |
… | |
170 | sub getpeername { getpeername tied(${$_[0]})->[0] } |
170 | sub getpeername { getpeername tied(${$_[0]})->[0] } |
171 | |
171 | |
172 | =item ($peername, $fh) = $listen_fh->accept |
172 | =item ($peername, $fh) = $listen_fh->accept |
173 | |
173 | |
174 | In scalar context, returns the newly accepted socket (or undef) and in |
174 | In scalar context, returns the newly accepted socket (or undef) and in |
175 | list context return the ($peername, $fh) pair (or nothing). |
175 | list context return the ($fh, $peername) pair (or nothing). |
176 | |
176 | |
177 | =cut |
177 | =cut |
178 | |
178 | |
179 | sub accept { |
179 | sub accept { |
180 | my ($peername, $fh); |
180 | my ($peername, $fh); |
181 | while () { |
181 | while () { |
182 | $peername = accept $fh, tied(${$_[0]})->[0] |
182 | $peername = accept $fh, tied(${$_[0]})->[0] |
183 | and return ($peername, $fh = new_from_fh Coro::Socket $fh); |
183 | and return wantarray |
|
|
184 | ? ((new_from_fh Coro::Socket $fh), $peername), |
|
|
185 | : (new_from_fh Coro::Socket $fh); |
184 | |
186 | |
185 | return unless $!{EAGAIN}; |
187 | return unless $!{EAGAIN}; |
186 | |
188 | |
187 | $_[0]->readable or return; |
189 | $_[0]->readable or return; |
188 | } |
190 | } |