apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Philippe M. Chiasson" <go...@cpan.org>
Subject Re: [PATCH] apr-util/buckets/apr_buckets_socket.c UDP friendly
Date Fri, 31 Jan 2003 04:10:39 GMT
After some experimentation, the patches I sent were incomplete (gotta
stop submitting patches late at night...)

Here is a better patch that does work fine for me.

Only thing I am not certain about is the re-insertion of the socket
bucket.

In the case of a UDP socket that has data to read, the data IS the whole
datagram. There is no point in adding the socket bucket back in the
brigade after having replaced it with a heap bucket, right ?

Index: srclib/apr-util/buckets/apr_buckets_socket.c
===================================================================
RCS file: /home/cvspublic/apr-util/buckets/apr_buckets_socket.c,v
retrieving revision 1.45
diff -u -I'$Id' -I'$Revision' -r1.45 apr_buckets_socket.c
--- srclib/apr-util/buckets/apr_buckets_socket.c	1 Jan 2003 00:02:17 -0000	1.45
+++ srclib/apr-util/buckets/apr_buckets_socket.c	31 Jan 2003 04:05:38 -0000
@@ -61,6 +61,8 @@
     char *buf;
     apr_status_t rv;
     apr_interval_time_t timeout;
+    apr_sockaddr_t *sa = NULL;
+    int protocol;
 
     if (block == APR_NONBLOCK_READ) {
         apr_socket_timeout_get(p, &timeout);
@@ -71,7 +73,14 @@
     *len = APR_BUCKET_BUFF_SIZE;
     buf = apr_bucket_alloc(*len, a->list); /* XXX: check for failure? */
 
-    rv = apr_socket_recv(p, buf, len);
+    apr_socket_protocol_get(p, &protocol);
+    if (protocol == APR_PROTO_UDP) {
+        apr_socket_addr_get(&sa, APR_REMOTE, p); 
+        rv = apr_recvfrom(sa, p, 0, buf, len);
+    }
+    else {
+        rv = apr_recv(p, buf, len);
+    }
 
     if (block == APR_NONBLOCK_READ) {
         apr_socket_timeout_set(p, timeout);
@@ -103,7 +112,10 @@
         h = a->data;
         h->alloc_len = APR_BUCKET_BUFF_SIZE; /* note the real buffer size */
         *str = buf;
+        
+        if (protocol != APR_PROTO_UDP) {
         APR_BUCKET_INSERT_AFTER(a, apr_bucket_socket_create(p, a->list));
+        }
     }
     else {
         apr_bucket_free(buf);



On Fri, 2003-01-31 at 00:28, Philippe M. Chiasson wrote:
> Oy!, sloppy fingers ...
> 
[...]
> > 
> > ----- Original Message -----
> > From: "Philippe M. Chiasson" <gozer@cpan.org>
> > To: <dev@apr.apache.org>
> > Sent: Thursday, January 30, 2003 3:10 PM
> > Subject: [PATCH] apr-util/buckets/apr_buckets_socket.c UDP friendly
> > 
> > 
> > > I noticed that socket buckets don't use recvfrom when the underlying
> > > socket is UDP. Without that, I have no way to send data back to the
> > > client who initiated the request.
> > >
> > > Either of the following 2 patches fixes this.
> > >
> > > Thanks a lot.
> > >
> > > --------------------------------------------------------------------------
> > ------
> > > Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5
> > > (122FF51B/C634E37B)
> > > http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107
> > > 88C3 A5A5
> > > Q: It is impossible to make anything foolproof because fools are so
> > > ingenious.
> > > perl
> > > -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}
> > '
> > >
> > >
> > 
> > 
> -- 
> 
> 
> --------------------------------------------------------------------------------
> Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5
> (122FF51B/C634E37B)
> http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107
> 88C3 A5A5
> Q: It is impossible to make anything foolproof because fools are so
> ingenious.
> perl
> -e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'
> 
> 
-- 


--------------------------------------------------------------------------------
Philippe M. Chiasson /gozer\@(cpan|ectoplasm)\.org/ 88C3A5A5
(122FF51B/C634E37B)
http://gozer.ectoplasm.org/    F9BF E0C2 480E 7680 1AE5 3631 CB32 A107
88C3 A5A5
Q: It is impossible to make anything foolproof because fools are so
ingenious.
perl
-e'$$=\${gozer};{$_=unpack(P7,pack(L,$$));/^JAm_pH\n$/&&print||$$++&&redo}'

Mime
View raw message