You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by "Philippe M. Chiasson" <go...@cpan.org> on 2003/01/30 16:10:41 UTC

[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}'


Re: [PATCH] apr-util/buckets/apr_buckets_socket.c UDP friendly

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
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" <go...@cpan.org>
> > To: <de...@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}'

Re: [PATCH] apr-util/buckets/apr_buckets_socket.c UDP friendly

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
Oy!, sloppy fingers ...

Index: 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 -b -B -r1.45 apr_buckets_socket.c
--- apr-util/buckets/apr_buckets_socket.c	1 Jan 2003 00:02:17 -0000	1.45
+++ apr-util/buckets/apr_buckets_socket.c	30 Jan 2003 15:03:55 -0000
@@ -61,6 +61,8 @@
     char *buf;
     apr_status_t rv;
     apr_interval_time_t timeout;
+    apr_sockaddr_t *sa;
+    int protocol;
 
     if (block == APR_NONBLOCK_READ) {
         apr_socket_timeout_get(p, &timeout);
@@ -71,7 +73,15 @@
     *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) {
+	rv = apr_recv(p, buf, len);
+    } 
+    else {
+        apr_socket_addr_get(&sa, APR_REMOTE, p);
+        rv = apr_recvfrom(sa, p, 0,buf, len);
+    }
 
     if (block == APR_NONBLOCK_READ) {
         apr_socket_timeout_set(p, timeout);
Index: 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 -b -B -r1.45 apr_buckets_socket.c
--- apr-util/buckets/apr_buckets_socket.c	1 Jan 2003 00:02:17 -0000	1.45
+++ apr-util/buckets/apr_buckets_socket.c	30 Jan 2003 15:04:40 -0000
@@ -61,6 +61,7 @@
     char *buf;
     apr_status_t rv;
     apr_interval_time_t timeout;
+    apr_sockaddr_t *sa;
 
     if (block == APR_NONBLOCK_READ) {
         apr_socket_timeout_get(p, &timeout);
@@ -71,7 +72,7 @@
     *len = APR_BUCKET_BUFF_SIZE;
     buf = apr_bucket_alloc(*len, a->list); /* XXX: check for failure? */
 
-    rv = apr_socket_recv(p, buf, len);
+    rv = apr_recvfrom(sa, p, 0,buf, len);
 
     if (block == APR_NONBLOCK_READ) {
         apr_socket_timeout_set(p, timeout);

On Thu, 2003-01-30 at 23:36, David Reid wrote:
> Phillipe, your patches missed the email. Maybe you'd like to rebook on a
> later email?
> 
> david
> 
> ----- Original Message -----
> From: "Philippe M. Chiasson" <go...@cpan.org>
> To: <de...@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}'


Re: [PATCH] apr-util/buckets/apr_buckets_socket.c UDP friendly

Posted by David Reid <dr...@jetnet.co.uk>.
Phillipe, your patches missed the email. Maybe you'd like to rebook on a
later email?

david

----- Original Message -----
From: "Philippe M. Chiasson" <go...@cpan.org>
To: <de...@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}
'
>
>