cvs commit: apache-2.0/src/lib/apr/network_io/unix sendrecv.c

2000-02-14 Thread rbb
rbb 00/02/14 05:43:39

  Modified:src/lib/apr/network_io/unix sendrecv.c
  Log:
  Fix some bugs in ap_send and ap_recv.  We used to return APR_SUCCESS even
  when it didn't succeed.  The other problem this is solving, is that we
  never set the length to -1 anymore.  The length is the number of bytes
  written or read, as such -1 makes no sense.  If there is an error, 0 bytes
  were written, so len should be 0.
  Submitted by: Manoj Kasichainula and Ryan Bloom
  
  Revision  ChangesPath
  1.10  +10 -2 apache-2.0/src/lib/apr/network_io/unix/sendrecv.c
  
  Index: sendrecv.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- sendrecv.c2000/01/26 05:01:16 1.9
  +++ sendrecv.c2000/02/14 13:43:39 1.10
  @@ -108,17 +108,21 @@
   } while (srv == -1  errno == EINTR);
   
   if (srv == 0) {
  -(*len) = -1;
  +(*len) = 0;
   return APR_TIMEUP;
   }
   else if (srv  0) {
  -(*len) = -1;
  +(*len) = 0;
   return errno;
   }
   else {
   do {
   rv = write(sock-socketdes, buf, (*len));
   } while (rv == -1  errno == EINTR);
  +if (rv == -1) {
  +(*len) = 0;
  +return errno;
  +}
   }
   }
   (*len) = rv;
  @@ -175,6 +179,10 @@
   do {
   rv = read(sock-socketdes, buf, (*len));
   } while (rv == -1  errno == EINTR);
  +if (rv == -1) {
  +(*len) = 0;
  +return errno;
  +}
   }
   }
   else if (rv == -1  errno == EAGAIN  sock-timeout == 0) {
  
  
  


cvs commit: apache-2.0/src/lib/apr/network_io/unix sendrecv.c

2000-01-26 Thread stoddard
stoddard00/01/25 21:01:19

  Modified:src/os/unix iol_socket.c
   src/lib/apr/network_io/unix sendrecv.c
  Log:
  Fix a couple of bugs in the Unix side of the house. Not tested (no machine 
available).
  First bug: Use ap_sendv to implement iol_writev. The previous implementation 
would
  only send the first buffer in the chain.
  
  Second bug: ap_sendfile() on HP needs to put all the headers (trailers) into 
a single
  header (trailer) buffer. The data was not being copied into the buffers 
correctly.
  
  Revision  ChangesPath
  1.14  +1 -2  apache-2.0/src/os/unix/iol_socket.c
  
  Index: iol_socket.c
  ===
  RCS file: /home/cvs/apache-2.0/src/os/unix/iol_socket.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- iol_socket.c  2000/01/19 01:16:21 1.13
  +++ iol_socket.c  2000/01/26 05:01:13 1.14
  @@ -109,8 +109,7 @@
   static ap_status_t unix_writev(ap_iol *viol, const struct iovec *vec, int 
nvec,
   ap_ssize_t *nbytes)
   {
  -*nbytes = vec[0].iov_len;
  -return ap_send(((iol_socket *)viol)-sock, vec[0].iov_base, nbytes);
  +return ap_sendv(((iol_socket *)viol)-sock, vec, nvec, nbytes);
   }
   
   static ap_status_t unix_read(ap_iol *viol, char* buf, ap_size_t size,
  
  
  
  1.9   +2 -2  apache-2.0/src/lib/apr/network_io/unix/sendrecv.c
  
  Index: sendrecv.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- sendrecv.c1999/12/04 21:48:34 1.8
  +++ sendrecv.c2000/01/26 05:01:16 1.9
  @@ -465,7 +465,7 @@
   headerbuf = ap_palloc(sock-cntxt, headerlen);
   
   for (i = 0; i  hdtr-numheaders; i++) {
  -memcpy(headerbuf, hdtr-headers[i].iov_base + ptr,
  +memcpy(headerbuf + ptr, hdtr-headers[i].iov_base,
  hdtr-headers[i].iov_len);
   ptr += hdtr-headers[i].iov_len;
   }
  @@ -477,7 +477,7 @@
   trailerbuf = ap_palloc(sock-cntxt, trailerlen);
   
   for (i = 0; i  hdtr-numtrailers; i++) {
  -memcpy(trailerbuf, hdtr-trailers[i].iov_base + ptr,
  +memcpy(trailerbuf + ptr, hdtr-trailers[i].iov_base,
  hdtr-trailers[i].iov_len);
   ptr += hdtr-trailers[i].iov_len;
   }
  
  
  


cvs commit: apache-2.0/src/lib/apr/network_io/unix sendrecv.c sockopt.c

1999-11-10 Thread rbb
rbb 99/11/10 07:49:57

  Modified:src/lib/apr/file_io/unix fileio.h open.c pipe.c readwrite.c
   src/lib/apr/include apr_file_io.h
   src/lib/apr/network_io/unix sendrecv.c sockopt.c
  Log:
  Add timeouts to pipes.  I also fixed a minor bug in timeout code for sending
  and receiving data over the network.  Specifying a negative timeout will
  result in the send or recv blocking until the operation is done.
  
  Revision  ChangesPath
  1.4   +1 -0  apache-2.0/src/lib/apr/file_io/unix/fileio.h
  
  Index: fileio.h
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileio.h,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- fileio.h  1999/10/12 20:00:30 1.3
  +++ fileio.h  1999/11/10 15:49:53 1.4
  @@ -85,6 +85,7 @@
   time_t atime;
   time_t mtime;
   time_t ctime;
  +int timeout;
   };
   
   struct dir_t {
  
  
  
  1.22  +7 -0  apache-2.0/src/lib/apr/file_io/unix/open.c
  
  Index: open.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/open.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- open.c1999/11/04 22:04:16 1.21
  +++ open.c1999/11/10 15:49:53 1.22
  @@ -177,6 +177,7 @@
   }
   
   (*new)-stated = 0;  /* we haven't called stat for this file yet. */
  +(*new)-timeout = -1;
   (*new)-eof_hit = 0;
   ap_register_cleanup((*new)-cntxt, (void *)(*new), file_cleanup,
   ap_null_cleanup);
  @@ -257,6 +258,12 @@
   (*file) = ap_pcalloc(cont, sizeof(struct file_t));
   (*file)-cntxt = cont;
   }
  +/* if we are putting in a new file descriptor, then we don't really
  + * have any of this information.
  + */
  +(*file)-eof_hit = 0;
  +(*file)-timeout = -1;
  +(*file)-stated = 0;
   (*file)-filedes = *dafile;
   return APR_SUCCESS;
   }
  
  
  
  1.5   +44 -0 apache-2.0/src/lib/apr/file_io/unix/pipe.c
  
  Index: pipe.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/pipe.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- pipe.c1999/11/01 03:07:07 1.4
  +++ pipe.c1999/11/10 15:49:53 1.5
  @@ -63,7 +63,46 @@
   #include sys/types.h
   #include sys/stat.h
   
  +static ap_status_t pipenonblock(struct file_t *thefile)
  +{
  +int fd_flags;
  +
  +fd_flags = fcntl(thefile-filedes, F_GETFL, 0);
  +#if defined(O_NONBLOCK)
  +fd_flags |= O_NONBLOCK;
  +#elif defined(O_NDELAY)
  +fd_flags |= O_NDELAY;
  +#elif defined(FNDELAY)
  +fd_flags |= O_FNDELAY;
  +#else
  +/* : this breaks things, but an alternative isn't obvious...*/
  +return -1;
  +#endif
  +if (fcntl(thefile-filedes, F_SETFL, fd_flags) == -1) {
  +return errno;
  +}
  +return APR_SUCCESS;
  +}
  +
   /* ***APRDOC
  + * ap_status_t ap_set_pipe_timeout(ap_file_t *, ap_int32_t)
  + *Set the timeout value for a pipe.
  + * arg 1) The pipe we are setting a timeout on.
  + * arg 3) The timeout value in seconds.  Values  0 mean wait forever, 0
  + *means do not wait at all.
  + */
  +ap_status_t ap_set_pipe_timeout(struct file_t *thepipe, ap_int32_t timeout)
  +{
  +if (!strcmp(thepipe-fname, PIPE)) {
  +thepipe-timeout = timeout;
  +return APR_SUCCESS;
  +}
  +return APR_EINVAL;
  +}
  +
  +
  +
  +/* ***APRDOC
* ap_status_t ap_create_pipe(ap_file_t **, ap_context_t *, ap_file_t **)
*Create an anonymous pipe.
* arg 1) The context to operate on.
  @@ -83,12 +122,17 @@
   (*in)-filedes = filedes[0];
   (*in)-buffered = 0;
   (*in)-fname = ap_pstrdup(cont, PIPE);
  +(*in)-timeout = -1;
   
   (*out) = (struct file_t *)ap_palloc(cont, sizeof(struct file_t));
   (*out)-cntxt = cont;
   (*out)-filedes = filedes[1];
   (*out)-buffered = 0;
   (*out)-fname = ap_pstrdup(cont, PIPE);
  +(*out)-timeout = -1;
  +
  +pipenonblock(*in);
  +pipenonblock(*out);
   
   return APR_SUCCESS;
   }
  
  
  
  1.16  +81 -4 apache-2.0/src/lib/apr/file_io/unix/readwrite.c
  
  Index: readwrite.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/readwrite.c,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- readwrite.c   1999/11/04 07:24:23 1.15
  +++ readwrite.c   1999/11/10 15:49:53 1.16
  @@ -70,6 +70,9 @@
   #ifdef HAVE_SYS_UIO_H
   #include sys/uio.h
   #endif
  +#ifdef HAVE_SYS_TIME_H
  +#include sys/time.h
  +#endif
   
   /* 

cvs commit: apache-2.0/src/lib/apr/network_io/unix sendrecv.c sockets.c

1999-09-02 Thread rbb
rbb 99/09/02 13:33:43

  Modified:src/lib/apr/include apr_network_io.h
   src/lib/apr/network_io/unix sendrecv.c sockets.c
  Log:
  Add some network API's to APR.
  
  Revision  ChangesPath
  1.2   +2 -0  apache-2.0/src/lib/apr/include/apr_network_io.h
  
  Index: apr_network_io.h
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_network_io.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- apr_network_io.h  1999/08/17 15:59:37 1.1
  +++ apr_network_io.h  1999/09/02 20:33:32 1.2
  @@ -117,6 +117,8 @@
   
   ap_status_t ap_setsocketopt(ap_socket_t *, ap_int32_t, ap_int32_t);
   ap_status_t ap_setport(ap_socket_t *, ap_uint32_t);
  +ap_status_t ap_setipaddr(ap_socket_t *, const char *);
  +ap_status_t ap_getport(ap_socket_t *, ap_uint32_t *);
   
   ap_status_t ap_setup_poll(ap_context_t *, ap_int32_t, ap_pollfd_t **);
   ap_status_t ap_poll(ap_pollfd_t *, ap_int32_t *, ap_int32_t);
  
  
  
  1.2   +24 -17apache-2.0/src/lib/apr/network_io/unix/sendrecv.c
  
  Index: sendrecv.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sendrecv.c1999/08/17 15:59:43 1.1
  +++ sendrecv.c1999/09/02 20:33:36 1.2
  @@ -68,10 +68,8 @@
* arg 2) The buffer which contains the data to be sent. 
* arg 3) The maximum number of bytes to send 
* arg 4) The amount of time in seconds to try sending this data. 
  - * NOTE: The number of bytes actually sent is stored in argument 3.  It is
  - *   not currently possible to have this behave like a blocking write.  
  - *   If the timeout is zero, it will try to send the data, and return
  - *   immediately.
  + * NOTE: The number of bytes actually sent is stored in argument 3.  To have
  + *   this behave like a non-blocking write, us a timeout of -1. 
*/
   ap_status_t ap_send(struct socket_t *sock, const char *buf, ap_ssize_t *len, 
time_t sec)
   {
  @@ -82,17 +80,22 @@
   } while (rv == -1  errno == EINTR);
   
   if (rv == -1  errno == EAGAIN  sec  0) {
  -struct timeval tv;
  +struct timeval *tv;
   fd_set fdset;
   int srv;
   
   do {
   FD_ZERO(fdset);
   FD_SET(sock-socketdes, fdset);
  -tv.tv_sec  = sec;
  -tv.tv_usec = 0;
  -
  -srv = select(FD_SETSIZE, NULL, fdset, NULL, tv);
  +if (sec == -1) {
  +tv = NULL;
  +}
  +else {
  +tv = ap_palloc(sock-cntxt, sizeof(struct timeval));
  +tv-tv_sec  = sec;
  +tv-tv_usec = 0;
  +}
  +srv = select(FD_SETSIZE, NULL, fdset, NULL, tv);
   } while (srv == -1  errno == EINTR);
   
   if (srv == 0) {
  @@ -120,10 +123,8 @@
* arg 2) The buffer to store the data in. 
* arg 3) The maximum number of bytes to read 
* arg 4) The amount of time in seconds to try reading data. 
  - * NOTE: The number of bytes actually read is stored in argument 3.  It is
  - *   not currently possible to have this behave like a blocking read.  
  - *   If the timeout is zero, it will try to read data, and return
  - *   immediately.
  + * NOTE: The number of bytes actually sent is stored in argument 3.  To have
  + *   this behave like a non-blocking write, us a timeout of -1. 
*/
   ap_status_t ap_recv(struct socket_t *sock, char *buf, ap_ssize_t *len, 
time_t sec)
   {
  @@ -134,17 +135,23 @@
   } while (rv == -1  errno == EINTR);
   
   if (rv == -1  errno == EAGAIN  sec  0) {
  -struct timeval tv;
  +struct timeval *tv;
   fd_set fdset;
   int srv;
   
   do {
   FD_ZERO(fdset);
   FD_SET(sock-socketdes, fdset);
  -tv.tv_sec  = sec;
  -tv.tv_usec = 0;
  +if (sec == -1) {
  +tv = NULL;
  +}
  +else {
  +tv = ap_palloc(sock-cntxt, sizeof(struct timeval));
  +tv-tv_sec  = sec;
  +tv-tv_usec = 0;
  +}
   
  -srv = select(FD_SETSIZE, fdset, NULL, NULL, tv);
  +srv = select(FD_SETSIZE, fdset, NULL, NULL, tv);
   } while (srv == -1  errno == EINTR);
   
   if (srv == 0) {
  
  
  
  1.2   +44 -14apache-2.0/src/lib/apr/network_io/unix/sockets.c
  
  Index: sockets.c
  ===
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/sockets.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sockets.c 1999/08/17 15:59:43 1.1
  +++ sockets.c 1999/09/02 20:33:36