apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@apache.org
Subject cvs commit: apr/test testpipe.c
Date Thu, 12 Dec 2002 23:27:13 GMT
rbb         2002/12/12 15:27:13

  Modified:    file_io/win32 pipe.c
               test     testpipe.c
  Log:
  Always use overlapped pipes on NT-based machines.  This allows pipes to
  timeout correctly.  Also, add a test case for pipes that don't have a
  timeout.
  
  Revision  Changes    Path
  1.46      +1 -43     apr/file_io/win32/pipe.c
  
  Index: pipe.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/win32/pipe.c,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- pipe.c	29 Oct 2002 01:33:51 -0000	1.45
  +++ pipe.c	12 Dec 2002 23:27:13 -0000	1.46
  @@ -89,49 +89,7 @@
   
   APR_DECLARE(apr_status_t) apr_file_pipe_create(apr_file_t **in, apr_file_t **out, apr_pool_t
*p)
   {
  -#ifdef _WIN32_WCE
  -    return APR_ENOTIMPL;
  -#else
  -    SECURITY_ATTRIBUTES sa;
  -
  -    sa.nLength = sizeof(sa);
  -    sa.bInheritHandle = TRUE;
  -    sa.lpSecurityDescriptor = NULL;
  -
  -    (*in) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
  -    (*in)->pool = p;
  -    (*in)->fname = NULL;
  -    (*in)->pipe = 1;
  -    (*in)->timeout = -1;
  -    (*in)->ungetchar = -1;
  -    (*in)->eof_hit = 0;
  -    (*in)->filePtr = 0;
  -    (*in)->bufpos = 0;
  -    (*in)->dataRead = 0;
  -    (*in)->direction = 0;
  -
  -    (*out) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
  -    (*out)->pool = p;
  -    (*in)->fname = NULL;
  -    (*out)->pipe = 1;
  -    (*out)->timeout = -1;
  -    (*out)->ungetchar = -1;
  -    (*out)->eof_hit = 0;
  -    (*out)->filePtr = 0;
  -    (*out)->bufpos = 0;
  -    (*out)->dataRead = 0;
  -    (*out)->direction = 0;
  -
  -    if (!CreatePipe(&(*in)->filehand, &(*out)->filehand, &sa, 65536))
{
  -        return apr_get_os_error();
  -    }
  -
  -    apr_pool_cleanup_register((*in)->pool, (void *)(*in), file_cleanup,
  -                        apr_pool_cleanup_null);
  -    apr_pool_cleanup_register((*out)->pool, (void *)(*out), file_cleanup,
  -                        apr_pool_cleanup_null);
  -    return APR_SUCCESS;
  -#endif
  +    return apr_create_nt_pipe(in, out, TRUE, TRUE, p);
   }
   
   /* apr_create_nt_pipe()
  
  
  
  1.22      +27 -10    apr/test/testpipe.c
  
  Index: testpipe.c
  ===================================================================
  RCS file: /home/cvs/apr/test/testpipe.c,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- testpipe.c	12 Dec 2002 04:02:10 -0000	1.21
  +++ testpipe.c	12 Dec 2002 23:27:13 -0000	1.22
  @@ -114,16 +114,6 @@
       apr_status_t rv;
       char *buf;
       apr_size_t nbytes;
  -
  -#ifdef WIN32
  -    /* XXX:   THIS IS A HACK
  -     * This test currently fails on Windows, because it never returns from the file_read
  -     * call.  Because this stops the test suite from working, I am just making this fail
  -     * automatically on Windows without running the test.  When Windows gets this feature,
  -     * this hack should be removed.
  -     */
  -    CuFail(tc, "Timeouts don't work on pipes on Windows");
  -#endif
       
       nbytes = strlen("this is a test");
       buf = (char *)apr_palloc(p, nbytes + 1);
  @@ -141,6 +131,32 @@
       CuAssertIntEquals(tc, 0, nbytes);
   }
   
  +static void read_write_notimeout(CuTest *tc)
  +{
  +    apr_status_t rv;
  +    char *buf = "this is a test";
  +    char *input;
  +    apr_size_t nbytes;
  +    
  +    nbytes = strlen("this is a test");
  +
  +    rv = apr_file_pipe_create(&readp, &writep, p);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertPtrNotNull(tc, readp);
  +    CuAssertPtrNotNull(tc, writep);
  +
  +    rv = apr_file_write(writep, buf, &nbytes);
  +    CuAssertIntEquals(tc, strlen("this is a test"), nbytes);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +
  +    nbytes = 256;
  +    input = apr_pcalloc(p, nbytes + 1);
  +    rv = apr_file_read(readp, input, &nbytes);
  +    CuAssertIntEquals(tc, APR_SUCCESS, rv);
  +    CuAssertIntEquals(tc, strlen("this is a test"), nbytes);
  +    CuAssertStrEquals(tc, "this is a test", input);
  +}
  +
   CuSuite *testpipe(void)
   {
       CuSuite *suite = CuSuiteNew("Pipes");
  @@ -149,6 +165,7 @@
       SUITE_ADD_TEST(suite, close_pipe);
       SUITE_ADD_TEST(suite, set_timeout);
       SUITE_ADD_TEST(suite, read_write);
  +    SUITE_ADD_TEST(suite, read_write_notimeout);
   
       return suite;
   }
  
  
  

Mime
View raw message