Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

RE: APR Socket Questions: msg#00207

apache.apr.devel

Subject: RE: APR Socket Questions

In addition to this response,
you should read the code for the APR functions you want/need to use.

See below:

-----Original Message-----
From: David Barrett [mailto:dbarrett@xxxxxxxxxxxx]
Sent: Wednesday, September 29, 2004 3:14 PM
To: dev@xxxxxxxxxxxxxx
Subject: APR Socket Questions

Ok, now I'm starting to move over my socket code, and I've come up with
the following questions:

1) If I want to set a socket to be non-blocking, is it enough to set:
"apr_socket_opt_set( s, APR_SO_NONBLOCK, 1 )", or need I also set
"apr_socket_timeout_set( s, 0 )"? This link
(http://marc.theaimsgroup.com/?l=apr-dev&m=106562047130592&w=2) seems to
indicate I need to do both, but it's almost a year old -- what's the
latest scoop?

I've not used non-blocking... sorry.


2) Is "apr_poll( )" the equivalent to "select( )"? How do I convert an
"apr_socket_t" into a "apr_pollfd_t" in order to add to the pollset?

Example of waiting for a connect to complete:
apr_poll_setup(&readbits, 1, pool);
apr_poll_socket_add(readbits, sock, APR_POLLOUT);
nbr_connects = 1;
status = apr_poll(readbits, 1, &nbr_connects, 5 *
APR_USEC_PER_SEC);
if ( status != APR_SUCCESS
|| nbr_connects == 0 )
{
apr_socket_close(*sock);
stuff deleted


3) When I open a non-blocking socket to a remote client, how do I know
if the connection succeeds? Normally I would "select( )" on the socket
until it's writeable (success) or an error (failure). What's the APR
equivalent?

sorry...


4) If I call "apr_socket_recv( )" on a non-blocking socket, how do I
distinguish between data being available, a graceful shutdown, or an
actual error? In essence, what's the portable equivalent to:

# int numRead = recv( s, ... );
# if( numRead == SOCKET_ERROR ) {
# int error = WSAGetLastError( );
# if( error == WSAEWOULDBLOCK ) {
# // No data available, but no error otherwise
# } else {
# // Actual read error
# }
# } else if( numRead == 0 ) {
# // Graceful shutdown initiated by remote side
# } else {
# // Data available
# assert( numRead > 0 );
# }

5) How do I bind a socket to listen on an unspecified port? Normally
I'd set "sockaddr_in.sin_port = INADDR_ANY" when using "bind( )".
However, APR defines "APR_ANYADDR" to be the string "0.0.0.0". Should I
use "APR_UNSPEC"
instead?

use apr_socket_bind(apr_socket_t *sock, apr_sockaddr_t *sa)
where sa's sin_port is set to zero.

6) When I bind a socket to a local port for listening, how can I
determine which port it was bound to? The sample uses
"apr_sockaddr_port_get( )", but this function doesn't seem to exist in
my APR installation (Unix nor Wi32).
("apr_sockaddr_ip_get( )" works fine, though.) Is my install
(apr-1.0.0) broken? As a workaround, will using "ntohs(
sockAddr->sa.sin.sin_port )" be portable?

Sorry...


7) When setting a socket to listen on a port, how can I choose the
maximum backlog? Normally I'd say "listen( s, SOMAXCONN )". Should I
just use "apr_socket_listen( s, SOMAXCONN )", or is there an APR
replacement for SOMAXCONN?

Searching APR doesn't reveal SOMAXCONN being used.


This is my first attempt at real cross-platform development and
compilation, and APR is proving to be a tremendous help. It's great to
have so much functionality under one roof. Thanks again!

-david




<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
ide.eclipse.wtp...    bug-tracking.ro...    xfree86.cvs/200...    lisp.wxcl.devel...    file-systems.ar...    kde.devel.kwrit...    jakarta.jetspee...    qnx.openqnx.dev...    drivers.openib/...    ports.xbox.deve...    gis.gdal.devel/...    netbsd.ports.ma...    ubuntu.marketin...    systemtap/2005-...    web.omniweb/200...    mail.qmail.ldap...    hardware.soekri...    os.netbsd.devel...    audio.madman.ge...    tv.freeguide-tv...    cluster.openmos...    education.ezpro...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation