static void s_Resolve(SERV_ITER iter) { struct SDISPD_Data* data = (struct SDISPD_Data*) iter->data; SConnNetInfo* net_info = data->net_info; EIO_Status status = eIO_Success; CONNECTOR c = 0; CONN conn; char* s; assert(!(data->eof | data->fail)); assert(!!net_info->stateless == !!iter->stateless); /* Obtain additional header information */ if ((!(s = SERV_Print(iter, 0, 0)) || ConnNetInfo_OverrideUserHeader(net_info, s)) && ConnNetInfo_OverrideUserHeader(net_info, iter->ok_down && iter->ok_suppressed ? "Dispatch-Mode: PROMISCUOUS\r\n" : iter->ok_down ? "Dispatch-Mode: OK_DOWN\r\n" : iter->ok_suppressed ? "Dispatch-Mode: OK_SUPPRESSED\r\n" : "Dispatch-Mode: INFORMATION_ONLY\r\n") && ConnNetInfo_OverrideUserHeader(net_info, iter->reverse_dns ? "Client-Mode: REVERSE_DNS\r\n" : !net_info->stateless ? "Client-Mode: STATEFUL_CAPABLE\r\n" : "Client-Mode: STATELESS_ONLY\r\n")) { c = HTTP_CreateConnectorEx(net_info, fHTTP_Flushable, s_ParseHeader, iter/*data*/, s_Adjust, 0/*cleanup*/); } if (s) { ConnNetInfo_DeleteUserHeader(net_info, s); free(s); } if (c && (status = CONN_Create(c, &conn)) == eIO_Success) { /* Send all the HTTP data... */ CONN_Flush(conn); /* ...then trigger the header callback */ CONN_Close(conn); } else { CORE_LOGF_X(5, eLOG_Error, ("%s%s%sUnable to create auxiliary HTTP %s: %s", &"["[!*iter->name], iter->name, *iter->name ? "] " : "", c ? "connection" : "connector", IO_StatusStr(c ? status : eIO_Unknown))); if (c && c->destroy) c->destroy(c); assert(0); } }
static void blocking_connect (CONNECTOR &con, const ACE_INET_Addr &server_addr) { Svc_Handler *svc_handler; ACE_NEW (svc_handler, Svc_Handler); // Perform a blocking connect to the server. if (con.connect (svc_handler, server_addr) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("connection failed"))); else { // Send the data to the server. svc_handler->send_data (); // Close the connection completely. if (svc_handler->close (1) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("close"))); } }
static void timed_blocking_connect (CONNECTOR &con, const ACE_INET_Addr &server_addr) { ACE_Time_Value tv (ACE_DEFAULT_TIMEOUT); ACE_Synch_Options options (ACE_Synch_Options::USE_TIMEOUT, tv); Svc_Handler *svc_handler; ACE_NEW (svc_handler, Svc_Handler); // Perform a timed-blocking connect to the server (this should // connect quickly since we're in the same address space or same // host). if (con.connect (svc_handler, server_addr, options) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("connection failed"))); else { // Send the data to the server. svc_handler->send_data (); // Close the connection completely. if (svc_handler->close (1) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("close"))); } }
CConn_Streambuf::CConn_Streambuf(CONNECTOR connector, EIO_Status status, const STimeout* timeout, size_t buf_size, CConn_IOStream::TConn_Flags flags, CT_CHAR_TYPE* ptr, size_t size) : m_Conn(0), m_WriteBuf(0), m_ReadBuf(&x_Buf), m_BufSize(1), m_Status(status), m_Tie(false), m_Close(true), m_CbValid(false), x_Buf(), x_GPos((CT_OFF_TYPE)(ptr ? size : 0)), x_PPos((CT_OFF_TYPE)size) { if (!connector) { if (m_Status == eIO_Success) m_Status = eIO_InvalidArg; ERR_POST_X(2, x_Message("CConn_Streambuf(): NULL connector")); return; } if ((flags & (CConn_IOStream::fConn_Untie | CConn_IOStream::fConn_WriteBuffered)) == CConn_IOStream::fConn_WriteBuffered && buf_size) { m_Tie = true; } if ((m_Status = CONN_CreateEx(connector, fCONN_Supplement | (m_Tie ? 0 : fCONN_Untie), &m_Conn)) != eIO_Success) { ERR_POST_X(3, x_Message("CConn_Streambuf(): CONN_Create() failed")); _ASSERT(!connector->meta && !connector->next); if (connector->destroy) connector->destroy(connector); return; } _ASSERT(m_Conn); x_Init(timeout, buf_size, flags, ptr, size); }
// Execute the client tests. void * client (void *arg) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) running client\n"))); ACE_INET_Addr *connection_addr = reinterpret_cast<ACE_INET_Addr *> (arg); CONNECTOR connector; int i; // Automagic memory cleanup. Write_Handler **temp_writers = 0; ACE_NEW_RETURN (temp_writers, Write_Handler *[opt_nconnections], 0); ACE_Auto_Basic_Array_Ptr <Write_Handler *> writers (temp_writers); ACE_TCHAR *temp_failed = 0; ACE_NEW_RETURN (temp_failed, ACE_TCHAR[opt_nconnections], 0); ACE_Auto_Basic_Array_Ptr <ACE_TCHAR> failed_svc_handlers (temp_failed); // Automagic memory cleanup. ACE_INET_Addr *temp_addresses; ACE_NEW_RETURN (temp_addresses, ACE_INET_Addr [opt_nconnections], 0); ACE_Auto_Array_Ptr <ACE_INET_Addr> addresses (temp_addresses); // Initialize array. for (i = 0; i < opt_nconnections; i++) { writers[i] = 0; addresses[i] = *connection_addr; } // Connection all <opt_nconnections> svc_handlers int result = connector.connect_n (opt_nconnections, writers.get (), addresses.get (), failed_svc_handlers.get ()); if (result == -1) { // Print out the connections that failed... for (i = 0; i < opt_nconnections; i++) if (failed_svc_handlers.get ()[i]) { ACE_INET_Addr failed_addr = addresses.get()[i]; ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) connection failed to %s, %d\n"), failed_addr.get_host_name (), failed_addr.get_port_number ())); } return 0; } // If no connections failed (result == 0) then there should be valid // ACE_Svc_handler pointers in each writers[] position. Iterate to // send data for (int j = 0; j < opt_nloops; j++) for (i = 0; i < opt_nconnections; i++) if (writers[i]->send_data () == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("writer::send_data")), 0); // Cleanup for (i = 0; i < opt_nconnections; i++) writers[i]->destroy (); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) finishing client\n"))); return 0; }
void test_connect (ACE_Reactor &reactor, ACE_INET_Addr *addresses, ACE_Synch_Options &synch_options, int complete_nonblocking_connections) { CONNECTOR connector (&reactor); int i = 0; int completion_counter = 0; Svc_Handler::Connection_Status *connection_status = new Svc_Handler::Connection_Status[number_of_connections]; Svc_Handler **svc_handlers = new Svc_Handler *[number_of_connections]; for (i = 0; i < number_of_connections; ++i) { svc_handlers[i] = new Svc_Handler; svc_handlers[i]->connection_status (connection_status[i], completion_counter); } connector.connect_n (number_of_connections, svc_handlers, addresses, 0, synch_options); if (!synch_options[ACE_Synch_Options::USE_REACTOR]) ACE_ASSERT (completion_counter == number_of_connections); if (complete_nonblocking_connections) { while (completion_counter != number_of_connections) { connector.reactor ()->handle_events (); } } connector.close (); for (i = 0; i < number_of_connections; ++i) { ACE_TCHAR buffer[1024]; addresses[i].addr_to_string (buffer, sizeof buffer / sizeof (ACE_TCHAR), 1); ACE_DEBUG ((LM_DEBUG, "Connection to %s %s\n", buffer, connection_status[i] == Svc_Handler::SUCCEEDED ? "succeeded" : "failed")); if (connection_status[i] == Svc_Handler::SUCCEEDED) { svc_handlers[i]->close (); } } delete[] svc_handlers; delete[] connection_status; }