stoddard    99/09/24 11:58:43

  Modified:    src/include ap_iol.h
               src/main buff.c iol_file.c
  Log:
  Adapt file iol to use APR functions. Replaced ap_open_file() with 
ap_create_file_iol(). ap_create_file_iol() requires that the file be opened 
prior to the call using ap_open().
  
  Revision  Changes    Path
  1.5       +1 -2      apache-2.0/src/include/ap_iol.h
  
  Index: ap_iol.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/include/ap_iol.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ap_iol.h  1999/06/28 19:00:48     1.4
  +++ ap_iol.h  1999/09/24 18:58:10     1.5
  @@ -127,7 +127,6 @@
   #define iol_getopt(iol, a, b) ((iol)->methods->getopt((iol), (a), (b)))
   
   /* the file iol */
  -/* TODO: use APR instead of unix semantics for this */
  -ap_iol *ap_open_file(const char *name, int flags, int mask);
  +ap_iol *ap_create_file_iol(ap_file_t *file);
   
   #endif
  
  
  
  1.5       +7 -2      apache-2.0/src/main/buff.c
  
  Index: buff.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/buff.c,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- buff.c    1999/08/31 05:32:55     1.4
  +++ buff.c    1999/09/24 18:58:30     1.5
  @@ -936,8 +936,13 @@
   {
       ap_iol *iol;
       BUFF *fb;
  -
  -    iol = ap_open_file(name, flg, mode);
  +    ap_status_t rv;
  +    ap_file_t *file;
  +    rv = ap_open(a, name, flg, 0, &file);
  +    if ((rv != APR_SUCCESS) || (file == NULL)) {
  +        return NULL;
  +    }
  +    iol = ap_create_file_iol(file);
       if (!iol) {
           return NULL;
       }
  
  
  
  1.3       +78 -0     apache-2.0/src/main/iol_file.c
  
  Index: iol_file.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/iol_file.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- iol_file.c        1999/06/28 19:00:49     1.2
  +++ iol_file.c        1999/09/24 18:58:35     1.3
  @@ -58,6 +58,7 @@
   #include "httpd.h"
   #include "ap_iol.h"
   
  +#if 0
   #include <sys/uio.h>
   
   typedef struct {
  @@ -82,6 +83,7 @@
   method(writev, (ap_iol *viol, const struct iovec *arg1, int arg2))
   method(read, (ap_iol *viol, char *arg1, int arg2))
   
  +
   static int file_close(ap_iol *viol)
   {
       iol_file *iol = (iol_file *)viol;
  @@ -130,3 +132,79 @@
       iol->fd = rv;
       return (ap_iol *)iol;
   }
  +#else
  +
  +typedef struct {
  +    ap_iol iol;
  +    ap_file_t *file;
  +} iol_file;
  +
  +/* TODO: I am not sure I have the return codes right... 
  + * and errno has got to go. It is not thread safe on WIn32...
  + */
  +#define method(syscall, args)        \
  +    static int file_##syscall args \
  +    { \
  +        ap_status_t rv; \
  +     iol_file *iol = (iol_file *)viol; \
  +     int cnt = arg2; \
  +     /* try writing, ignoring EINTR, the upper layer has to handle \
  +         partial read/writes anyhow, so we can return early */ \
  +     do { \
  +         rv = syscall(iol->file, (void*)arg1, &cnt); \
  +     } while (rv == APR_EINTR); \
  +     return cnt; \
  +    }
  +
  +method(ap_write, (ap_iol *viol, const char *arg1, int arg2))
  +method(ap_writev, (ap_iol *viol, const struct iovec *arg1, int arg2))
  +method(ap_read, (ap_iol *viol, char *arg1, int arg2))
  +
  +
  +/* This function will clean-up the iol struct and close the file... */
  +static int file_close(ap_iol *viol)
  +{
  +    ap_status_t rv;
  +    iol_file *iol = (iol_file *)viol;
  +    rv = ap_close(iol->file);
  +    free(iol);
  +
  +    if (rv == APR_SUCCESS)
  +        return 0;
  +    else
  +        return -1;
  +}
  +
  +static int file_setopt(ap_iol *viol, ap_iol_option opt, const void *value)
  +{
  +    errno = EINVAL;
  +    return -1;
  +}
  +
  +static int file_getopt(ap_iol *viol, ap_iol_option opt, void *value)
  +{
  +    errno = EINVAL;
  +    return -1;
  +}
  +
  +static const ap_iol_methods file_methods = {
  +    file_close,
  +    file_ap_write,
  +    file_ap_writev,
  +    file_ap_read,
  +    file_setopt,
  +    file_getopt
  +};
  +
  +/*
  + * Create an ap_iol struct given an apr_file_t
  + */
  +ap_iol *ap_create_file_iol(ap_file_t *file)
  +{
  +    iol_file *iol;
  +    iol = malloc(sizeof(iol_file));
  +    iol->iol.methods = &file_methods;
  +    iol->file = file;
  +    return (ap_iol *)iol;
  +}
  +#endif
  
  
  

Reply via email to