// $Id$ // ============================================================================ // // = LIBRARY // tests // // = FILENAME // Conn_Test.cpp // // = DESCRIPTION // This is a test of the and // classes. The test forks two processes or spawns two threads // (depending upon the platform) and then executes client and // server allowing them to connect and exchange data. The test // also illustrates how the works by // showing how you can cache connections on the client. // // = AUTHOR // Doug Schmidt, Chris Cleeland // // ============================================================================ #include "ace/SOCK_Connector.h" #include "ace/SOCK_Acceptor.h" #include "ace/Acceptor.h" #include "ace/Handle_Set.h" #include "ace/Connector.h" #include "ace/Strategies.h" #include "test_config.h" #include "Conn_Test.h" // **************************************** Svc_Handler::Svc_Handler (ACE_Thread_Manager *) : in_use_ (0) { } int Svc_Handler::in_use (void) { return this->in_use_; } void Svc_Handler::in_use (int use) { this->in_use_ = use; } int Svc_Handler::open (void *) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) opening Svc_Handler %d with handle\n", this, this->peer ().get_handle ())); // Enable non-blocking I/O. if (this->peer ().enable (ACE_NONBLOCK) == -1) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "enable"), -1); return 0; } void Svc_Handler::send_data (void) { // Send data to server. for (char c = 'a'; c <= 'z'; c++) if (this->peer ().send_n (&c, 1) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); } void Svc_Handler::recv_data (void) { ACE_SOCK_Stream &new_stream = this->peer (); ACE_Handle_Set handle_set; handle_set.set_bit (new_stream.get_handle ()); char t = 'a'; // Read data from client (terminate on error). for (ssize_t r_bytes; ;) { // Since we're in non-blocking mode we need to use