apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mr.Ch...@area99.dk
Subject Re: UDP Listening Port
Date Sun, 05 Aug 2007 06:48:36 GMT
Hi Barry.

This is just a quick suggestion, but try moving the  
apr_socket_timeout_set into the while(!terminate) loop, so it's called  
everytime (works for me).

Regards
Ruben

Quoting Barry Molof <bmolof@olf.com>:

> Hi All,
>
>
>
> I am trying to create a UDP port that will only receive data, never
> send.  My problem is that even though I am setting the socket timeout to
> a number greater than 0, the call to apr_socket_recv blocks and never
> returns because of a timeout.  This is causing my program to hang.  Even
> if another thread closes the socket, the recv method still blocks.  Here
> is some of my code below.  Can anyone help?  Thanks.
>
>
>
> apr_pool_t *p;
>
> apr_socket_t *sock;
>
> apr_sockaddr_t *local_sa;
>
>
>
> // create a pool
>
> apr_pool_create(&p, NULL);
>
>
>
> // create the address info
>
> apr_sockaddr_info_get(&local_sa, NULL, APR_INET, notificationPort, 0,
> p);
>
>
>
> // create the socket
>
> apr_socket_create(&sock, local_sa->family, SOCK_DGRAM, APR_PROTO_UDP,
> p);
>
>
>
> // set socket opts
>
> apr_socket_opt_set(sock, APR_SO_LINGER, 1);
>
> apr_socket_opt_set(sock, APR_SO_RCVBUF, 16384);
>
> apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1);
>
> apr_socket_opt_set(sock, APR_SO_BROADCAST, 1);
>
>
>
> // set timeout
>
> apr_socket_timeout_set(sock, 1000000);
>
>
>
> // bind socket to notification port
>
> apr_socket_bind(sock, local_sa);
>
>
>
> char datarecv[MON_APR_STRLEN];
>
> string readbuff = "";
>
> size_t maxLineSize = 8000;
>
> while(!terminate)
>
> {
>
>       apr_size_t length = MON_APR_STRLEN;
>
>       memset(datarecv, 0, MON_APR_STRLEN);
>
>       rv = apr_socket_recv(sock, datarecv, &length); // this will block
> forever
>
>
>
>
>
>



----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


Mime
View raw message