diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-11-24 23:25:58 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1996-11-24 23:25:58 +0000 |
commit | ae3742d1d6afe6974dfb95acab3b7b99776f30a4 (patch) | |
tree | 12679470148b109564cc28a52fa7aeb5732f5b00 /tests | |
parent | 1d68bf26a8df9cf5b878a2070ab7d82e966eabc9 (diff) | |
download | ATCD-ae3742d1d6afe6974dfb95acab3b7b99776f30a4.tar.gz |
Done
Diffstat (limited to 'tests')
-rw-r--r-- | tests/UPIPE_SAP_Test.cpp | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/tests/UPIPE_SAP_Test.cpp b/tests/UPIPE_SAP_Test.cpp index 0b38ecd7d39..2cd62cd4b9e 100644 --- a/tests/UPIPE_SAP_Test.cpp +++ b/tests/UPIPE_SAP_Test.cpp @@ -29,21 +29,21 @@ // Global pattern static ACE_UPIPE_Addr addr ("pattern"); -// client thread. +// connector thread. static void * -client (void *) +connector (void *) { // Insert thread into thr_mgr. ACE_NEW_THREAD; ACE_UPIPE_Stream c_stream; - ACE_DEBUG ((LM_DEBUG, "(%t) client starting connect\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) connector starting connect\n")); ACE_UPIPE_Connector con; if (con.connect (c_stream, addr) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) client ACE_UPIPE_Connector failed\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) connector ACE_UPIPE_Connector failed\n")); ACE_Message_Block *mb; @@ -52,10 +52,10 @@ client (void *) mb->copy ("hello"); if (c_stream.send (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) error client send\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) error connector send\n")); if (c_stream.recv (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) error client recv\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) error connector recv\n")); ACE_ASSERT (ACE_OS::strcmp (mb->rd_ptr (), "thanks") == 0); @@ -63,12 +63,12 @@ client (void *) delete mb; // Now try the send()/recv() interface. - char mytext[] = "This string is sent by client as a buffer"; + char mytext[] = "This string is sent by connector as a buffer"; - ACE_DEBUG ((LM_DEBUG, "(%t) client sending text\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) connector sending text\n")); if (c_stream.send (mytext, sizeof mytext) == -1) ACE_DEBUG ((LM_DEBUG, - "(%t) buffer send from client failed\n")); + "(%t) buffer send from connector failed\n")); char conbuf[BUFSIZ]; // Buffer to receive response. @@ -78,14 +78,15 @@ client (void *) { if (c_stream.recv (&c, 1) == -1) ACE_DEBUG ((LM_DEBUG, - "(%t) buffer recv from client failed\n")); + "(%t) buffer recv from connector failed\n")); else conbuf[i] = c; } conbuf[i] = '\0'; ACE_DEBUG ((LM_DEBUG, "(%t) conbuf = %s", conbuf)); - ACE_ASSERT (ACE_OS::strcmp (conbuf, "this is the server response!") == 0); + ACE_ASSERT (ACE_OS::strcmp (conbuf, "this is the acceptor response!") == 0); + ACE_ASSERT (ACE_OS::strcmp (conbuf, "this is the acceptor response!") == 0); c_stream.close (); ACE_DEBUG ((LM_DEBUG, "\n(%t) exiting thread\n")); @@ -93,15 +94,24 @@ client (void *) } static void * -server (void *args) +acceptor (void *args) { // Insert thread into thr_mgr. ACE_NEW_THREAD; ACE_UPIPE_Acceptor *acceptor = (ACE_UPIPE_Acceptor *) args; ACE_UPIPE_Stream s_stream; + ACE_hthread_t thr_handle; - ACE_DEBUG ((LM_DEBUG, "(%t) server starting accept\n")); + // Spawn a connector thread. + if (ACE_Thread::spawn (ACE_THR_FUNC (connector), + (void *) 0, + THR_NEW_LWP | THR_DETACHED, + 0, + &thr_handle) == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 0); + + ACE_DEBUG ((LM_DEBUG, "(%t) acceptor starting accept\n")); if (acceptor->accept (s_stream) == -1) ACE_DEBUG ((LM_DEBUG, @@ -110,7 +120,7 @@ server (void *args) ACE_Message_Block *mb = 0; if (s_stream.recv (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) server recv failed\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) acceptor recv failed\n")); ACE_ASSERT (ACE_OS::strcmp (mb->rd_ptr (), "hello") == 0); @@ -118,28 +128,27 @@ server (void *args) mb->copy ("thanks"); if (s_stream.send (mb) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) server send failed\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) acceptor send failed\n")); char s_buf[BUFSIZ]; - ACE_DEBUG ((LM_DEBUG, "(%t) server sleeping on recv\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) acceptor sleeping on recv\n")); if (s_stream.recv (s_buf, sizeof s_buf) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) server recv failed\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) acceptor recv failed\n")); else ACE_ASSERT (ACE_OS::strcmp (s_buf, - "This string is sent by client as a buffer") == 0); + "This string is sent by connector as a buffer") == 0); - const char svr_response[] = "this is the server response!"; + const char svr_response[] = "this is the acceptor response!"; ACE_OS::strcpy (s_buf, svr_response); if (s_stream.send (s_buf, sizeof svr_response) == -1) - ACE_DEBUG ((LM_DEBUG, "(%t) server send failed\n")); + ACE_DEBUG ((LM_DEBUG, "(%t) acceptor send failed\n")); s_stream.close (); ACE_DEBUG ((LM_DEBUG, "(%t) exiting thread\n")); return 0; } - #endif /* ACE_HAS_THREADS */ int @@ -148,33 +157,30 @@ main (int, char *argv[]) ACE_START_TEST ("UPIPE_SAP_Test.cpp"); #if defined (ACE_HAS_THREADS) && (defined (ACE_HAS_STREAM_PIPES) || defined (ACE_WIN32)) - - ACE_hthread_t thr_handle_server; - ACE_hthread_t thr_handle_client; - + ACE_hthread_t thr_handle_acceptor; + ACE_hthread_t thr_handle_connector; ACE_UPIPE_Acceptor acceptor (addr); - // Spawn a server thread. - if (ACE_Thread::spawn (ACE_THR_FUNC (server), + // Spawn a acceptor thread. + if (ACE_Thread::spawn (ACE_THR_FUNC (acceptor), (void *) &acceptor, THR_NEW_LWP | THR_DETACHED, 0, - &thr_handle_server) == -1) + &thr_handle_acceptor) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1); - // Spawn a client thread. - if (ACE_Thread::spawn (ACE_THR_FUNC (client), + // Spawn a connector thread. + if (ACE_Thread::spawn (ACE_THR_FUNC (connector), (void *) 0, THR_NEW_LWP | THR_DETACHED, 0, - &thr_handle_client) == -1) + &thr_handle_connector) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "spawn"), 1); - // Wait for server and client threads to exit. - ACE_Thread::join (thr_handle_client); - ACE_Thread::join (thr_handle_server); - + // Wait for both the acceptor and connector threads to exit. + ACE_Thread::join (thr_handle_connector); + ACE_Thread::join (thr_handle_acceptor); #else ACE_ERROR ((LM_ERROR, "threads and/or UPIPE not supported on this platform\n")); #endif /* ACE_HAS_THREADS */ |