Hi Everyone, This patch adds a poll() method to APR::Socket that allows you to poll a nonblocking APR socket -- similar to the select() call in Unix-land.
Synopsis: use APR::Socket(); use Apache::Connection (); use APR::Const -compile => qw(POLLIN); my $timeout = 10_000_000; # microseconds my $socket = $connection->client_socket(); $socket->poll($connection->pool, $timeout, APR::POLLIN); Thanks to Stas for showing me the ropes of how to add this support in. mock and I will be updating Apache::TieBucketBrigade to take advantage of this polling interface so that you can do magic things like make Apache look just like a regular Perl socket or file handle -- which would be handy if you were, say, writing an SMTP server that leverages Net::Server::Mail (see Apache::SMTP). </shameless_plug> Index: xs/APR/Socket/APR__Socket.h =================================================================== RCS file: /home/cvspublic/modperl-2.0/xs/APR/Socket/APR__Socket.h,v retrieving revision 1.11 diff -d -u -r1.11 APR__Socket.h --- xs/APR/Socket/APR__Socket.h 9 Jun 2004 14:46:22 -0000 1.11 +++ xs/APR/Socket/APR__Socket.h 30 Aug 2004 19:34:01 -0000 @@ -96,3 +96,23 @@ MP_RUN_CROAK(apr_socket_opt_set(socket, opt, val), "APR::Socket::opt_set"); } + +static MP_INLINE +apr_int32_t mpxs_APR__Socket_poll(pTHX_ apr_socket_t *socket, + apr_pool_t *pool, + apr_interval_time_t timeout, + apr_int16_t reqevents) +{ + apr_pollfd_t fd; + apr_int32_t nsds; + + /* Set up the aprset parameter, which tells apr_poll what to poll */ + fd.desc_type = APR_POLL_SOCKET; + fd.reqevents = reqevents; + fd.rtnevents = 0; /* XXX: not really necessary to set this */ + fd.p = pool; + fd.desc.s = socket; + + /* Poll the socket */ + return apr_poll(&fd, 1, &nsds, timeout); +} Index: xs/maps/apr_functions.map =================================================================== RCS file: /home/cvspublic/modperl-2.0/xs/maps/apr_functions.map,v retrieving revision 1.85 diff -d -u -r1.85 apr_functions.map --- xs/maps/apr_functions.map 25 Aug 2004 22:32:01 -0000 1.85 +++ xs/maps/apr_functions.map 30 Aug 2004 19:34:01 -0000 @@ -72,6 +72,8 @@ -apr_socket_sendfile -apr_socket_sendv !apr_socket_from_file + mpxs_APR__Socket_poll | | apr_socket_t *:socket, apr_pool_t *:pool, \ + apr_interval_time_t:timeout, apr_int16_t:reqevents MODULE=APR::SockAddr !apr_sockaddr_info_get Index: xs/tables/current/ModPerl/FunctionTable.pm =================================================================== RCS file: /home/cvspublic/modperl-2.0/xs/tables/current/ModPerl/FunctionTable.pm,v retrieving revision 1.176 diff -d -u -r1.176 FunctionTable.pm --- xs/tables/current/ModPerl/FunctionTable.pm 25 Aug 2004 22:32:01 -0000 1.176 +++ xs/tables/current/ModPerl/FunctionTable.pm 30 Aug 2004 19:34:01 -0000 @@ -7660,6 +7660,28 @@ 'name' => 'func' } ] + }, + { + 'return_type' => 'apr_int32_t', + 'name' => 'mpxs_APR__Socket_poll', + 'args' => [ + { + 'type' => 'apr_socket_t *', + 'name' => 'socket' + }, + { + 'type' => 'apr_pool_t *', + 'name' => 'pool' + }, + { + 'type' => 'apr_interval_time_t', + 'name' => 'timeout' + }, + { + 'type' => 'apr_int16_t', + 'name' => 'reqevents' + } + ] } ]; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]