tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/native/common jk_shm.c
Date Sun, 06 Feb 2005 11:20:49 GMT
mturk       2005/02/06 03:20:49

  Modified:    jk/native/common jk_shm.c
  Log:
  Use plain memory if shmem filename was not defined.
  This enable transparent API, regardles of shm type and JkShmFile.
  
  Revision  Changes    Path
  1.4       +37 -15    jakarta-tomcat-connectors/jk/native/common/jk_shm.c
  
  Index: jk_shm.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native/common/jk_shm.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- jk_shm.c	6 Feb 2005 10:35:55 -0000	1.3
  +++ jk_shm.c	6 Feb 2005 11:20:49 -0000	1.4
  @@ -85,8 +85,6 @@
       }
   }
   
  -
  -
   #else
   
   #include <unistd.h>
  @@ -110,48 +108,68 @@
       int fd;
       int flags = O_RDWR;
   
  -    if (!attached)
  -        flags |= (O_CREAT|O_TRUNC);
  -    fd = open(fname, flags, 0666);
  -    if (fd == -1)
  -        return -1;
  +    shm->size = 0;
  +    shm->base = NULL;
   
       if (workers < 1 || workers > JK_SHM_MAX_WORKERS)
           workers = JK_SHM_MAX_WORKERS;
       if (dynamic < 1 || dynamic > JK_SHM_MAX_WORKERS)
           dynamic = JK_SHM_MAX_WORKERS;
   
  +    shm->filename = fname;
  +    shm->attached = attached;
       shm->size = sizeof(jk_shm_h_rec_t) + (workers + dynamic) * sizeof(jk_shm_w_rec_t);
   
  +    /* Use plain memory in case there is no file name */
  +    if (!fname) {
  +        shm->base = calloc(1, shm->size);
  +        if (!shm->base)
  +            return -1;
  +        hdr = (jk_shm_h_rec_t *)shm->base;
  +
  +        memcpy(hdr->magic, shm_signature, 8);
  +        hdr->workers = workers;
  +        hdr->dynamic = dynamic;
  +        return 0;
  +    }
  +    if (!attached)
  +        flags |= (O_CREAT|O_TRUNC);
  +    fd = open(fname, flags, 0666);
  +    if (fd == -1) {
  +        shm->size = 0;
  +        return -1;
  +    }
  +
       if (!attached) {
           size_t size = lseek(fd, 0, SEEK_END);
           if (size < shm->size) {
               size = shm->size;
               if (ftruncate(fd, shm->size)) {
                   close(fd);
  +                shm->size = 0;
                   return -1;
               }
           }
       }
       if (lseek(fd, 0, SEEK_SET) != 0) {
           close(fd);
  +        shm->size = 0;
           return -1;
       }
   
       shm->base = mmap(NULL, shm->size,
  -                    PROT_READ | PROT_WRITE,
  -                    MAP_FILE | MAP_SHARED,
  -                    fd, 0);
  +                     PROT_READ | PROT_WRITE,
  +                     MAP_FILE | MAP_SHARED,
  +                     fd, 0);
       if (shm->base == (void *)MAP_FAILED) {
           shm->base = NULL;
       }
       if (!shm->base) {
           close(fd);
  +        shm->size = 0;
           return -1;
       }
  -    shm->filename = fname;
       shm->fd = fd;
  -    shm->attached = attached;
   
       /* Clear shared memory */
       if (!attached) {
  @@ -185,8 +203,12 @@
   {
       if (shm) {
           if (shm->base) {
  -            munmap(shm->base, shm->size);
  -            close(shm->fd);
  +            if (shm->fd >= 0) {
  +                munmap(shm->base, shm->size);
  +                close(shm->fd);
  +            }
  +            else
  +                free(shm->base);
           }
           shm->base = NULL;
           shm->fd = -1;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org


Mime
View raw message