You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jon Travis <jt...@covalent.net> on 2000/12/01 02:41:29 UTC

Nonblocking, dynamic sockets

There is some issue with some of the dynamic sockets (length == -1) when
dealing with non-blocking.  This should fix some of those issues.  Sorry,
nobody committed my last patch, so this is against the repo.

Commit or reject at your leisure.

-- Jon

Index: ap_buckets_socket.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/ap/ap_buckets_socket.c,v
retrieving revision 1.9
diff -u -r1.9 ap_buckets_socket.c
--- ap_buckets_socket.c	2000/11/11 04:41:56	1.9
+++ ap_buckets_socket.c	2000/12/01 01:39:09
@@ -56,7 +56,6 @@
 #include "ap_buckets.h"
 #include <stdlib.h>
 
-/* XXX: We should obey the block flag */
 static apr_status_t socket_read(ap_bucket *a, const char **str,
 			      apr_size_t *len, ap_read_type block)
 {
@@ -66,14 +65,17 @@
     apr_status_t rv;
     apr_int32_t timeout;
 
+    if ((buf = malloc(AP_IOBUFSIZE)) == NULL) {
+        return APR_ENOMEM;
+    }
+
     if (block == AP_NONBLOCK_READ) {
         apr_getsocketopt(p, APR_SO_TIMEOUT, &timeout);
         apr_setsocketopt(p, APR_SO_TIMEOUT, 0);
     }
 
-    buf = malloc(IOBUFSIZE); /* XXX: check for failure? */
     *str = buf;
-    *len = IOBUFSIZE;
+    *len = AP_IOBUFSIZE;
     rv = apr_recv(p, buf, len);
 
     if (block == AP_NONBLOCK_READ) {
@@ -108,6 +110,9 @@
     if (*len > 0) {
         b = ap_bucket_create_socket(p);
 	AP_BUCKET_INSERT_AFTER(a, b);
+    }
+    else if (rv == APR_EOF && block == AP_NONBLOCK_READ) {
+        return APR_EOF;
     }
     return APR_SUCCESS;
 }
Index: ap_buckets_pipe.c
===================================================================
RCS file: /home/cvspublic/apache-2.0/src/ap/ap_buckets_pipe.c,v
retrieving revision 1.20
diff -u -r1.20 ap_buckets_pipe.c
--- ap_buckets_pipe.c	2000/11/11 04:41:56	1.20
+++ ap_buckets_pipe.c	2000/12/01 01:39:09
@@ -56,7 +56,6 @@
 #include "ap_buckets.h"
 #include <stdlib.h>
 
-/* XXX: We should obey the block flag */
 static apr_status_t pipe_read(ap_bucket *a, const char **str,
 			      apr_size_t *len, ap_read_type block)
 {
@@ -66,14 +65,17 @@
     apr_status_t rv;
     apr_interval_time_t timeout;
 
+    if ((buf = malloc(AP_IOBUFSIZE)) == NULL) {
+        return APR_ENOMEM;
+    }
+
     if (block == AP_NONBLOCK_READ) {
         apr_get_pipe_timeout(p, &timeout);
         apr_set_pipe_timeout(p, 0);
     }
 
-    buf = malloc(IOBUFSIZE); /* XXX: check for failure? */
     *str = buf;
-    *len = IOBUFSIZE;
+    *len = AP_IOBUFSIZE;
     rv = apr_read(p, buf, len);
 
     if (block == AP_NONBLOCK_READ) {
@@ -106,8 +108,9 @@
         b = ap_bucket_create_pipe(p);
 	AP_BUCKET_INSERT_AFTER(a, b);
     }
-    else {
+    else if (rv == APR_EOF) {
         apr_close(p);
+        return (block == AP_NONBLOCK_READ) ? APR_EOF : APR_SUCCESS;
     }
     return APR_SUCCESS;
 }