httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/apr/test testfile.c
Date Wed, 24 May 2000 22:32:50 GMT
rbb         00/05/24 15:32:47

  Modified:    src/lib/apr/file_io/unix fileacc.c
               src/lib/apr/include apr.h.in apr_network_io.h
               src/lib/apr/network_io/unix poll.c
               src/lib/apr/test testfile.c
  Log:
  Add a new APR function.  This function basically lets a file masquerade as
  a socket so that we can poll on it.  This is not my favorite idea, but
  since some platforms don't allow us to poll files and some do, we have to
  find a happy medium, this is it.  :-|
  
  Revision  Changes    Path
  1.28      +0 -1      apache-2.0/src/lib/apr/file_io/unix/fileacc.c
  
  Index: fileacc.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/unix/fileacc.c,v
  retrieving revision 1.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- fileacc.c	2000/05/17 22:06:15	1.27
  +++ fileacc.c	2000/05/24 22:32:28	1.28
  @@ -132,4 +132,3 @@
           return APR_ENOFILE;
       }
   }
  -
  
  
  
  1.24      +8 -0      apache-2.0/src/lib/apr/include/apr.h.in
  
  Index: apr.h.in
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr.h.in,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- apr.h.in	2000/05/18 02:17:22	1.23
  +++ apr.h.in	2000/05/24 22:32:34	1.24
  @@ -66,6 +66,14 @@
   #define APR_HAS_XLATE             @iconv@
   #define APR_HAS_OTHER_CHILD       @oc@
   
  +/* Any time a file and socket are represented as the same type, this macro
  + * should be true.  I don't know of any platforms using Autoconf where this
  + * isn't true (OS/2? maybe), but I know it isn't true for Windows.  For right
  + * now, just define it as 1, and Windows will define it correctly, if this
  + * turns out to not work, we can devise an Autoconf test for it later.  rbb
  + */
  +#define APR_FILES_AS_SOCKETS      1
  +
   /* Typedefs that APR needs. */
   
   typedef  @short_value@           ap_int16_t;
  
  
  
  1.36      +18 -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.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- apr_network_io.h	2000/05/12 00:14:42	1.35
  +++ apr_network_io.h	2000/05/24 22:32:36	1.36
  @@ -711,6 +711,24 @@
   ap_status_t ap_set_polldata(ap_pollfd_t *pollfd, void *data, char *key,
                               ap_status_t (*cleanup) (void *));
   
  +/*
  +
  +=head1 ap_status_t ap_socket_from_file(ap_socket_t **newsock, ap_file_t *file)
  +
  +B<Convert a File type to a socket so that it can be used in a poll operation.>
  +
  +    arg 1) the newly created socket which represents a file.
  +    arg 2) the file to mask as a socket.
  +
  +B<NOTE>: This is not available on all platforms.  Platforms that have the
  +         ability to poll files for data to be read/written/exceptions will
  +         have the APR_FILES_AS_SOCKETS macro defined as true.
  +
  +=cut
  + */
  +ap_status_t ap_socket_from_file(ap_socket_t **newsock, ap_file_t *file);
  +
  +
   /*  accessor functions   */
   
   #ifdef __cplusplus
  
  
  
  1.33      +14 -0     apache-2.0/src/lib/apr/network_io/unix/poll.c
  
  Index: poll.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/network_io/unix/poll.c,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- poll.c	2000/05/16 20:35:39	1.32
  +++ poll.c	2000/05/24 22:32:41	1.33
  @@ -53,6 +53,7 @@
    */
   
   #include "networkio.h"
  +#include "../../file_io/unix/fileio.h"
   
   #ifdef HAVE_POLL    /* We can just use poll to do our socket polling. */
   
  @@ -395,3 +396,16 @@
       }
   }
   
  +#if APR_FILES_AS_SOCKETS
  +/* I'm not sure if this needs to return an ap_status_t or not, but
  + * for right now, we'll leave it this way, and change it later if
  + * necessary.
  + */
  +ap_status_t ap_socket_from_file(ap_socket_t **newsock, ap_file_t *file)
  +{
  +    (*newsock) = ap_pcalloc(file->cntxt, sizeof(**newsock));
  +    (*newsock)->socketdes = file->filedes;
  +    (*newsock)->cntxt = file->cntxt;
  +    return APR_SUCCESS;
  +}
  +#endif
  
  
  
  1.13      +29 -0     apache-2.0/src/lib/apr/test/testfile.c
  
  Index: testfile.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/test/testfile.c,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- testfile.c	2000/04/14 15:58:44	1.12
  +++ testfile.c	2000/05/24 22:32:44	1.13
  @@ -55,6 +55,7 @@
   #include <stdio.h>
   #include <stdlib.h>
   #include "apr_file_io.h"
  +#include "apr_network_io.h"
   #include "apr_errno.h"
   #include "apr_general.h"
   #include "apr_lib.h"
  @@ -70,9 +71,12 @@
       ap_pool_t *context;
       ap_pool_t *cont2;
       ap_file_t *thefile = NULL;
  +    ap_socket_t *testsock = NULL;
  +    ap_pollfd_t *sdset = NULL;
       ap_status_t status = 0;
       ap_int32_t flag = APR_READ | APR_WRITE | APR_CREATE;
       ap_ssize_t nbytes = 0;
  +    ap_int32_t rv;
       ap_off_t zer = 0;
       char *buf;
       char *str;
  @@ -142,6 +146,31 @@
       else {
           fprintf(stdout, "OK\n");
       }
  +
  +#if APR_FILES_AS_SOCKETS
  +    fprintf(stdout, "\tThis platform supports files_like_sockets\n");
  +    fprintf(stdout, "\t\tMaking file look like a socket.......");
  +    if (ap_socket_from_file(&testsock, thefile) != APR_SUCCESS) {
  +        perror("Something went wrong");
  +        exit(-1);
  +    }
  +    fprintf(stdout, "OK\n");
  +
  +    fprintf(stdout, "\t\tChecking for incoming data.......");
  +    ap_setup_poll(&sdset, 1, context);
  +    ap_add_poll_socket(sdset, testsock, APR_POLLIN);
  +    rv = 1;
  +    if (ap_poll(sdset, &rv, -1) != APR_SUCCESS) {
  +        fprintf(stderr, "Select caused an error\n");
  +        exit(-1);
  +    }
  +    else if (rv == 0) {
  +        fprintf(stderr, "I should not return until rv == 1\n");
  +        exit(-1);
  +    }
  +    fprintf(stdout, "OK\n");
  +#endif
  +
   
       fprintf(stdout, "\tReading from the file.......");
       nbytes = (ap_ssize_t)strlen("this is a test");
  
  
  

Mime
View raw message