// $Id$ // ============================================================================ // // = LIBRARY // tests // // = FILENAME // Conn_Test.cpp // // = DESCRIPTION // This is a test of the and // classes. The test forks processes or spawns 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, and Irfan Pyarali // // ============================================================================ #include "test_config.h" #include "ace/SOCK_Connector.h" #include "ace/LOCK_SOCK_Acceptor.h" #include "ace/Acceptor.h" #include "ace/Handle_Set.h" #include "ace/Connector.h" #include "ace/Strategies.h" #include "ace/Auto_Ptr.h" #include "ace/Get_Opt.h" #include "Conn_Test.h" // Default number of clients/servers. static int n_servers = 4; static int n_clients = 10; static int n_client_iterations = 2; Svc_Handler::Svc_Handler (ACE_Thread_Manager *) { } int Svc_Handler::open (void *) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) opening Svc_Handler %d with handle %d\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; } int Svc_Handler::recycle (void *) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) recycling Svc_Handler %d with handle %d\n", this, this->peer ().get_handle ())); return 0; } void Svc_Handler::send_data (void) { // Send data to server. for (char *c = ACE_ALPHABET; *c != '\0'; 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 = ACE_ALPHABET; // Read data from client (terminate on error). for (ssize_t r_bytes; ;) { // Since we're in non-blocking mode we need to use