apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jose Quiroga <joseluisquir...@yahoo.com>
Subject Question about APR networking.
Date Fri, 14 Jan 2005 20:03:52 GMT

Hi APR people,

Here it is:

I am coding an UDP protocol app. For each datagram I
need to compare ip info (address and port), and if a
condition is met then keep a copy of it to use it
latter. I can receive millions of datagrams over a
single port coming from several different clients. 
The ip information is compared and copied by a
different thread that the one receiving the datagram.

The problem is memory growth. Since I cannot copy
apr_sockaddr_t objects (internal APR struc has
pointers that a user should not touch), it seems to me
that I would have to create a new one for each call to
apr_socket_recvfrom in a pool for them, but that is
not nice because the pool would start to get really
big (I cannot ‘free’ them) and I cannot clean it
periodically with apr_pool_clear because some of them
could be in use by the thread that processes the ip
info. The ‘hostname’ and ‘port’ fields of
apr_sockaddr_t are not filled at apr_socket_recvfrom
time (so I could make ‘freeable’ duplications of them)
and there are no 'apr_os_sockaddr_get' and
'apr_os_sockaddr_put' functions as for sockets. The
functions 'apr_getnameinfo' and  'apr_sockaddr_ip_get'
allocate memory in apr pools (I cannot pass them an
already allocated pointers as with the ‘buf’ field of
'apr_socket_recvfrom') so that I could pass them my
malloc allocated pointer and free it later, so that
does not help either. There are no
'apr_sockaddr_data_get' and 'apr_sockaddr_data_set'
functions as for sockets. It would help if they
existed and received allocated buffers as parameters.

In other words, I see no APR way to create ‘freeable’
duplication of ip info (host and port) of an incoming
datagram, and I need to do so.

This problem is not present in most apps because UDP
based apps is not a common choice. With TCP apps the
ip addr belongs to the socket and if created it is
done once for each connection not for each TCP packet
so memory growth is not a problem.

At the moment I am solving the problem the non-APR

msg->host = strdup(inet_ntoa(from->sa.sin.sin_addr));
msg->port = ntohs(from->sa.sin.sin_port);

(where 'from''s type is 'apr_sockaddr_t*')

Any suggestions?



Do you Yahoo!? 
Take Yahoo! Mail with you! Get it on your mobile phone. 

View raw message