Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

I have added 'connected' method to Feersum::Connection::Handle #11

Closed
wants to merge 3 commits into
from
Jump to file or symbol
Failed to load files and symbols.
+29 −1
Split
View
@@ -2511,6 +2511,24 @@ seek (feer_conn_handle *hdl, ssize_t offset, ...)
RETVAL
int
+connected (feer_conn_handle *hdl)
+ PROTOTYPE: $
+ CODE:
+{
+ assert(ix);
+ socklen_t addrlen;
+ int res;
+ res = getpeername(hdl->fd, hdl->sa, &addrlen);
+ if (res == 0) {
+ RETVAL = 1;
+ } else {
+ RETVAL = 0;
+ }
+}
+ OUTPUT:
+ RETVAL
+
+int
close (feer_conn_handle *hdl)
PROTOTYPE: $
ALIAS:
@@ -57,6 +57,8 @@ For write handles:
$w->poll_cb(sub {
# use $_[0] instead of $w to avoid a closure
$_[0]->write(\"some data");
+ # check if the socket is connected
+ $_[0]->connected();
# can close() or unregister the poll_cb in here
$_[0]->close();
});
@@ -138,6 +140,13 @@ Pass in an array-ref and it works much like the two C<write()> calls above,
except it's way more efficient than calling C<write()> over and over.
Undefined elements of the array are ignored.
+=item C<< $w->connected() >>
+
+Uses getpeername in order to determine if the underlying socket is connected.
+It will return true even if the socket is in CLOSE_WAIT state. If the TCP
+socket is closed (after TCP timeout) by the system it will return false
+value. The implementations is consistent with IO::Handle.
+
=item C<< $w->close() >>
Close the HTTP response (which triggers the "T-E: chunked" terminating chunk
View
@@ -5,7 +5,7 @@ use constant HARDER => $ENV{RELEASE_TESTING} ? 10 : 1;
use constant CLIENTS_11 => HARDER * 2;
use constant CLIENTS_10 => HARDER * 2;
use constant CLIENTS => CLIENTS_11 + CLIENTS_10;
-use Test::More tests => 7 + 21 * CLIENTS_11 + 22 * CLIENTS_10;
+use Test::More tests => 7 + 22 * CLIENTS_11 + 23 * CLIENTS_10;
use Test::Fatal;
use lib 't'; use Utils;
@@ -45,6 +45,7 @@ $evh->request_handler(sub {
$started++;
isa_ok($w, 'Feersum::Connection::Writer', "got a writer $cnum");
isa_ok($w, 'Feersum::Connection::Handle', "... it's a handle $cnum");
+ ok $w->connected, "connected method works on write handle";
my $n = 0;
my $wrote_third = 0;
my $t; $t = AE::timer rand()/5,rand()/5, sub {