apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jor...@apache.org
Subject cvs commit: apr/test testshm.c
Date Tue, 01 Jun 2004 10:03:51 GMT
jorton      2004/06/01 03:03:51

  Modified:    .        CHANGES
               include  apr_shm.h
               shmem/beos shm.c
               shmem/os2 shm.c
               shmem/unix shm.c
               shmem/win32 shm.c
               test     testshm.c
  Log:
  * include/apr_shm.c (apr_shm_remove): Add prototype.
  
  * shmem/unix/shm.c (apr_shm_remove): New function.
  
  * shmem/beos/shm.c, shmem/win32/shm.c, shmem/os2/shm.c
  (apr_shm_remove): APR_ENOTIMPL stubs.
  
  Submitted by: Amit Athavale <amit_athavale@persistent.co.in>
  
  Revision  Changes    Path
  1.471     +3 -0      apr/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apr/CHANGES,v
  retrieving revision 1.470
  retrieving revision 1.471
  diff -d -u -r1.470 -r1.471
  --- CHANGES	24 May 2004 09:33:25 -0000	1.470
  +++ CHANGES	1 Jun 2004 10:03:47 -0000	1.471
  @@ -7,6 +7,9 @@
   
   Changes with APR 1.0
   
  +  *) Add apr_shm_remove() function for removing a named shared
  +     memory segment.  [Amit Athavale <amit_athavale persistent.co.in>]
  +
     *) Add apr_strtoff() function for converting numeric strings into 
        apr_off_t values.  [André Malo <nd perlig.de>, Joe Orton]
   
  
  
  
  1.7       +12 -0     apr/include/apr_shm.h
  
  Index: apr_shm.h
  ===================================================================
  RCS file: /home/cvs/apr/include/apr_shm.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -d -u -r1.6 -r1.7
  --- apr_shm.h	13 Feb 2004 09:38:28 -0000	1.6
  +++ apr_shm.h	1 Jun 2004 10:03:49 -0000	1.7
  @@ -70,6 +70,18 @@
                                            apr_pool_t *pool);
   
   /**
  + * Remove shared memory segment associated with a filename.
  + * @param filename The filename associated with shared-memory segment which
  + *        needs to be removed
  + * @param pool The pool used for file operations
  + * @remark This function is only supported on platforms which support
  + * name-based shared memory segments, and will return APR_ENOTIMPL on
  + * platforms without such support.
  + */
  +APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
  +                                         apr_pool_t *pool);
  +
  +/**
    * Destroy a shared memory segment and associated memory.
    * @param m The shared memory segment structure to destroy.
    */
  
  
  
  1.12      +5 -0      apr/shmem/beos/shm.c
  
  Index: shm.c
  ===================================================================
  RCS file: /home/cvs/apr/shmem/beos/shm.c,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -d -u -r1.11 -r1.12
  --- shm.c	13 Feb 2004 09:38:33 -0000	1.11
  +++ shm.c	1 Jun 2004 10:03:50 -0000	1.12
  @@ -69,6 +69,11 @@
       return APR_SUCCESS;
   }
   
  +APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
  +                                         apr_pool_t *pool)
  +{
  +    return APR_ENOTIMPL;
  +}
   
   APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
                                            const char *filename,
  
  
  
  1.10      +6 -0      apr/shmem/os2/shm.c
  
  Index: shm.c
  ===================================================================
  RCS file: /home/cvs/apr/shmem/os2/shm.c,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -d -u -r1.9 -r1.10
  --- shm.c	13 Feb 2004 09:38:33 -0000	1.9
  +++ shm.c	1 Jun 2004 10:03:50 -0000	1.10
  @@ -61,6 +61,12 @@
       return APR_SUCCESS;
   }
   
  +APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
  +                                         apr_pool_t *pool)
  +{
  +    return APR_ENOTIMPL;
  +}
  +
   APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
                                            const char *filename,
                                            apr_pool_t *pool)
  
  
  
  1.27      +51 -0     apr/shmem/unix/shm.c
  
  Index: shm.c
  ===================================================================
  RCS file: /home/cvs/apr/shmem/unix/shm.c,v
  retrieving revision 1.26
  retrieving revision 1.27
  diff -d -u -r1.26 -r1.27
  --- shm.c	27 May 2004 16:00:05 -0000	1.26
  +++ shm.c	1 Jun 2004 10:03:50 -0000	1.27
  @@ -354,6 +354,57 @@
       return APR_ENOTIMPL;
   }
   
  +APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
  +                                         apr_pool_t *pool)
  +{
  +#if APR_USE_SHMEM_SHMGET
  +    apr_status_t status;
  +    apr_file_t *file;  
  +    key_t shmkey;
  +    int shmid;
  +#endif
  +
  +#if APR_USE_SHMEM_MMAP_TMP
  +    return apr_file_remove(filename, pool);
  +#endif
  +#if APR_USE_SHMEM_MMAP_SHM
  +    if (shm_unlink(filename) == -1) {
  +        return errno;
  +    }
  +    return APR_SUCCESS;
  +#endif
  +#if APR_USE_SHMEM_SHMGET
  +    /* Presume that the file already exists; just open for writing */    
  +    status = apr_file_open(&file, filename, APR_WRITE,
  +                           APR_OS_DEFAULT, pool);
  +    if (status) {
  +        return status;
  +    }
  +
  +    /* ftok() (on solaris at least) requires that the file actually
  +     * exist before calling ftok(). */
  +    shmkey = ftok(filename, 1);
  +    if (shmkey == (key_t)-1) {
  +        return errno;
  +    }
  +
  +    if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
  +        return errno;
  +    }
  +
  +    /* Indicate that the segment is to be destroyed as soon
  +     * as all processes have detached. This also disallows any
  +     * new attachments to the segment. */
  +    if (shmctl(shmid, IPC_RMID, NULL) == -1) {
  +        return errno;
  +    }
  +    return apr_file_remove(filename, pool);
  +#endif
  +
  +    /* No support for anonymous shm */
  +    return APR_ENOTIMPL;
  +} 
  +
   APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m)
   {
       return apr_pool_cleanup_run(m->pool, m, shm_cleanup_owner);
  
  
  
  1.18      +6 -0      apr/shmem/win32/shm.c
  
  Index: shm.c
  ===================================================================
  RCS file: /home/cvs/apr/shmem/win32/shm.c,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -d -u -r1.17 -r1.18
  --- shm.c	13 Feb 2004 09:38:34 -0000	1.17
  +++ shm.c	1 Jun 2004 10:03:50 -0000	1.18
  @@ -162,6 +162,12 @@
       return rv;
   }
   
  +APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
  +                                         apr_pool_t *pool)
  +{
  +    return APR_ENOTIMPL;
  +}
  +
   APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m,
                                            const char *file,
                                            apr_pool_t *pool)
  
  
  
  1.17      +31 -0     apr/test/testshm.c
  
  Index: testshm.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testshm.c,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -d -u -r1.16 -r1.17
  --- testshm.c	15 May 2004 19:51:50 -0000	1.16
  +++ testshm.c	1 Jun 2004 10:03:51 -0000	1.17
  @@ -214,6 +214,36 @@
       ABTS_INT_EQUAL(tc, sent, received);
   
   }
  +
  +static void test_named_remove(abts_case *tc, void *data)
  +{
  +    apr_status_t rv;
  +    apr_shm_t *shm;
  +
  +    rv = apr_shm_create(&shm, SHARED_SIZE, SHARED_FILENAME, p);
  +    apr_assert_success(tc, "Error allocating shared memory block", rv);
  +    if (rv != APR_SUCCESS) {
  +        return;
  +    }
  +    ABTS_PTR_NOTNULL(tc, shm);
  +
  +    rv = apr_shm_remove(SHARED_FILENAME, p);
  +    apr_assert_success(tc, "Error removing shared memory block", rv);
  +    if (rv != APR_SUCCESS) {
  +        return ;
  +    }
  +
  +    rv = apr_shm_create(&shm, SHARED_SIZE, SHARED_FILENAME, p);
  +    apr_assert_success(tc, "Error allocating shared memory block", rv);
  +    if (rv != APR_SUCCESS) {
  +        return;
  +    }
  +    ABTS_PTR_NOTNULL(tc, shm);
  +
  +    rv = apr_shm_destroy(shm);
  +    apr_assert_success(tc, "Error destroying shared memory block", rv);
  +}
  +
   #endif
   
   abts_suite *testshm(abts_suite *suite)
  @@ -228,6 +258,7 @@
       abts_run_test(suite, test_anon, NULL);
   #endif
       abts_run_test(suite, test_named, NULL); 
  +    abts_run_test(suite, test_named_remove, NULL); 
   #endif
   
       return suite;
  
  
  

Mime
View raw message