int ACE_TMAIN (int argc, ACE_TCHAR **argv){ Options_Manager optsMgr(argc, argv, ACE_TEXT ("server-opts")); // show usage is requested if (optsMgr._usage) { optsMgr._show_usage(stderr, ACE_TEXT ("server-opts")); return 1; } // If SCTP is not installed then terminate the program, unless TCP // was specified. #ifndef ACE_HAS_SCTP if (optsMgr.test_transport_protocol == IPPROTO_SCTP) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("SCTP was NOT installed when this binary was compiled.\n") ACE_TEXT ("SOCK_STREAM_srv may still be run using TCP ") ACE_TEXT ("via the '-t tcp' option.\n")), 1); #endif // check that valid options were specified if (optsMgr._error) { ACE_OS::fprintf (stderr, "ERROR: %s\n", ACE_TEXT_ALWAYS_CHAR (optsMgr._error_message)); return 1; } // this is the socket that the server will listen on ACE_SOCK_Acceptor acceptor_socket; // Create the address that we want to listen for connections on. If // server_accept_addr=INADDR_ANY (the default), SCTP will listen for // connections on all IP interfaces. If an address is specified, // SCTP will listen for connections on that address ONLY. ACE_INET_Addr serverAddr(optsMgr.server_port, optsMgr.server_accept_addr); ACE_DEBUG((LM_DEBUG, ACE_TEXT ("(%P|%t) Accepting connections on port %u on interface %C using %C\n"), serverAddr.get_port_number(), (optsMgr.server_accept_addr == INADDR_ANY) ? "INADDR_ANY" : serverAddr.get_host_addr(), (optsMgr.test_transport_protocol == IPPROTO_SCTP) ? "IPPROTO_SCTP" : "IPPROTO_TCP")); // this operation creates a socket, binds the specified internet // address to it and calls listen. As this is a wrapper facade // approach, the ACE_OS::{socket,bind,listen} calls are invoked in // the implementation of open. if (acceptor_socket.open(serverAddr, 1, AF_INET, ACE_DEFAULT_BACKLOG, optsMgr.test_transport_protocol) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("open")), 1); // this function checks that the port that was actually bound was // the port we asked for. Apparently some operating systems will // automatically select new ports if the specified port is currently // used. else if (acceptor_socket.get_local_addr(serverAddr) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("get_local_addr")), 1); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) starting server at port %d\n"), serverAddr.get_port_number())); // this is the stream object that will associated with a completed // connection (aka the data mode socket). It will be set when accept // is called below. ACE_SOCK_Stream new_stream; // a file decriptor set ACE_Handle_Set handle_set; // add the acceptor socket to the file descriptor set. handle_set.set_bit(acceptor_socket.get_handle()); for (;;){ ACE_Time_Value timeout(ACE_DEFAULT_TIMEOUT); ACE_Handle_Set temp = handle_set; // wait for connect() call from client. In the original test there // were two different acceptor sockets for two different // services. So select was needed to wait on both sockets // simultaneously. In this test we could just call accept on the // one socket. int result = ACE_OS::select(ACE_Utils::truncate_cast<int> ((intptr_t)acceptor_socket.get_handle()) +1, (fd_set *) temp, 0, 0, timeout); // check that select did not end with an error. if (result == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("select"))); // check to see if select timed out. else if (result == 0){ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) select timed out\n"))); } else { // case where a file descriptor was actually set if (!(temp.is_set(acceptor_socket.get_handle()))){ // CANNOT BE REACHED ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("select: NO ERROR BUT NO FD SET"))); } else { // call accept to set up the new stream. if (acceptor_socket.accept(new_stream) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("accept"))); continue; } else{ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) spawning server\n"))); } // Run the server. run_server (new_stream.get_handle ()); } } } ACE_NOTREACHED (return 0;) }
int ACE_TMAIN (int argc, ACE_TCHAR **argv){ // Initialize the options manager Options_Manager optsMgr(argc, argv, ACE_TEXT ("client-opts")); // show usage if requested if (optsMgr._usage) { optsMgr._show_usage(stderr, ACE_TEXT ("client-opts")); return 1; } // If SCTP is not installed then terminate the program, unless TCP // was specified. #ifndef ACE_HAS_SCTP if (optsMgr.test_transport_protocol == IPPROTO_SCTP) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("SCTP was NOT installed when this binary was compiled.\nSOCK_STREAM_clt may still be run using TCP via the '-t tcp' option.\n")), 1); #endif // check that valid options were specified if (optsMgr._error) { ACE_OS::fprintf (stderr, "ERROR: %s\n", ACE_TEXT_ALWAYS_CHAR (optsMgr._error_message)); return 1; } // Create the address that we want the client to connect to ACE_INET_Addr serverAddr(Options_Manager::server_port, Options_Manager::server_host); // Create the address that we want the client to connect FROM ACE_INET_Addr clientAddr(Options_Manager::client_port, Options_Manager::client_connect_addr); // object that manages the connection to the server ACE_SOCK_Connector connector; // object that manages the data xfer between the client and server ACE_SOCK_Stream dataStream; // connect to the server if (connector.connect (dataStream, serverAddr, 0,clientAddr, 0, 0, 0, // ALL DEFAULT ARGUMENTS Options_Manager::test_transport_protocol) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) %p\n"), ACE_TEXT ("connection failed")), 1); // run the test ACE_SCTP::HIST testResultsHistogram = 0; // connection is closed by runTest* functions testResultsHistogram = runTest(dataStream); // report out the test statistics. // all histograms created are placed onto a linked list that report() // can access. So the histogram created in one of the *_test() functions // will be reported out by the report() call if (testResultsHistogram) ACE_SCTP::report(); return 0; }