diff options
Diffstat (limited to 'tests/Conn_Test.cpp')
-rw-r--r-- | tests/Conn_Test.cpp | 102 |
1 files changed, 60 insertions, 42 deletions
diff --git a/tests/Conn_Test.cpp b/tests/Conn_Test.cpp index e073aba4b57..3f5f03d8ed7 100644 --- a/tests/Conn_Test.cpp +++ b/tests/Conn_Test.cpp @@ -4,7 +4,7 @@ // // = LIBRARY // tests -// +// // = FILENAME // Conn_Test.cpp // @@ -18,7 +18,7 @@ // // = AUTHOR // Doug Schmidt, Chris Cleeland -// +// // ============================================================================ #include "ace/SOCK_Connector.h" @@ -52,12 +52,12 @@ Svc_Handler::in_use (int use) int Svc_Handler::open (void *) { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) opening Svc_Handler %d with handle\n", + 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; } @@ -65,9 +65,9 @@ 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) + if (this->peer ().send_n (c, 1) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "send_n")); } @@ -82,7 +82,7 @@ Svc_Handler::recv_data (void) 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 <select> @@ -110,7 +110,7 @@ Svc_Handler::recv_data (void) if (r_bytes == 0) { - ACE_DEBUG ((LM_DEBUG, + ACE_DEBUG ((LM_DEBUG, "(%P|%t) reached end of input, connection closed by client\n")); // Handshake back with client. @@ -119,14 +119,14 @@ Svc_Handler::recv_data (void) // Close endpoint handle (but don't close <this> yet since // we're going to recycle it for the next iteration). - if (new_stream.close () == -1) + if (new_stream.close () == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); break; } else if (r_bytes == -1) { if (errno == EWOULDBLOCK) - ACE_DEBUG ((LM_DEBUG, + ACE_DEBUG ((LM_DEBUG, "(%P|%t) no input available, going back to reading\n")); else ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "recv_n")); @@ -167,7 +167,7 @@ ACE_Hash_Addr<ACE_INET_Addr, Svc_Handler>::hash_i (const ACE_INET_Addr &addr) co } int -ACE_Hash_Addr<ACE_INET_Addr, Svc_Handler>::compare_i (const ACE_INET_Addr &a1, +ACE_Hash_Addr<ACE_INET_Addr, Svc_Handler>::compare_i (const ACE_INET_Addr &a1, const ACE_INET_Addr &a2) const { return a1 != a2; @@ -194,7 +194,7 @@ nonblocking_connect (CONNECTOR &con, const ACE_INET_Addr &server_addr) ACE_NEW (svc_handler[1], Svc_Handler); ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting non-blocking connect\n")); - + // Perform a non-blocking connect to the server (this should connect // immediately since we're in the same address space or same host). if (con.connect (svc_handler[0], server_addr, options) == -1 @@ -211,7 +211,7 @@ nonblocking_connect (CONNECTOR &con, const ACE_INET_Addr &server_addr) // Close the connection completely. if (svc_handler[0]->close (1) == -1 - || svc_handler[1]->close (1) == -1) + || svc_handler[1]->close (1) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); } @@ -223,7 +223,7 @@ blocking_connect (CONNECTOR &con, const ACE_INET_Addr &server_addr) ACE_NEW (svc_handler[1], Svc_Handler); ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting blocking connect\n")); - + // Perform a blocking connect to the server. if (con.connect (svc_handler[0], server_addr) == -1 || con.connect (svc_handler[1], server_addr) == -1) @@ -239,7 +239,7 @@ blocking_connect (CONNECTOR &con, const ACE_INET_Addr &server_addr) // Close the connection completely. if (svc_handler[0]->close (1) == -1 - || svc_handler[1]->close (1) == -1) + || svc_handler[1]->close (1) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); } @@ -259,7 +259,7 @@ dump_map (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_Null_Mutex> &hashmap) { if (hashmap.table_[slot] == hashmap.sentinel_) continue; - + ACE_DEBUG ((LM_DEBUG, "slot %-4d: ", slot)); for (MAP_ENTRY *temp = hashmap.table_[slot]; @@ -270,8 +270,8 @@ dump_map (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_Null_Mutex> &hashmap) INT_ID& val = temp->int_id_; ACE_DEBUG ((LM_DEBUG, "(%s,%d,%sin use,0x%p), ", - key.get_host_name (), - key.get_port_number (), + key.get_host_name (), + key.get_port_number (), val->in_use() ? "" : "not ", val)); } @@ -284,7 +284,7 @@ dump_map (ACE_Hash_Map_Manager<EXT_ID, INT_ID, ACE_Null_Mutex> &hashmap) static void dump (STRAT_CONNECTOR &con) { - CACHED_CONNECT_STRATEGY* csp = + CACHED_CONNECT_STRATEGY* csp = (CACHED_CONNECT_STRATEGY *) con.connect_strategy_; dump_map (csp->connection_cache_); @@ -304,7 +304,7 @@ cached_connect (STRAT_CONNECTOR &con, const ACE_INET_Addr &server_addr) ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting cached blocking connect\n")); // Initiate timed, non-blocking connection with server. - + // Perform a blocking connect to the server using the Strategy // Connector with a connection caching strategy. Since we are // connecting to the same <server_addr> these calls will return the @@ -354,12 +354,12 @@ client (void *arg) { #if (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) // Insert thread into thr_mgr - ACE_Thread_Control thread_control (ACE_Thread_Manager::instance ()); + ACE_Thread_Control thread_control (ACE_Thread_Manager::instance ()); ACE_NEW_THREAD; #endif /* (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) */ ACE_INET_Addr *remote_addr = (ACE_INET_Addr *) arg; - ACE_INET_Addr server_addr (remote_addr->get_port_number (), + ACE_INET_Addr server_addr (remote_addr->get_port_number (), ACE_DEFAULT_SERVER_HOST); CONNECTOR connector; @@ -368,7 +368,7 @@ client (void *arg) // connection. CACHED_CONNECT_STRATEGY caching_connect_strategy; - STRAT_CONNECTOR strat_connector (0, + STRAT_CONNECTOR strat_connector (0, &creation_strategy, &caching_connect_strategy); @@ -390,7 +390,7 @@ server (void *arg) { #if (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) // Insert thread into thr_mgr - ACE_Thread_Control thread_control (ACE_Thread_Manager::instance ()); + ACE_Thread_Control thread_control (ACE_Thread_Manager::instance ()); ACE_NEW_THREAD; #endif /* (defined (ACE_WIN32) || defined (VXWORKS)) && defined (ACE_HAS_THREADS) */ @@ -403,29 +403,29 @@ server (void *arg) ACE_NEW_RETURN (svc_handler, Svc_Handler, 0); // Create a new <Svc_Handler> to consume the data. - + int result; - while ((result = acceptor->accept (svc_handler, + while ((result = acceptor->accept (svc_handler, &cli_addr, options)) != -1) { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) client %s connected from %d\n", - cli_addr.get_host_name (), + ACE_DEBUG ((LM_DEBUG, "(%P|%t) client %s connected from %d\n", + cli_addr.get_host_name (), cli_addr.get_port_number ())); - + svc_handler->recv_data (); } if (result == -1) { if (errno == ETIMEDOUT) - ACE_ERROR ((LM_DEBUG, + ACE_ERROR ((LM_DEBUG, "(%P|%t) accept timedout, shutting down\n")); else ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "accept")); } - if (svc_handler->close () == -1) + if (svc_handler->close () == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "close")); return 0; @@ -444,7 +444,7 @@ main (int, char *[]) if (acceptor.open ((const ACE_INET_Addr &) ACE_Addr::sap_any) == -1 || acceptor.acceptor ().get_local_addr (server_addr) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "open")); - else + else { ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting server at port %d\n", server_addr.get_port_number ())); @@ -467,31 +467,31 @@ main (int, char *[]) /* NOTREACHED */ } #elif defined (ACE_HAS_THREADS) - if (ACE_Thread_Manager::instance ()->spawn - (ACE_THR_FUNC (server), - (void *) &acceptor, + if (ACE_Thread_Manager::instance ()->spawn + (ACE_THR_FUNC (server), + (void *) &acceptor, THR_NEW_LWP | THR_DETACHED) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "thread create failed")); - if (ACE_Thread_Manager::instance ()->spawn - (ACE_THR_FUNC (client), - (void *) &server_addr, + if (ACE_Thread_Manager::instance ()->spawn + (ACE_THR_FUNC (client), + (void *) &server_addr, THR_NEW_LWP | THR_DETACHED) == -1) ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "thread create failed")); // Wait for the threads to exit. ACE_Thread_Manager::instance ()->wait (); #else - ACE_ERROR ((LM_ERROR, + ACE_ERROR ((LM_ERROR, "(%P|%t) only one thread may be run in a process on this platform\n%a", 1)); -#endif /* ACE_HAS_THREADS */ +#endif /* ACE_HAS_THREADS */ } ACE_END_TEST; return 0; } -#if defined (ACE_TEMPLATES_REQUIRE_SPECIALIZATION) +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) template class ACE_Cached_Connect_Strategy<Svc_Handler, ACE_SOCK_CONNECTOR, ACE_Null_Mutex>; template class ACE_Hash_Addr<ACE_INET_Addr, Svc_Handler>; template class ACE_NOOP_Creation_Strategy<Svc_Handler>; @@ -508,4 +508,22 @@ template class ACE_Map_Manager<ACE_HANDLE, ACE_Svc_Tuple<Svc_Handler> *, ACE_SYN template class ACE_Strategy_Connector<Svc_Handler, ACE_SOCK_CONNECTOR>; template class ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH>; template class ACE_Svc_Tuple<Svc_Handler>; -#endif /* ACE_TEMPLATES_REQUIRE_SPECIALIZATION */ +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Cached_Connect_Strategy<Svc_Handler, ACE_SOCK_CONNECTOR, ACE_Null_Mutex> +#pragma instantiate ACE_Hash_Addr<ACE_INET_Addr, Svc_Handler> +#pragma instantiate ACE_NOOP_Creation_Strategy<Svc_Handler> +#pragma instantiate ACE_Concurrency_Strategy<Svc_Handler> +#pragma instantiate ACE_Connect_Strategy<Svc_Handler, ACE_SOCK_CONNECTOR> +#pragma instantiate ACE_Connector<Svc_Handler, ACE_SOCK_CONNECTOR> +#pragma instantiate ACE_Creation_Strategy<Svc_Handler> +#pragma instantiate ACE_Hash_Map_Entry<ACE_Hash_Addr<ACE_INET_Addr,Svc_Handler>, Svc_Handler *> +#pragma instantiate ACE_Hash_Map_Manager<ACE_Hash_Addr<ACE_INET_Addr,Svc_Handler>, Svc_Handler *, ACE_Null_Mutex> +#pragma instantiate ACE_Oneshot_Acceptor<Svc_Handler, ACE_SOCK_ACCEPTOR> +#pragma instantiate ACE_Map_Entry<ACE_HANDLE, ACE_Svc_Tuple<Svc_Handler> *> +#pragma instantiate ACE_Map_Iterator<ACE_HANDLE, ACE_Svc_Tuple<Svc_Handler> *, ACE_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Map_Manager<ACE_HANDLE, ACE_Svc_Tuple<Svc_Handler> *, ACE_SYNCH_RW_MUTEX> +#pragma instantiate ACE_Strategy_Connector<Svc_Handler, ACE_SOCK_CONNECTOR> +#pragma instantiate ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_NULL_SYNCH> +#pragma instantiate ACE_Svc_Tuple<Svc_Handler> +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ + |