You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@locus.apache.org on 2000/05/25 00:32:50 UTC

cvs commit: apache-2.0/src/lib/apr/test testfile.c

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");
  
  
  

Re: cvs commit: apache-2.0/src/lib/apr/test testfile.c

Posted by Greg Stein <gs...@lyra.org>.
On Thu, 25 May 2000, Brian Havard wrote:
>...
> >  +/* 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
> 
> For OS/2 this isn't true, as you suspect. I think BeOS also.

Presuming that we can't detect it thru autoconf, then we can easily handle
the tweak using 'hints.m4'

Cheers,
-g

-- 
Greg Stein, http://www.lyra.org/


Re: cvs commit: apache-2.0/src/lib/apr/test testfile.c

Posted by rb...@covalent.net.
> >  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.  :-|
> 
> Why do we need this?

Because we need to be able to poll on a file/pipe.  Currently, APR doesn't
allow this, with this change platforms that support it can do it.  For the
Unix MPM's, where we are using a pipe to communicate between parent and
child, this is essential.

> >  +/* 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
> 
> For OS/2 this isn't true, as you suspect. I think BeOS also.

Okay, I'll come up with an Autoconf test.

Ryan

_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Re: cvs commit: apache-2.0/src/lib/apr/test testfile.c

Posted by Brian Havard <br...@kheldar.apana.org.au>.
On 24 May 2000 22:32:50 -0000, rbb@locus.apache.org wrote:

>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.  :-|

Why do we need this?



>  +/* 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

For OS/2 this isn't true, as you suspect. I think BeOS also.

-- 
 ______________________________________________________________________________
 |  Brian Havard                 |  "He is not the messiah!                   |
 |  brianh@kheldar.apana.org.au  |  He's a very naughty boy!" - Life of Brian |
 ------------------------------------------------------------------------------