… | |
… | |
150 | |
150 | |
151 | $fh; |
151 | $fh; |
152 | } |
152 | } |
153 | |
153 | |
154 | =item connect, listen, bind, getsockopt, setsockopt, |
154 | =item connect, listen, bind, getsockopt, setsockopt, |
155 | send, recv, getpeername, getsockname |
155 | send, recv, peername, sockname |
156 | |
156 | |
157 | Do the same thing as the perl builtins (but return true on |
157 | Do the same thing as the perl builtins or IO::Socket methods (but return |
158 | EINPROGRESS). Remember that these must be method calls. |
158 | true on EINPROGRESS). Remember that these must be method calls. |
159 | |
159 | |
160 | =cut |
160 | =cut |
161 | |
161 | |
162 | sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == Errno::EINPROGRESS } |
162 | sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == Errno::EINPROGRESS } |
163 | sub bind { bind tied(${$_[0]})->[0], $_[1] } |
163 | sub bind { bind tied(${$_[0]})->[0], $_[1] } |
164 | sub listen { listen tied(${$_[0]})->[0], $_[1] } |
164 | sub listen { listen tied(${$_[0]})->[0], $_[1] } |
165 | sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] } |
165 | sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] } |
166 | sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] } |
166 | sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] } |
167 | sub send { send tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
167 | sub send { send tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
168 | sub recv { recv tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
168 | sub recv { recv tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
|
|
169 | sub sockname { getsockname tied(${$_[0]})->[0] } |
169 | sub getsockname { getsockname tied(${$_[0]})->[0] } |
170 | sub peername { 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 ($fh, $peername) pair (or nothing). |
175 | list context return the ($fh, $peername) pair (or nothing). |
… | |
… | |
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 wantarray |
183 | and return wantarray |
184 | ? ((new_from_fh Coro::Socket $fh), $peername), |
184 | ? ((new_from_fh Coro::Socket $fh), $peername) |
185 | : (new_from_fh Coro::Socket $fh); |
185 | : (new_from_fh Coro::Socket $fh); |
186 | |
186 | |
187 | return unless $!{EAGAIN}; |
187 | return unless $!{EAGAIN}; |
188 | |
188 | |
189 | $_[0]->readable or return; |
189 | $_[0]->readable or return; |