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/native2/common jk_shm.c
Date Fri, 12 Mar 2004 19:15:56 GMT
mturk       2004/03/12 11:15:56

  Modified:    jk/native2/common jk_shm.c
  Log:
  Total rewrite...
  Allows using anonymous shared memory or file based.
  Also allow usage of raw memory in case there is no shmem support.
  Added two new setup direcives: slots (manages max number of slots),
  and memory that when set uses malloc'd memory instead shmem.
  If the file name starts with 'anon' try using anonymous memory.
  Shmem uses create/attach mechanism so please test.
  
  Revision  Changes    Path
  1.40      +205 -370  jakarta-tomcat-connectors/jk/native2/common/jk_shm.c
  
  Index: jk_shm.c
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/native2/common/jk_shm.c,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- jk_shm.c	11 Mar 2004 15:32:38 -0000	1.39
  +++ jk_shm.c	12 Mar 2004 19:15:56 -0000	1.40
  @@ -15,14 +15,6 @@
    */
   
   /**
  - * Scoreboard - used for communication on multi-process servers.
  - *
  - * This is an optional component - will be enabled only if APR is used. 
  - * The code is cut&pasted from apache and mod_jserv.
  - *
  - * 
  - * 
  - * @author Jserv and Apache people
    */
   
   #include "jk_global.h"
  @@ -30,23 +22,11 @@
   #include "jk_pool.h"
   #include "jk_shm.h"
   
  -/* global.h will include apr.h. If APR and mmap is compiled in, we'll use
  -   it. If APR is not availalbe, we use mmap directly - the code worked fine
  -   for jserv.
  -*/
  -#if APR_HAS_MMAP
  -
  -#include "apr_mmap.h"
  -#include "apr_file_io.h"
  -#include "apr_file_info.h"
  +#include "apr_shm.h"
  +#include "apr_rmm.h"
  +#include "apr_errno.h"
   #include "apr_general.h"
  -
  -#elif defined(HAVE_MMAP) && !defined(WIN32)
  -
  -#include <sys/mman.h>
  -#include <fcntl.h>
  -
  -#endif
  +#include "apr_lib.h" 
   
   
   #define SHM_WRITE_SLOT 2
  @@ -54,276 +34,147 @@
   #define SHM_DUMP 6
   
   
  -#if (APR_HAS_MMAP == 1)
  -
  -static int JK_METHOD jk2_shm_destroy(jk_env_t *env, jk_shm_t *shm)
  +static int JK_METHOD jk2_shm_destroy(jk_env_t *env, jk_shm_t *shmem)
   {
  -    apr_mmap_t *aprShm=(apr_mmap_t *)shm->privateData;
  +    apr_status_t rv = APR_SUCCESS;
  +#if APR_HAS_SHARED_MEMORY
  +    apr_shm_t *shm = (apr_shm_t *)shmem->privateData;
  +
  +    if (shm) {
  +        if (shmem->attached)
  +            rv = apr_shm_detach(shm);
  +        else
  +            rv = apr_shm_destroy(shm);
  +    }
  +#endif
  +    shmem->head = NULL;
  +    shmem->image = NULL;
   
  -    if( aprShm==NULL )
  -        return JK_OK;
  -    
  -    return apr_mmap_delete(aprShm);
  +    return rv == APR_SUCCESS ? JK_OK : JK_ERR;
   }
   
  -static int jk2_shm_create(jk_env_t *env, jk_shm_t *shm)
  +static int jk2_shm_create(jk_env_t *env, jk_shm_t *shmem)
   {
  -    apr_status_t rc;
  -    apr_file_t *file;
  -    apr_finfo_t finfo;
  -    apr_mmap_t *aprMmap;
  +    apr_status_t rc = APR_EGENERAL;
  +    apr_shm_t *shm = NULL;
       apr_pool_t *globalShmPool;
   
  -    globalShmPool= (apr_pool_t *)env->getAprPool( env );
  +    globalShmPool = (apr_pool_t *)env->getAprPool(env);
   
  -    if( globalShmPool==NULL )
  +    if (!globalShmPool) {
           return JK_ERR;
  -
  -    /* Check if the scoreboard is in a note. That's the only way we
  -       can get HP-UX to work
  -    */
  -    apr_pool_userdata_get( & shm->image, "mod_jk_shm",globalShmPool );
  -    if( shm->image!=NULL ) {
  -        shm->head = (jk_shm_head_t *)shm->image;
  -
  -        if( shm->mbean->debug > 0 )
  -            env->l->jkLog(env, env->l, JK_LOG_DEBUG, 
  -                          "shm.create(): GLOBAL_SHM  %#lx\n", shm->image );
  -        return JK_OK;
  -    } else {
  -        if( shm->mbean->debug > 0 )
  -            env->l->jkLog(env, env->l, JK_LOG_DEBUG, 
  -                          "shm.create(): NO GLOBAL_SHM  %#lx\n", shm->image );
       }
       
  -
  -    /* First make sure the file exists and is big enough
  -     */
  -    rc=apr_file_open( &file, shm->fname,
  -                      APR_READ | APR_WRITE | APR_CREATE | APR_BINARY,
  -                      APR_OS_DEFAULT, globalShmPool);
  -    if (rc) {
  -        char error[256];
  -        apr_strerror( rc, error, 256 );
  -        
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): error opening file %s %d %s\n",
  -                      shm->fname, rc, error );
  -        shm->privateData=NULL;
  -        return JK_ERR;
  -    } 
  -
  -    rc=apr_file_info_get(&finfo, APR_FINFO_SIZE, file);
  -
  -    if( shm->mbean->debug > 0 )
  -        env->l->jkLog(env, env->l, JK_LOG_DEBUG, 
  -                      "shm.create(): file open %s %d %d\n", shm->fname, shm->size,
(int) finfo.size );
  -
  -    if( (int) finfo.size < shm->size ) {
  -        char bytes[1024];
  -        apr_size_t toWrite = (apr_size_t)(shm->size-finfo.size);
  -        apr_off_t off=0;
  -        
  -        memset( bytes, 0, 1024 );        
  -        apr_file_seek( file, APR_END, &off);
  -
  -        while( toWrite > 0 ) {
  -            apr_size_t written;
  -            rc=apr_file_write_full(file, bytes, 1024, &written);
  -            if( rc!=APR_SUCCESS ) {
  -                env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                              "shm.create(): Can't write %s %d %s\n",
  -                              shm->fname, errno, strerror( errno ));
  -                return JK_ERR;
  -            }
  -            if( toWrite < written  ){
  -                toWrite=0;
  -            }else{
  -                toWrite-=written;
  -            }
  -        }
  -        
  -        rc=apr_file_info_get(&finfo, APR_FINFO_SIZE, file);
  -    }
  -     
  -    /* Now mmap it
  -     */
  -    rc=apr_mmap_create( &aprMmap,  file, (apr_off_t)0,
  -                        (apr_size_t)finfo.size, APR_MMAP_READ | APR_MMAP_WRITE,
  -                        globalShmPool );
  -    if( rc ) {
  -        char error[256];
  -        apr_strerror( rc, error, 256 );
  -        
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): error creating %s %d %d %#lx %s\n",
  -                      shm->fname, (int) finfo.size, (int) rc, globalShmPool, error );
  -        shm->privateData=NULL;
  -        return JK_ERR;
  +    if (shmem->inmem) {
  +        shmem->head = apr_pcalloc(globalShmPool, sizeof(jk_shm_head_t) + shmem->slotMaxCount);
  +        shmem->image = apr_pcalloc(globalShmPool, shmem->slotMaxCount * shmem->slotSize);
  +        shmem->head->structSize = sizeof(jk_shm_head_t) + shmem->slotMaxCount;
  +        shmem->head->slotSize = shmem->slotSize;
  +        shmem->head->slotMaxCount = shmem->slotMaxCount;
  +        return JK_OK;
       }
  -
  -    shm->privateData=aprMmap;
  -
  -    apr_mmap_offset(& shm->image, aprMmap, (apr_off_t)0);
  -
  -    apr_pool_userdata_set( shm->image, "mod_jk_shm", NULL, globalShmPool );
  -        
  -    shm->head = (jk_shm_head_t *)shm->image;
  -
  -    if( shm->image==NULL ) {
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): No base memory %s\n", shm->fname);
  -        return JK_ERR;
  +#if APR_HAS_SHARED_MEMORY
  +    /* XXX: deal with anonymous */
  +    if (strncmp(shmem->fname, "anon", 4) == 0) {
  +        rc = apr_shm_create(&shm, shmem->size, NULL, globalShmPool);
  +        if (APR_STATUS_IS_ENOTIMPL(rc)) {
  +            env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  +                          "shm.create(): Anonymous shared memory not implemented %d\n");
  +            shmem->privateData=NULL;
  +            return JK_ERR;
  +        }
       }
  -
  -    return JK_OK;
  -}
  -
  -#elif defined(HAVE_MMAP) && !defined(WIN32)
  -
  -static int JK_METHOD jk2_shm_destroy(jk_env_t *env, jk_shm_t *shm)
  -{
  -    caddr_t shmf=(caddr_t)shm->privateData;
  -
  -    munmap(shmf, shm->size);
  -
  -    return JK_OK;
  -}
  -
  -static int jk2_shm_create(jk_env_t *env, jk_shm_t *shm)
  -{
  -    int rc;
  -    struct stat filestat;
  -
  -    int fd = open(shm->fname, O_RDWR|O_CREAT, 0777);
  -    
  -    if (fd == -1) {
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): Can't open %s %d %s\n",
  -                      shm->fname, errno, strerror( errno ));
  -        return JK_ERR;
  +    if (rc != APR_SUCCESS) {
  +        rc = apr_shm_create(&shm, shmem->size, shmem->fname, globalShmPool);
  +        if (rc == APR_EEXIST) {
  +            /*
  +            * The shm could have already been created (i.e. we may be a child process).
  +            * See if we can attach to the existing shared memory.
  +            */
  +            rc = apr_shm_attach(&shm, shmem->fname, globalShmPool); 
  +            shmem->attached = 1;
  +        }
       }
  +    if (rc != APR_SUCCESS) {
  +        char ebuf[256];
  +        apr_strerror(rc, ebuf, 256);
   
  -    rc=stat( shm->fname, &filestat);
  -    if ( rc == -1) {
           env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): Can't stat %s %d %s\n",
  -                      shm->fname, errno, strerror( errno ));
  +                      "shm.create(): error creating shm %d %s\n",
  +                      rc, ebuf);
  +        shmem->privateData = NULL;
           return JK_ERR;
  -    }
  -
  -    if( shm->mbean->debug > 0 )
  -        env->l->jkLog(env, env->l, JK_LOG_DEBUG, 
  -                      "shm.create(): file open %s %d %d\n", shm->fname, shm->size,
filestat.st_size );
  -
  -    if (filestat.st_size < shm->size ) {
  -        char bytes[1024];
  -        int toWrite=shm->size - filestat.st_size;
  -        
  -        memset( bytes, 0, 1024 );        
  -        lseek(fd, 0, SEEK_END);
  +    } 
  +    shmem->privateData = shm;
  +    shmem->head = (jk_shm_head_t *)apr_shm_baseaddr_get(shm);
   
  -        while( toWrite > 0 ) {
  -            int written;
  -            written=write(fd, bytes, 1024);
  -            if( written == -1 ) {
  -                env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                              "shm.create(): Can't write %s %d %s\n",
  -                              shm->fname, errno, strerror( errno ));
  -                return JK_ERR;
  -            }
  -            toWrite-=written;
  +    if (!shmem->attached) {
  +        /* Allocate header */
  +        apr_size_t head_size = sizeof(jk_shm_head_t) + shmem->slotMaxCount;
  +        /* align to slotSize */
  +        head_size = APR_ALIGN(head_size, shmem->slotSize);
  +        memset(shmem->head, 0, head_size);
  +        if (shmem->head) {
  +            shmem->head->structSize = (int)head_size;
  +            shmem->head->slotSize = shmem->slotSize;
  +            shmem->head->slotMaxCount = shmem->slotMaxCount;
           }
  -        
  -        rc=stat( shm->fname, &filestat);
  -        if ( rc == -1) {
  -            env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                          "shm.create(): Can't stat2 %s %d %s\n",
  -                          shm->fname, errno, strerror( errno ));
  -            return JK_ERR;
  -         }
  -    }
  -
  -    shm->privateData = mmap(NULL, filestat.st_size, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
  -
  -    if (shm->privateData == (caddr_t)-1 ||
  -        shm->privateData == NULL ) {
  -            env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                          "shm.create(): Can't mmap %s %d %s\n",
  -                          shm->fname, errno, strerror( errno ));
  +        env->l->jkLog(env, env->l, JK_LOG_INFO, 
  +                      "shm.create() Created head %#lx size %d\n",
  +                       shmem->head, head_size);
   
  -        close(fd);
  -        return JK_ERR;
       }
  -
  -    shm->image = (void *)shm->privateData;
  -    shm->head = (jk_shm_head_t *)shm->image;
  -    
  -    close(fd);
  -    
  -    return JK_OK;
  -}
  -
  -
  -#else
  -
  -static int JK_METHOD jk2_shm_destroy(jk_env_t *env, jk_shm_t *shm)
  -{
  +    else {
  +        shmem->slotSize = shmem->head->slotSize;
  +        shmem->slotMaxCount = shmem->head->slotMaxCount;
  +    }
  +    shmem->image = ((char *)apr_shm_baseaddr_get(shm)) + shmem->head->structSize;
  +#endif
       return JK_OK;
   }
   
   
  -static int jk2_shm_create(jk_env_t *env, jk_shm_t *shm)
  -{
  -    return JK_ERR;
  -}
  -
  -#endif
  -
  -
   /* Create or reinit an existing scoreboard. The MPM can control whether
    * the scoreboard is shared across multiple processes or not
    */
   static int JK_METHOD jk2_shm_init(struct jk_env *env, jk_shm_t *shm) {
  +    
       int rv=JK_OK;
       
  -    shm->privateData=NULL;
  +    shm->privateData = NULL;
   
  -    if( shm->fname==NULL ) {
  -        env->l->jkLog(env, env->l, JK_LOG_INFO, "shm.init(): shm file not specified\n");
  +    if (shm->fname == NULL) {
  +        env->l->jkLog(env, env->l, JK_LOG_INFO,
  +                      "shm.init(): shm file not specified\n");
           return JK_ERR;
       }
  +    if (!shm->slotMaxCount)
  +        shm->slotMaxCount = 1;
  +    shm->size = shm->slotSize * shm->slotMaxCount;
  +    shm->size += APR_ALIGN(sizeof(jk_shm_head_t) + shm->slotMaxCount, shm->slotSize);
  +    
  +    /* The smalles size is 64K */
  +    shm->size = APR_ALIGN(shm->size, 1024 * 64);
   
  -    /* make sure it's an absolute pathname */
  -    /*  fname = ap_server_root_relative(pconf, ap_scoreboard_fname); */
  -
  -    if( shm->size == 0  ) {
  -        shm->size = shm->slotSize * shm->slotMaxCount;
  -    }
  -
  -    if( shm->mbean->debug > 0 ) {
  -        env->l->jkLog(env, env->l, JK_LOG_DEBUG, "shm.init(): file=%s size=%d\n",
  +    if  (shm->mbean->debug > 0) {
  +        env->l->jkLog(env, env->l, JK_LOG_DEBUG,
  +                      "shm.init(): file=%s size=%d\n",
                         shm->fname, shm->size);
       }
   
  -    if( shm->size <= 0 ) {
  -        env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): No size %s\n", shm->fname);
  -        return JK_ERR;
  -    }
  -    
  -    rv=jk2_shm_create( env, shm );
  +    rv = jk2_shm_create(env, shm);
       
  -    if( rv!=JK_OK ) {
  +    if (rv != JK_OK) {
           env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.create(): error mmapping %s\n",
  -                      shm->fname );
  +                      "shm.create(): error creating shm %s\n",
  +                      shm->fname);
           return rv;
       }
   
  -    if( shm->mbean->debug > 0 )
  +    if (shm->mbean->debug > 0)
           env->l->jkLog(env, env->l, JK_LOG_DEBUG, 
  -                      "shm.create(): shm created %#lx\n", shm->head );
  +        "shm.create(): shm created %#lx %#lx %d\n",
  +        shm->head, shm->image, shm->attached);
   
       return JK_OK;
   }
  @@ -333,126 +184,96 @@
    */
   static int JK_METHOD jk2_shm_reset(jk_env_t *env, jk_shm_t *shm)
   {
  -    if( shm->head == NULL ) {
  +    if (shm->head == NULL) {
           return JK_ERR;
       }
  -    memset(shm->image, 0, shm->size);
   
       shm->head->slotSize = shm->slotSize;
       shm->head->slotMaxCount = shm->slotMaxCount;
  -    shm->head->lastSlot = 1;
  -
  -    if( shm->mbean->debug > 0 )
  +    shm->head->lastSlot = 0;
  +    memset(shm->head->slots, 0, shm->head->slotMaxCount); 
  +    if (shm->mbean->debug > 0) {
           env->l->jkLog(env, env->l, JK_LOG_DEBUG, "shm.init() Reset %s %#lx\n",
                         shm->fname, shm->image);
  -
  -    return JK_OK;
  -}
  -
  -static int jk2_shm_dump(jk_env_t *env, jk_shm_t *shm, char *name)
  -{
  -    FILE *f;
  -    int i;
  -
  -    env->l->jkLog(env, env->l, JK_LOG_INFO, "shm.dump(): Struct Size=%d slotSize=%d
slotCnt=%d head=%#lx\n",
  -                  shm->size, shm->slotSize, shm->slotMaxCount, shm->head );
  -
  -    if( shm->head==NULL ) return JK_ERR;
  -
  -    env->l->jkLog(env, env->l, JK_LOG_INFO, "shm.dump(): shmem  slotSize=%d slotCnt=%d
lastSlot=%d ver=%d\n",
  -                  shm->head->slotSize, shm->head->slotMaxCount, shm->head->lastSlot,
shm->head->lbVer );
  -
  -    for( i=1; i< shm->head->lastSlot; i++ ) {
  -        jk_shm_slot_t *slot=shm->getSlot( env, shm, i );
  -        jk_msg_t *msg;
  -
  -        if( slot==NULL ) continue;
  -        msg=jk2_msg_ajp_create2( env, env->tmpPool, slot->data, slot->size);
  -
  -        env->l->jkLog(env, env->l, JK_LOG_INFO, "shm.dump(): slot %d ver=%d size=%d
name=%s\n",
  -                      i, slot->ver, slot->size, slot->name );
  -
  -        msg->dump( env, msg, "Slot content ");
       }
  -    
  -    if( name==NULL ) return JK_ERR;
  -    
  -/* 
  - * XXX
  - * To be checked later, AS400 may need no ccsid 
  - * conversions applied if pure binary, for now 
  - * I assume stream is EBCDIC and need to be converted 
  - * in standard ASCII using codepage 819
  - */
  -#ifdef AS400
  -    f = fopen(name, "a+, o_ccsid=819");
  -#else
  -    f = fopen(name, "a+");
  -#endif        
  -
  -    fwrite( shm->head, 1, shm->size, f ); 
  -    fclose( f );
  -
  -    env->l->jkLog(env, env->l, JK_LOG_INFO, "shm.dump(): Dumped %d in %s\n",
  -                  shm->size, name);
  -    
       return JK_OK;
   }
   
   
   /* pos starts with 1 ( 0 is the head )
    */
  -jk_shm_slot_t * JK_METHOD jk2_shm_getSlot(struct jk_env *env, struct jk_shm *shm, int pos)
  +jk_shm_slot_t * JK_METHOD jk2_shm_getSlot(struct jk_env *env,
  +                                          struct jk_shm *shm, int pos)
   {
  -    char *ptr;
  -    if( pos==0 ) return NULL;
  -    if( shm->image==NULL ) return NULL;
  -    if( pos > shm->slotMaxCount ) return NULL;
  -    if( pos * shm->slotSize > shm->size ) return NULL;
  -
  -    /* Pointer aritmethic, I hope it's right */
  -    ptr = (void *) shm->image;
  -    ptr = ptr + (pos * shm->slotSize);
  -    return ((jk_shm_slot_t *) ptr);
  +    jk_shm_slot_t *slot = NULL;
  +
  +    if (!shm->image) 
  +        return NULL;
  +    if (pos >= shm->slotMaxCount)
  +        return NULL;
  +    /* Use only allocated slots */
  +    if (shm->head->slots[pos])
  +        slot = (jk_shm_slot_t *)((char *)shm->image + pos * shm->slotSize);
  +    if (slot) {
  +        env->l->jkLog(env, env->l, JK_LOG_INFO, 
  +                      "shm.getSlot() found existing slot %d %s\n",
  +                      pos * shm->slotSize,
  +                      slot->name);
  +    }
  +    return slot;
   }
   
  -jk_shm_slot_t * JK_METHOD jk2_shm_createSlot(struct jk_env *env, struct jk_shm *shm, 
  -                                  char *name, int size)
  +jk_shm_slot_t * JK_METHOD jk2_shm_createSlot(struct jk_env *env,
  +                                             struct jk_shm *shm, 
  +                                             char *name, int size)
   {
       /* For now all slots are equal size
        */
  -    int slotId;
       int i;
       jk_shm_slot_t *slot;
  -   
  -    if (shm->head!=NULL) { 
  -        for( i=1; i<shm->head->lastSlot; i++ ) {
  -            slot= shm->getSlot( env, shm, i );
  -            if( strncmp( slot->name, name, strlen(name) ) == 0 ) {
  +
  +    if (shm->head != NULL) { 
  +        for (i = 1; i < shm->head->lastSlot; i++) {
  +            slot = shm->getSlot(env, shm, i);
  +            if (strncmp(slot->name, name, strlen(name)) == 0) {
  +                env->l->jkLog(env, env->l, JK_LOG_INFO, 
  +                              "shm.createSlot() found existing slot %s\n",
  +                              slot->name);
                   return slot;
               }
           }
  -        /* New slot */
  -        /* XXX interprocess sync */
  -        slotId=shm->head->lastSlot++;
       }
       else {
           env->l->jkLog(env, env->l, JK_LOG_ERROR, 
                         "shm.createSlot() no shared memory head\n");
           return NULL;
       }
  -    slot=shm->getSlot( env, shm, slotId );
  -
  -    if( slot==NULL ) {
  +    /* Allocate new slot  
  +     * TODO: We need the mutex here
  +     */
  +    for (i = shm->head->lastSlot; i < shm->head->slotMaxCount; i++) {
  +        if (!shm->head->slots[i]) {
  +            slot = (jk_shm_slot_t *)((char *)shm->image + i * shm->head->slotSize);
  +            /* Mark the slot as used */
  +            shm->head->slots[i] = 1;
  +            /* Clear any garbage data */
  +            memset(slot, 0, shm->head->slotSize);
  +            ++shm->head->lastSlot;
  +            break;
  +        }
  +    }
  +    if (slot == NULL) {
           env->l->jkLog(env, env->l, JK_LOG_ERROR, 
  -                      "shm.createSlot() getSlot() returned NULL\n");
  +            "shm.createSlot() create %d returned NULL\n",
  +            shm->slotSize);
           return NULL;
       }
       
       env->l->jkLog(env, env->l, JK_LOG_INFO, 
  -                  "shm.createSlot() Create %d %#lx %#lx\n", slotId, shm->image, slot
);
  -    strncpy(slot->name, name, 64 );
  -    
  +                  "shm.createSlot() Created slot %d\n",
  +                  shm->head->lastSlot);
  +    strncpy(slot->name, name, 64);
  +    slot->size = size;
       return slot;
   }
   
  @@ -468,36 +289,42 @@
   {
       int i, j;
       
  -    if( shm==NULL || shm->head==NULL) {
  +    if (!shm || !shm->head) {
           return;
       }
       
  -    for( i=1; i < shm->head->lastSlot; i++ ) {
  -        jk_shm_slot_t *slot= shm->getSlot( env, shm, i );
  +    for (i = 0; i < shm->head->lastSlot; i++) {
  +        jk_shm_slot_t *slot = shm->getSlot(env, shm, i);
           
  -        if( slot==NULL ) continue;
  +        if (slot == NULL)
  +            continue;
           
  -        if( strncmp( slot->name, "epStat", 6 ) == 0 ) {
  +        if (strncmp(slot->name, "epStat", 6) == 0) {
               /* This is an endpoint slot */
  -            void *data=slot->data;
  +            void *data = slot->data;
   
  -            for( j=0; j<slot->structCnt ; j++ ) {
  -                jk_stat_t *statArray=(jk_stat_t *)data;
  -                jk_stat_t *stat=statArray + j;
  -
  -                stat->reqCnt=0;
  -                stat->errCnt=0;
  -                stat->totalTime=0;
  -                stat->maxTime=0;
  +            for (j = 0; j < slot->structCnt; j++) {
  +                jk_stat_t *statArray = (jk_stat_t *)data;
  +                jk_stat_t *stat = statArray + j;
  +
  +                stat->reqCnt = 0;
  +                stat->errCnt = 0;
  +                stat->totalTime = 0;
  +                stat->maxTime = 0;
               }
           }
       }    
   }
   
   
  -static char *jk2_shm_setAttributeInfo[]={"resetEndpointStats", "file", "size", NULL };
  +static char *jk2_shm_setAttributeInfo[] = {"resetEndpointStats",
  +                                           "file", "size",
  +                                           "slots", "memory",
  +                                           NULL};
   
  -static int JK_METHOD jk2_shm_setAttribute( jk_env_t *env, jk_bean_t *mbean, char *name,
void *valueP ) {
  +static int JK_METHOD jk2_shm_setAttribute(jk_env_t *env, jk_bean_t *mbean,
  +                                          char *name, void *valueP ) 
  +{
       jk_shm_t *shm=(jk_shm_t *)mbean->object;
       char *value=(char *)valueP;
       
  @@ -505,6 +332,10 @@
           shm->fname=value;
       } else if( strcmp( "size", name ) == 0 ) {
           shm->size=atoi(value);
  +    } else if( strcmp( "slots", name ) == 0 ) {
  +        shm->slotMaxCount=atoi(value);
  +    } else if( strcmp( "memory", name ) == 0 ) {
  +        shm->inmem=atoi(value);
       } else if( strcmp( "resetEndpointStats", name ) == 0 ) {
           if( strcmp( value, "1" )==0 )
               jk2_shm_resetEndpointStats( env, shm );
  @@ -524,22 +355,24 @@
       
       env->l->jkLog(env, env->l, JK_LOG_INFO, 
                     "shm.writeSlot() %s %d\n", instanceName, len );
  -    if( len > shm->slotSize ) {
  +    if ((size_t)len > (shm->slotSize - sizeof(jk_shm_slot_t))) {
           env->l->jkLog(env, env->l, JK_LOG_ERROR, 
                         "shm.writeSlot() Packet too large %d %d\n",
  -                      shm->slotSize, len );
  +                      shm->slotSize - sizeof(jk_shm_slot_t),
  +                      len);
           return JK_ERR;
       }
  -    if( shm->head == NULL ) {
  +    if (shm->head == NULL) {
           env->l->jkLog(env, env->l, JK_LOG_ERROR, 
                         "shm.writeSlot() No head - shm was not initalized\n");
           return JK_ERR;
       }
  -    slot=shm->createSlot( env, shm, instanceName, 0 );
  +    
  +    slot = shm->createSlot(env, shm, instanceName, 0);
       
       /*  Copy the body in the slot */
  -    memcpy( slot->data, buf, len );
  -    slot->size=len;
  +    memcpy(slot->data, buf, len);
  +    slot->size = len;
       slot->ver++;
       /* Update the head lb version number - that would triger
          reconf on the next request */
  @@ -576,8 +409,10 @@
       }
       case SHM_DUMP: {
           char *name=msg->getString( env, msg );
  -
  +#if 0
  +        /* XXX do we realy need that */
           jk2_shm_dump( env, shm, name );
  +#endif
           return JK_OK;
       }
       }/* switch */
  @@ -595,24 +430,24 @@
       if( shm == NULL )
           return JK_ERR;
   
  -    shm->pool=pool;
  -    shm->privateData=NULL;
  +    shm->pool = pool;
  +    shm->privateData = NULL;
   
  -    shm->slotSize=DEFAULT_SLOT_SIZE;
  -    shm->slotMaxCount=DEFAULT_SLOT_COUNT;
  +    shm->slotSize = DEFAULT_SLOT_SIZE;
  +    shm->slotMaxCount = DEFAULT_SLOT_COUNT;
       
  -    result->setAttribute=jk2_shm_setAttribute;
  -    result->setAttributeInfo=jk2_shm_setAttributeInfo;
  +    result->setAttribute = jk2_shm_setAttribute;
  +    result->setAttributeInfo = jk2_shm_setAttributeInfo;
       /* result->getAttribute=jk2_shm_getAttribute; */
  -    shm->mbean=result; 
  -    result->object=shm;
  +    shm->mbean = result; 
  +    result->object = shm;
       result->invoke=jk2_shm_invoke;
  -    shm->init=jk2_shm_init;
  -    shm->destroy=jk2_shm_destroy;
  +    shm->init = jk2_shm_init;
  +    shm->destroy = jk2_shm_destroy;
       
  -    shm->getSlot=jk2_shm_getSlot;
  -    shm->createSlot=jk2_shm_createSlot;
  -    shm->reset=jk2_shm_reset;
  +    shm->getSlot = jk2_shm_getSlot;
  +    shm->createSlot = jk2_shm_createSlot;
  +    shm->reset = jk2_shm_reset;
       
       return JK_OK;
   }
  
  
  

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