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