… | |
… | |
113 | my $obj = tied ${$_[0]}; |
113 | my $obj = tied ${$_[0]}; |
114 | |
114 | |
115 | my $retval = $obj->[8]; |
115 | my $retval = $obj->[8]; |
116 | $obj->[8] = $_[1] if @_ > 1; |
116 | $obj->[8] = $_[1] if @_ > 1; |
117 | $retval |
117 | $retval |
|
|
118 | } |
|
|
119 | |
|
|
120 | =item connect, listen, bind, getsockopt, setsockopt, |
|
|
121 | send, recv, peername, sockname, shutdown, peerport, peerhost |
|
|
122 | |
|
|
123 | Do the same thing as the perl builtins or IO::Socket methods (but return |
|
|
124 | true on EINPROGRESS). Remember that these must be method calls. |
|
|
125 | |
|
|
126 | =cut |
|
|
127 | |
|
|
128 | sub connect { connect tied(${$_[0]})->[0], $_[1] or $! == Errno::EINPROGRESS } |
|
|
129 | sub bind { bind tied(${$_[0]})->[0], $_[1] } |
|
|
130 | sub listen { listen tied(${$_[0]})->[0], $_[1] } |
|
|
131 | sub getsockopt { getsockopt tied(${$_[0]})->[0], $_[1], $_[2] } |
|
|
132 | sub setsockopt { setsockopt tied(${$_[0]})->[0], $_[1], $_[2], $_[3] } |
|
|
133 | sub send { send tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
|
|
134 | sub recv { recv tied(${$_[0]})->[0], $_[1], $_[2], @_ > 2 ? $_[3] : () } |
|
|
135 | sub sockname { getsockname tied(${$_[0]})->[0] } |
|
|
136 | sub peername { getpeername tied(${$_[0]})->[0] } |
|
|
137 | sub shutdown { shutdown tied(${$_[0]})->[0], $_[1] } |
|
|
138 | |
|
|
139 | =item ($fh, $peername) = $listen_fh->accept |
|
|
140 | |
|
|
141 | In scalar context, returns the newly accepted socket (or undef) and in |
|
|
142 | list context return the ($fh, $peername) pair (or nothing). |
|
|
143 | |
|
|
144 | =cut |
|
|
145 | |
|
|
146 | sub accept { |
|
|
147 | my ($peername, $fh); |
|
|
148 | while () { |
|
|
149 | $peername = accept $fh, tied(${$_[0]})->[0] |
|
|
150 | and return wantarray |
|
|
151 | ? ($_[0]->new_from_fh($fh), $peername) |
|
|
152 | : $_[0]->new_from_fh($fh); |
|
|
153 | |
|
|
154 | return unless $!{EAGAIN}; |
|
|
155 | |
|
|
156 | $_[0]->readable or return; |
|
|
157 | } |
118 | } |
158 | } |
119 | |
159 | |
120 | =item $fh->timeout ([...]) |
160 | =item $fh->timeout ([...]) |
121 | |
161 | |
122 | The optional argument sets the new timeout (in seconds) for this |
162 | The optional argument sets the new timeout (in seconds) for this |