Davi Arnaut wrote:
> Henry Jen wrote:
>   
>> On Nov 12, 2007 6:41 PM, Davi Arnaut <[EMAIL PROTECTED]> wrote:
>>     
>>> Paul Querna wrote:
>>>       
>>>> Adds: apr_bucket_socket_get_peer() and has the bucket read call recvfrom().
>>>>
>>>> Based on an earlier patch from Issac Goldstand.
>>>>
>>>>         
>>> [..]
>>>
>>>       
>>>> -    rv = apr_socket_recv(p, buf, len);
>>>> +    apr_socket_type_get(p, &sd_type);
>>>> +    if (sd_type == SOCK_STREAM) {
>>>> +        rv = apr_socket_recv(p, buf, len);
>>>> +    } else {
>>>> +        /* Is socket connected? */
>>>> +        if (apr_socket_addr_get(&baton->peer, APR_REMOTE, p) != 
>>>> APR_SUCCESS) {
>>>> +            rv = apr_socket_recv(p, buf, len);
>>>> +        } else {
>>>> +            if (!baton->peer) {
>>>> +                baton->peer = apr_bucket_alloc(sizeof(*baton->peer), 
>>>> a->list);
>>>> +            }
>>>> +            /* Caller is responsible for detecting peer on his own if 
>>>> needed */
>>>> +            rv = apr_socket_recvfrom(baton->peer, p, 0, buf, len);
>>>> +        }
>>>> +    }
>>>>         
>>> Why not cache the the peer and avoid a call to apr_socket_addr_get on
>>> every read?
>>>
>>>       
>> UDP traffic can come from different peers.
>> I wonder if we can simply call apr_socket_recvfrom for all non-stream 
>> protocols?
>>     
>
> I think you missed my point. Since the patch exports apr_bucket_socket
> why not let the user force a specific baton->peer (apr_sockaddr_t) ?
>
> Something like:
>
> } else {
>       if (baton->peer || apr_socket_addr_get() == APR_SUCCESS)
>               if (!baton->peer)
>                       baton->peer = apr_bucket_alloc();
>               rv = apr_socket_recvfrom(baton->peer, p, 0, buf, len);
>       else
>               rv = apr_socket_recv(p, buf, len);
> }
>   

I don't think that will do what you intend.  Doing recvfrom won't
connect the socket in any way, so calls to apr_socket_recv won't work on
it later on.  The same single socket needs to receive from *every* UDP peer.

  Issac

Reply via email to