Permalink
Browse files

Document using getsockname to verify a listening socket

  • Loading branch information...
1 parent f0eff5d commit 937f52e99ce487326a176c0742fb20fc71b32bf1 @hinrik hinrik committed May 22, 2011
Showing with 14 additions and 1 deletion.
  1. +14 −1 lib/POE/Wheel/SocketFactory.pm
@@ -1443,7 +1443,20 @@ to which POE::Wheel::SocketFactory has bound its listening socket.
Test applications may use getsockname() to find the server socket
after POE::Wheel::SocketFactory has bound to INADDR_ANY port 0.
-Z<TODO - Example.>
+Since there is no event fired immediately after a successful creation of a
+listening socket, applications can use getsockname() to verify this.
+
+ use Socket 'unpack_sockaddr_in';
+
+ my $listener = POE::Wheel::SocketFactory->new(
+ BindPort => 123,
+ SuccessEvent => 'got_client',
+ FailureEvent => 'listener_failed',
+ Reuse => 'on',
+ );
+
+ my ($port, $addr) = unpack_sockaddr_in($listener->getsockname);
+ print "Socket successfully bound\n" if $port;
=head2 ID

0 comments on commit 937f52e

Please sign in to comment.