int FT_EventService::report_factory(CORBA::ORB_ptr orb, FtRtecEventChannelAdmin::EventChannel_ptr ec) { try{ char* addr = ACE_OS::getenv("EventChannelFactoryAddr"); if (addr != 0) { // instaniated by object factory, report my ior back to the factory ACE_INET_Addr factory_addr(addr); ACE_SOCK_Connector connector; ACE_SOCK_Stream stream; ORBSVCS_DEBUG((LM_DEBUG,"connecting to %s\n",addr)); if (connector.connect(stream, factory_addr) == -1) ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) Invalid Factory Address\n"), -1); ORBSVCS_DEBUG((LM_DEBUG,"Factory connected\n")); CORBA::String_var my_ior_string = orb->object_to_string(ec); int len = ACE_OS::strlen(my_ior_string.in()) ; if (stream.send_n(my_ior_string.in(), len) != len) ORBSVCS_ERROR_RETURN((LM_ERROR, "(%P|%t) IOR Transmission Error\n"), -1); stream.close(); } } catch (...){ return -1; } return 0; }
int ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream, const ACE_Time_Value *timeout, const ACE_Addr &local_sap) { ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start"); if (local_sap != ACE_Addr::sap_any) { sockaddr *laddr = reinterpret_cast<sockaddr *> (local_sap.get_addr ()); int const size = local_sap.get_size (); if (ACE_OS::bind (new_stream.get_handle (), laddr, size) == -1) { // Save/restore errno. ACE_Errno_Guard error (errno); new_stream.close (); return -1; } } // Enable non-blocking, if required. if (timeout != 0 && new_stream.enable (ACE_NONBLOCK) == -1) return -1; else return 0; }
int main (int argc, char *argv[]) { u_short logger_port = argc > 1 ? atoi (argv[1]) : LOGGER_PORT; const char *logger_host = argc > 2 ? argv[2] : LOGGER_HOST; ACE_SOCK_Stream logger; ACE_SOCK_Connector connector; ACE_INET_Addr addr (logger_port, logger_host); ACE_Log_Record log_record (LM_DEBUG, ACE_OS::time ((time_t *) 0), ACE_OS::getpid ()); if (connector.connect (logger, addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), -1); log_record.msg_data (DATA); size_t len = log_record.length (); log_record.encode (); if (logger.send ((char *) &log_record, len) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send"), -1); else if (logger.close () == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "close"), -1); return 0; }
int main(int argc, char* argv[]){ if (argc > 1){ return 1; } cout << argv[0] << endl; ACE_INET_Addr addr(1234, ACE_LOCALHOST); ACE_SOCK_Stream stream; ACE_SOCK_Acceptor acceptor; int success = acceptor.open(addr, 1); ACE_TCHAR addrStr[20]; if (success > 0) { addr.addr_to_string(addrStr, 20); } //* success = acceptor.accept(stream); if (success < 0) { cout << "Cannot accept" << endl; return 1; } //*/ char buf[BUFSIZ]; int n; char *msg = "You are connected"; stream.send_n(msg, strlen(msg)); stream.close(); /* while (stream.recv(buf, BUFSIZ)) { // _write(1, buf, n); cout << buf << endl; } //*/ cout << endl << "Done" << endl; return 0; }
// thread function that serves the client for the UnMarshalled Octet // test static ACE_THR_FUNC_RETURN unmarshalledOctetServer (void *arg){ // unbundle the arguments ArgStruct * args = reinterpret_cast<ArgStruct *> (arg); ACE_SOCK_Stream * dataModeStream = args->stream; ACE_CDR::ULong numIterations = args->numIters; delete args; // serve the client for numIterations synchronous invocations do { // READ A MESSAGE FROM THE CLIENT size_t bt; ACE_CDR::ULong msgBufSize=0; // read the size of the buffer to follow if ((dataModeStream->recv_n(&msgBufSize, ACE_CDR::LONG_SIZE, 0, &bt)) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv_n")), 0); msgBufSize = ACE_NTOHL(msgBufSize); // allocate the buffer for the message payload ACE_CDR::Octet * msgBuf = 0; ACE_NEW_RETURN(msgBuf, ACE_CDR::Octet[msgBufSize], 0); // read the buffer if ((dataModeStream->recv_n(msgBuf, msgBufSize, 0, &bt)) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("recv_n")), 0); // clean up the allocated buffer delete[] msgBuf; // SEND A REPLY TO THE CLIENT // send back a 2 byte reply ACE_CDR::Short reply; if ((dataModeStream->send_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1) ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("send_n")), 0); } while (--numIterations); // close and destroy the stream dataModeStream->close(); delete dataModeStream; return 0; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_LOG_MSG->open (argv[0]); parse_args (argc, argv); // Default is to ask the server for ``help.'' static char buf[BUFSIZ] = "help\n"; int n; ACE_SOCK_Stream sc; ACE_SOCK_Connector con; if (con.connect (sc, ACE_INET_Addr (port_number, host_name)) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n%a", "connect", 1), -1); if (remote_reconfigure) // Remotely instruct the server to reconfigure itself. ACE_OS::strcpy (buf, "reconfigure\n"); // Send the command. if (sc.send_n (buf, ACE_OS::strlen (buf) + 1) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n%a", "send", 1), -1); // Next, read the response. while ((n = sc.recv (buf, sizeof buf)) > 0) if (ACE_OS::write (ACE_STDOUT, buf, n) != n) ACE_ERROR_RETURN ((LM_ERROR, "%p\n%a", "write", 1), -1); if (sc.close () == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p\n%a", "close", 1), -1); return 0; }
int Scavenger_Task::svc(void) { this->the_barrier_->wait (); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Starting scavenger thread\n")); ACE_SOCK_Stream stream; { ACE_INET_Addr remote_sap (this->endpoint_); ACE_SOCK_Connector connector; if (connector.connect(stream, remote_sap) == -1) { ACE_ERROR((LM_ERROR, "Cannot connect to <%s>\n", endpoint_)); return -1; } } for (;;) { ACE_Time_Value period (0, this->period_in_usecs_); ACE_OS::sleep (period); { ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->mutex_, -1); if (this->stopped_) break; } ACE_hrtime_t start = ACE_OS::gethrtime (); ssize_t n = stream.send_n(&start, sizeof(start)); if (n == 0 || n == -1) break; ACE_hrtime_t end; n = stream.recv(&end, sizeof(end)); if (n == 0 || n == -1) break; if (start != end) { ACE_ERROR((LM_ERROR, "Mismatched response from <%s>\n", endpoint_)); break; } } stream.close(); ACE_DEBUG ((LM_DEBUG, "(%P|%t) Finishing scavenger thread\n")); return 0; }
static ACE_THR_FUNC_RETURN worker (void *) { ACE_OS::sleep (3); const ACE_TCHAR *msg = ACE_TEXT ("Message from Connection worker"); ACE_TCHAR buf [BUFSIZ]; buf[0] = static_cast<ACE_TCHAR> ((ACE_OS::strlen (msg) + 1)); ACE_OS::strcpy (&buf[1], msg); ACE_INET_Addr addr (rendezvous); ACE_DEBUG((LM_DEBUG, "(%t) Spawning %d client threads...\n", cli_thrno)); int grp = ACE_Thread_Manager::instance ()->spawn_n (cli_thrno, &cli_worker, buf); ACE_TEST_ASSERT (grp != -1); ACE_Thread_Manager::instance ()->wait_grp (grp); ACE_DEBUG ((LM_DEBUG, "(%t) Client threads done; shutting down...\n")); ACE_SOCK_Stream stream; ACE_SOCK_Connector connect; if (connect.connect (stream, addr) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p Error while connecting\n"), ACE_TEXT ("connect"))); const ACE_TCHAR *sbuf = ACE_TEXT ("\011shutdown"); ACE_DEBUG ((LM_DEBUG, "shutdown stream handle = %x\n", stream.get_handle ())); if (stream.send_n (sbuf, (ACE_OS::strlen (sbuf) + 1) * sizeof (ACE_TCHAR)) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("send_n"))); ACE_DEBUG ((LM_DEBUG, "Sent message of length = %d\n", ACE_OS::strlen (sbuf))); stream.close (); return 0; }
int SOYALDevice::make_handler(KSGDeviceNode* node,ACE_HANDLE* handler) { if(!node) return -1; std::string ip = node->GetDevAddr().GetConnect(); int port = node->GetDevAddr().GetPort(); ACE_INET_Addr addr(port,ip.c_str()); ACE_SOCK_Connector conn; ACE_SOCK_Stream stream; ACE_Time_Value tv = KSGGetTaskTimeoutIntval(); int err_code; ACE_DEBUG((LM_TRACE,"开始连接soyal控制器,[%s][%s]",node->get_name().c_str(),ip.c_str())); if(conn.connect(stream,addr,&tv)) { err_code = ACE_OS::last_error(); // TODO: 返回连接的错误码 if(EWOULDBLOCK == err_code) { ACE_DEBUG((LM_ERROR,"连接控制器失败")); } else if(EHOSTUNREACH == err_code || ENETUNREACH == err_code) { ACE_DEBUG((LM_ERROR,"无法连接设备主机")); node->SetState(KSGDeviceNode::dsError); } else { ACE_DEBUG((LM_ERROR,"连接主机未知错误![%d][%s]ip[%s]" ,err_code,ACE_OS::strerror(err_code),ip.c_str())); } // add by cash 释放 SOCKET // 2007-01-29 stream.close(); return -1; } // 设置 handler 为 BLOCK 的 // stream.disable(ACE_NONBLOCK); // 设置 linger 属性 struct linger lg; ACE_OS::memset(&lg,0,sizeof lg); lg.l_onoff = 1; // 3s lg.l_linger = 3; stream.set_option(SOL_SOCKET,SO_LINGER,&lg,sizeof lg); node->SetState(KSGDeviceNode::dsOnline); *handler = stream.get_handle(); return 0; }
int handle_connection(){ for (int i = 0; i < NO_ITERATIONS; i++){ int byte_count = 0; if ((byte_count = new_stream_.recv_n(data_buf_, SIZE_DATA, 0)) == -1){ ACE_ERROR((LM_ERROR, "%p\n", "Error in recv")); } else{ data_buf_[byte_count] = 0; ACE_DEBUG((LM_DEBUG, "Server received %s \n", data_buf_)); } } if (new_stream_.close() == -1){ ACE_ERROR((LM_ERROR,"%p\n","close")); } return 0; }
int main(int argc, char** argv) { const char* pathname = argc > 1 ? argv[1] : "/index.html"; const char* server_hostname = argc > 2 ? argv[2] : "ace.ece.uci.edu"; // Add funcation call for demo. dummy(); ACE_SOCK_Connector connector; ACE_SOCK_Stream peer; ACE_INET_Addr peer_addr; if (-1 == peer_addr.set(80, server_hostname)) { log("peer_addr.set failed\n"); return 1; } else if (-1 == connector.connect(peer, peer_addr)) { log("connector.connect failed\n"); return 1; } char buf[BUFSIZ]; iovec iov[3]; iov[0].iov_base = (void*)"GET "; iov[0].iov_len = 4; iov[1].iov_base = (void*)pathname; iov[1].iov_len = strlen(pathname); iov[2].iov_base = (void*)" HTTP/1.0\r\n\r\n"; iov[2].iov_len = 13; if (-1 == peer.sendv_n(iov, 3)) { log("peer.sendv_v failed\n"); return 1; } for (ssize_t n = 0; (n = peer.recv(buf, sizeof(buf))) > 0; ) { ACE::write_n(ACE_STDOUT, buf, n); } return peer.close(); }
int Pipe::open (void) { ACE_INET_Addr my_addr; ACE_SOCK_Acceptor acceptor; ACE_SOCK_Connector connector; ACE_SOCK_Stream reader; ACE_SOCK_Stream writer; int result = 0; // Bind listener to any port and then find out what the port was. if (acceptor.open (ACE_Addr::sap_any) == -1 || acceptor.get_local_addr (my_addr) == -1) result = -1; else { int af = my_addr.get_type (); const ACE_TCHAR *local = ACE_LOCALHOST; #if defined (ACE_HAS_IPV6) if (af == AF_INET6) local = ACE_IPV6_LOCALHOST; #endif /* ACE_HAS_IPV6 */ ACE_INET_Addr sv_addr (my_addr.get_port_number (), local, af); // Establish a connection within the same process. if (connector.connect (writer, sv_addr) == -1) result = -1; else if (acceptor.accept (reader) == -1) { writer.close (); result = -1; } } // Close down the acceptor endpoint since we don't need it anymore. acceptor.close (); if (result == -1) return -1; this->handles_[0] = reader.get_handle (); this->handles_[1] = writer.get_handle (); return 0; }
static u_int host_is_up (ACE_TCHAR hostname[]) { ACE_SOCK_Connector con; ACE_SOCK_Stream sock; // The ACE_INET_Addr construction causes gethostbyname_r to be // called, so we need to copy the hostname. ACE_TCHAR test_host[MAXHOSTNAMELEN]; ACE_OS::strcpy (test_host, hostname); ACE_INET_Addr another_host ((u_short) 7, test_host); ACE_Time_Value timeout_value (5); int const status = con.connect (sock, another_host, &timeout_value); sock.close (); return status == 0 ? 1 : 0; }
static ACE_THR_FUNC_RETURN cli_worker (void *arg) { // Client thread function. ACE_INET_Addr addr (rendezvous); ACE_SOCK_Stream stream; ACE_SOCK_Connector connect; ACE_Time_Value delay (0, req_delay); size_t len = * reinterpret_cast<ACE_TCHAR *> (arg); for (size_t i = 0 ; i < cli_conn_no; i++) { if (connect.connect (stream, addr) < 0) { ACE_ERROR ((LM_ERROR, "(%t) %p\n", "connect")); continue; } for (size_t j = 0; j < cli_req_no; j++) { ACE_DEBUG ((LM_DEBUG, "(%t) conn_worker handle 0x%x, req %d\n", stream.get_handle (), j+1)); if (stream.send_n (arg, (len + 1) * sizeof (ACE_TCHAR)) == -1) { ACE_ERROR ((LM_ERROR, "(%t) %p\n", "send_n")); continue; } ACE_OS::sleep (delay); } stream.close (); } return 0; }
int main() { ACE_INET_Addr server_addr; ACE_SOCK_Acceptor acceptor; ACE_SOCK_Stream peer; if (-1 == server_addr.set(22334)) { log("server_addr.set faild\n"); return 1; } if (-1 == acceptor.open(server_addr)) { log("acceptor.open failed\n"); return 1; } while(1) { if (-1 == acceptor.accept(peer)) { log("acceptor.accept failed\n"); return 1; } peer.disable(ACE_NONBLOCK); auto_ptr<char> pathname(get_url_pathname(&peer)); ACE_Mem_Map mapped_file(pathname.get()); if (-1 == (peer.send_n(mapped_file.addr(), mapped_file.size()))) { log("peer.send_n failed\n"); return 1; } peer.close(); } return acceptor.close() == -1 ? 1 : 0; }
static void * client (void *) { char buf[100]; size_t mes_len; ACE_OS::sleep (1); ACE_DEBUG ((LM_DEBUG, " (%P) Client: Starting...\n")); ACE_SOCK_Stream stream; ACE_SOCK_Connector connector; ACE_OS::sprintf (buf, "Client: the life was good!"); mes_len = (int) htonl (ACE_OS::strlen (buf) + 1); if (connector.connect (stream, ACE_INET_Addr (SERV_TCP_PORT, ACE_DEFAULT_SERVER_HOST)) == -1) ACE_ERROR ((LM_ERROR, "(%P) %p\n", "Socket open")); if (stream.send (4, (void *) &mes_len, sizeof (size_t), (void *)buf, ACE_OS::strlen (buf) + 1) == -1) ACE_ERROR ((LM_ERROR, "(%P) %p\n", "Socket send")); if (stream.close () == -1) ACE_ERROR ((LM_ERROR, "(%P) %p\n", "Socket close")); ACE_DEBUG ((LM_DEBUG, "(%P) Client: Message has been sent, about to exit...\n")); return 0; }
int main(int argc, char *argv[]) { ACE_INET_Addr addr(1500, "127.0.0.1"); //remote address ACE_SOCK_Connector con; // connector for socket client ACE_SOCK_Stream stream; // stream is for socket read/write if (con.connect(stream, addr) == -1) //connect to remote address { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) %p\n"), ACE_TEXT("connection failed"))); return 1; } const char msg[] = "Hello,ACE!"; stream.send_n(msg, sizeof(msg)); // send_n function send exactly n bytes char buffer[1024] = { 0 }; if (stream.recv(buffer, sizeof(buffer) - 1) == -1) // just call socket recv { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) %p\n"), ACE_TEXT("recv failed"))); return 1; } ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) recv:%s\n"), buffer)); if (stream.close() == -1) //close the connection { ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) %p\n"), ACE_TEXT("close"))); return 1; } return 0; }
void send_work_to_server(ACE_TCHAR* arg) { ACE_SOCK_Stream stream; ACE_SOCK_Connector connect; ACE_Time_Value delay (0, req_delay); size_t len = * reinterpret_cast<ACE_TCHAR *> (arg); for (size_t i = 0 ; i < cli_conn_no; i++) { if (connect.connect (stream, addr_) < 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("connect"))); continue; } for (size_t j = 0; j < cli_req_no; j++) { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Sending work to server on handle 0x%x, req %d\n"), stream.get_handle (), j+1)); if (stream.send_n (arg, (len + 1) * sizeof (ACE_TCHAR)) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("send_n"))); continue; } ACE_OS::sleep (delay); } stream.close (); } }
int ACE_SOCK_Connector::shared_connect_start (ACE_SOCK_Stream &new_stream, const ACE_Time_Value *timeout, const ACE_Addr &local_sap) { ACE_TRACE ("ACE_SOCK_Connector::shared_connect_start"); if (local_sap != ACE_Addr::sap_any) { sockaddr *laddr = ACE_reinterpret_cast (sockaddr *, local_sap.get_addr ()); int size = local_sap.get_size (); if (ACE_OS::bind (new_stream.get_handle (), laddr, size) == -1) { // Save/restore errno. ACE_Errno_Guard error (errno); new_stream.close (); return -1; } }
void shut_down() { ACE_SOCK_Stream stream; ACE_SOCK_Connector connect; if (connect.connect (stream, addr_) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p Error while connecting\n"), ACE_TEXT ("connect"))); const ACE_TCHAR *sbuf = ACE_TEXT ("\011shutdown"); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("shutdown stream handle = %x\n"), stream.get_handle ())); if (stream.send_n (sbuf, (ACE_OS::strlen (sbuf) + 1) * sizeof (ACE_TCHAR)) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"), ACE_TEXT ("send_n"))); stream.close (); }
static int succeed_nonblocking (void) { ACE_TCHAR test_host[MAXHOSTNAMELEN], test_addr[MAXHOSTNAMELEN + 8]; int status; ACE_INET_Addr echo_server; ACE_SOCK_Connector con; ACE_SOCK_Stream sock; ACE_Time_Value nonblock (0, 0); u_short test_port = 7; // Echo find_another_host (test_host); if (ACE_OS::strcmp (ACE_TEXT ("localhost"), test_host) == 0) { #if defined (ACE_WIN32) test_port = 80; // Echo not available on Win32; try web server #endif /* ACE_WIN32 */ } if (echo_server.set (test_port, test_host) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Host lookup for %s %p\n"), test_host, ACE_TEXT ("failed"))); return -1; } echo_server.addr_to_string (test_addr, MAXHOSTNAMELEN + 8); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing to host \"%s\", port %d (%s)\n"), test_host, test_port, test_addr)); status = con.connect (sock, echo_server, &nonblock); // Need to test the call to 'complete' really. if (status == 0 || (status == -1 && errno != EWOULDBLOCK)) { ACE_DEBUG((LM_WARNING, ACE_TEXT ("Immediate success/fail; test not completed\n"))); status = 0; } else { if (sock.get_handle () != ACE_INVALID_HANDLE) { status = con.complete (sock); } if (status == -1) { // Reset the status _before_ doing the printout, in case the // printout overwrites errno. if (errno == ECONNREFUSED) { status = 0; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Should succeed, but refused: ok\n"))); } else { ACE_ERROR ((LM_ERROR, ACE_TEXT("Errno <%d>: %p\n"), ACE_ERRNO_GET, ACE_TEXT("connect should succeed, but"))); } } else ACE_DEBUG((LM_DEBUG, ACE_TEXT("Connect which should succeed, did\n"))); } // Just in case. sock.close (); return status; }
static int fail_no_listener_nonblocking (void) { ACE_TCHAR test_host[MAXHOSTNAMELEN], test_addr[MAXHOSTNAMELEN + 8]; int status; ACE_INET_Addr nobody_home; ACE_SOCK_Connector con; ACE_SOCK_Stream sock; ACE_Time_Value nonblock (0, 0); find_another_host (test_host); if (nobody_home.set ((u_short) 42000, test_host) == -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Host lookup for %s %p\n"), test_host, ACE_TEXT ("failed"))); return -1; } nobody_home.addr_to_string (test_addr, MAXHOSTNAMELEN + 8); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Testing to host \"%s\" (%s)\n"), test_host, test_addr)); status = con.connect (sock, nobody_home, &nonblock); // Need a port that will fail. if (status == 0) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Connect which should fail didn't\n"))); status = -1; } // On some systems, a failed connect to localhost will return // ECONNREFUSED or ENETUNREACH directly, instead of // EWOULDBLOCK. That is also fine. else if (errno == EWOULDBLOCK || errno == ECONNREFUSED || errno == ENETUNREACH) { if (sock.get_handle () != ACE_INVALID_HANDLE) status = con.complete (sock); if (status != -1) { ACE_ERROR ((LM_ERROR, ACE_TEXT ("Connect which should fail didn't\n"))); status = -1; } else { ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%p\n"), ACE_TEXT ("Proper fail"))); status = 0; } } else { ACE_DEBUG ((LM_WARNING, ACE_TEXT ("Test not executed fully; ") ACE_TEXT ("expected EWOULDBLOCK, %p (%d)\n"), ACE_TEXT ("not"), ACE_ERRNO_GET)); status = -1; } // Just in case. sock.close (); return status; }
int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { // args string dicomStem(argc > 1 ? argv[1] : "/data/subjects/xc_ferro/TrioTim-35115-20070929-151440-250000/250000"); int series = argc > 2 ? atoi(argv[2]) : 10; int numImgs = argc > 3 ? atoi(argv[3]) : 248; long tr = 1000*(argc > 4 ? atof(argv[4]) : 2000); int port = argc > 5 ? atoi(argv[5]) : 15000; string host(argc > 6 ? argv[6] : "localhost"); cout << "1 using dicomStem=" << dicomStem << endl; cout << "2 using series=" << series << endl; cout << "3 using numImgs=" << numImgs << endl; cout << "4 using tr=" << tr << endl; cout << "5 using port=" << port << endl; cout << "6 using host=" << host << endl; // Local server address. ACE_INET_Addr my_addr (port, host.c_str()); // Data transfer object. ACE_SOCK_Stream stream; // Initialize the connector. ACE_SOCK_Connector connector; // keep making new connections while we havent sent the whole series DicomImage *image; for(int i = 0; i < numImgs && (image = loadNextInSeries(dicomStem,series)) != NULL && !connector.connect (stream, my_addr); i++) { cout << "made connection, loading image" << endl; image->setMinMaxWindow(); unsigned short *upixelData = (unsigned short*)(image->getOutputData(16 /* bits */)); RtExternalImageInfo *ei = new RtExternalImageInfo(); ei->lImageDataLength = image->getOutputDataSize(); ei->lNumberOfPixels = ei->lImageDataLength/2; ei->bIsMoCo = true; ei->iNoOfImagesInMosaic = 32; ei->iMosaicGridSize = 6; ei->nCol = image->getHeight()/ei->iMosaicGridSize; ei->nLin = image->getWidth()/ei->iMosaicGridSize; // ei->nCol = 64; // ei->nLin = 64; ei->dThick = 3.5; ei->dPosSag = 2.50517; ei->dPosCor = -29.9335; ei->dPosTra = -75.1856; ei->dNorSag = -0.00637429; ei->dNorCor = 0.337923; ei->dNorTra = 0.941152; ei->dRowSag = 0.99998; ei->dRowCor = 0.00194039; ei->dRowTra = 0.00607602; ei->dColSag = 0.000227022; ei->dColCor = 0.941172; ei->dColTra = -0.337928; ei->iAcquisitionNumber = i+1; cout << "sending img " << ei->iAcquisitionNumber << endl; char *data = new char[ei->iSizeOfRtExternalImageInfo]; data = ei->convertToScannerDataArray(); cout << "sending info of size " << ei->iSizeOfRtExternalImageInfo << endl; stream.send_n (data, ei->iSizeOfRtExternalImageInfo); delete data; cout << "sending img of size " << ei->lImageDataLength << endl; // shorten to 12 bits short *pixelData = (short*) malloc(image->getOutputDataSize()); for(int i = 0; i < ei->lImageDataLength/2; i++) { pixelData[i] = upixelData[i]/16; } stream.send_n (pixelData, ei->lImageDataLength); usleep(tr); stream.close(); delete ei; delete image; free(pixelData); } return 0; }
/*the repo function talk to the repo.jg.org at a regular interval, 1 minute, and send acknowledgement to repo.jg.org */ static ACE_THR_FUNC_RETURN fetch_step2(void *){ ACE_INET_Addr addr(repo_port, repo_host.c_str()); ACE_SOCK_Connector con; ACE_SOCK_Stream stream; do{ if(con.connect(stream, addr) == -1){ ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t:%l) %p\n", "connection failed"), 0); } else ACE_DEBUG ((LM_DEBUG, "(%P|%t:%l) connected to %s at port %d\n", addr.get_host_name (), addr.get_port_number ())); ACE_CString hb = ACE_CString("^^hb->"); hb+=id+"$$"; ACE_DEBUG((LM_INFO, "%l: %s\n", hb.c_str())); stream.send(hb.c_str(),hb.length()); stream.close_writer(); ACE_DEBUG((LM_INFO, "%l\n")); char* buf = new char[128]; ACE_CString str; do{ int bytes = stream.recv(buf,128); if(bytes == -1 || bytes == 0){ break; } for(int i=0; i< bytes; i++){ str += buf[i]; } }while(true); delete[] buf; stream.close(); ACE_CString acks = ACE_CString("^^"); int p1=2; int p2= str.find("->",p1); int p3 = str.find("->",p2); int p4 = str.find("||",p3); node *head=NULL, *tail=NULL; while(p1 != -1 && p2 != -1 && p3 != -1){ ACE_CString* pqr = new ACE_CString(str.substr(p1, p2 - p1)); ACE_CString* v2 = new ACE_CString(str.substr(p2, p3 - p2)); ACE_CString txn_id = str.substr(p3, p4 - p3); acks+="ack->"+txn_id+"||"; node* n = new node(pqr, v2); if(head == NULL){ head = n; tail = n; }else{ tail->next = n; tail = n; } } acks+="$$"; // delete str; if(con.connect(stream, addr) == -1){ ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t:%l) %p\n", "connection failed"), 0); } else ACE_DEBUG ((LM_DEBUG, "(%P|%t:%l) connected to %s at port %d\n", addr.get_host_name (), addr.get_port_number ())); //send out the acks ACE_DEBUG((LM_INFO, "(%P|%t:%l) %s\n",acks.c_str())); stream.send(acks.c_str(),acks.length()); stream.close(); node* tmp=head; // ACE_SOCK_Connector connector; ACE_INET_Addr _9907addr(9907,"localhost"); //ACE_SOCK_Stream stream; if(con.connect(stream, _9907addr) == -1){ ACE_ERROR_RETURN((LM_ERROR, "(%P|%t:%l) %p\n", "connection failed"),0); }else ACE_DEBUG ((LM_DEBUG, "(%P|%t) connected to %s at port %d\n", _9907addr.get_host_name (), _9907addr.get_port_number ())); ACE_CString reply = ACE_CString("^^"); while(tmp!=NULL){ bn* pqr = from_hex(tmp->pqr); bn* v2 = from_hex(tmp->v2); bn* prv = from_hex(&pr); bn* res = npmod(v2,prv,pqr); ACE_CString* resStr = res->to_hex(); /*send the output to localhost:9907*/ reply += tmp->pqr->c_str(); reply += "->" + *resStr + "||"; ACE_DEBUG((LM_DEBUG, "(%P|%t) %s\n",reply.c_str())); delete pqr; delete v2; delete prv; delete res; delete resStr; tmp = tmp->next; } reply += "$$"; stream.send(reply.c_str(),reply.length()); stream.close(); reclaim_node(head); /*sleep for 1 second, for the next poll;*/ ACE_OS::sleep(1000); }while(true); // delete str; }
int ACE_TMAIN (int, ACE_TCHAR *[]) { ACE_INET_Addr srvr (50000, ACE_LOCALHOST); ACE_SOCK_Connector connector; ACE_SOCK_Stream peer; ACE_ASSERT (connector.connect (peer, srvr) != -1); ssize_t bc; // Listing 1 code/ch06 iovec send[4]; send[0].iov_base = const_cast<char *> ("up"); send[0].iov_len = 2; send[1].iov_base = const_cast<char *> ("time"); send[1].iov_len = 4; send[2].iov_base = const_cast<char *> ("\n"); send[2].iov_len = 1; peer.sendv (send, 3); // Listing 1 // // A more clever approach would use something like this: // Where the addCommand() method allocates and populates // the query array from a set of global commands. // // Listing 2 code/ch06 iovec query[3]; addCommand (query, UPTIME); addCommand (query, HUMIDITY); addCommand (query, TEMPERATURE); peer.sendv (query, 3); // Listing 2 // Listing 3 code/ch06 iovec receive[2]; receive[0].iov_base = new char [32]; receive[0].iov_len = 32; receive[1].iov_base = new char [64]; receive[1].iov_len = 64; bc = peer.recvv (receive, 2); // Listing 3 // Listing 4 code/ch06 for (int i = 0; i < 2 && bc > 0; ++i) { size_t wc = receive[i].iov_len; if (static_cast<size_t> (bc) < wc) wc = static_cast<size_t> (bc); ACE_OS::write (ACE_STDOUT, receive[i].iov_base, wc); bc -= receive[i].iov_len; delete [] (reinterpret_cast<char *> (receive[i].iov_base)); } // Listing 4 // Listing 5 code/ch06 peer.send_n ("uptime\n", 7); iovec response; peer.recvv (&response); ACE_OS::write (ACE_STDOUT, response.iov_base, response.iov_len); delete [] reinterpret_cast<char *> (response.iov_base); // Listing 5 peer.close (); return (0); }
int ACE_TMAIN(int argc, ACE_TCHAR **argv) { // size and count for transmissions int size = 0, count = -1; // the server's answer is a single byte char answer; // parse the <size> argument if ((argc < 2) || (((size = ACE_OS::strtol(argv[1], 0, 10)) < 1) || (errno == EINVAL))) return printUsage(argv[0]); // take size as the number of MiB and create appropriate buffer size *= BASE; char *someData = new (std::nothrow) char[size]; if (someData == 0) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%N:%l: Failed to allocate ") ACE_TEXT ("data buffer.\n")), -1); // put someData in an auto_ptr so it gets deleted automatically auto_ptr<char> pSomeData(someData); // parse the <count> argument if available if ((argc == 3) && (((count = ACE_OS::strtol(argv[2], 0, 10)) < 1) || (errno == EINVAL))) return printUsage(argv[0]); // the server listens on localhost on default port (from common.h) ACE_INET_Addr serverAddr(PORT, "localhost"); ACE_SOCK_Stream stream; ACE_SOCK_Connector connector; // -1 is running indefinitely while ((count == -1) || (count-- != 0)) { // some output, that we know something is happening //ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l: Passes left: %i\n"), count)); ACE_DEBUG((LM_DEBUG, ACE_TEXT("."))); // connect to the server and get the stream if (connector.connect(stream, serverAddr) == -1) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to connect to ") ACE_TEXT ("server. (errno = %i: %m)\n"), ACE_ERRNO_GET)); break; } try { // send the request to the server (number of MiB in the next call) // Note: only use the sizeof and pointer to int on compatible // platforms (i.e. little-endian/big-endian, data type size) if (stream.send_n(&size, sizeof(size), &connTimeout) != sizeof(size)) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to send ") ACE_TEXT ("request. (errno = %i: %m)\n"), ACE_ERRNO_GET)); throw 1; } // receive the answer if (stream.recv_n(&answer, sizeof(answer), &connTimeout) != 1) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N: %l: Failed to receive ") ACE_TEXT ("1st response. (errno = %i: %m)\n"), ACE_ERRNO_GET)); throw 1; } // server answer, 'K" indicates a positive answer if (answer == 'K') { // send a huge message to the server if (stream.send_n(someData, size, &connTimeout) != size) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to send ") ACE_TEXT ("someData. (errno = %i: %m)\n"), ACE_ERRNO_GET)); throw 1; } // get an answer if (stream.recv_n(&answer, sizeof(answer), &connTimeout) != 1) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N: %l: Failed to receive ") ACE_TEXT ("2nd response. (errno = %i: %m)\n"), ACE_ERRNO_GET)); throw 1; } // check the answer if (answer != 'K') { cout << "The server was unable to process the data." << endl; } } } catch (...) { // ok we know an error occurred, we need to close the socket. // The we'll try again. } // close the current stream if (stream.close() == -1) { ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to close ") ACE_TEXT ("socket. (errno = %i: %m)\n"), ACE_ERRNO_GET)); break; } } // while cout << "Bye. Bye" << endl; return 0; }
/*the accept function*/ static ACE_THR_FUNC_RETURN accept_step1(void *arg) { /*ACE_INET_Addr addr;*/ ACE_SOCK_Stream stream; ACE_HANDLE handle = (ACE_HANDLE)(intptr_t) arg; stream.set_handle(handle); if(stream.disable(ACE_NONBLOCK) == -1){ ACE_ERROR_RETURN((LM_ERROR, "%p\n","get_remote_addr"),0); } /* ACE_DEBUG ((LM_INFO, "(%P|%t) client %s connected from %d\n", addr.get_host_name (), addr.get_port_number ())); */ char* buf = new char[128]; ACE_CString* str = new ACE_CString(); do{ int bytes= stream.recv(buf,128); ACE_DEBUG((LM_INFO, "(%P|%t:%l) bytes = %d\n",bytes)); if(bytes == -1|| bytes == 0){ break; } for(int i=0 ;i < bytes; i++){ *str += buf[i]; } }while(true); delete[] buf; //the input format is '^^pqr->v1$$'; int pos = str->find("->"); int tail = str->find("$$"); ACE_CString* pqr = new ACE_CString(str->substr(2,pos-2)); ACE_CString* pv1 = new ACE_CString(str->substr(pos+2, tail - pos - 2)); ACE_DEBUG((LM_INFO, "(%P|%t:%l) pqr: %s\n pv1:%s\n",pqr->c_str(),pv1->c_str())); bn* _pqr = from_hex(pqr); bn* _v1 = from_hex(pv1); bn* _pr = from_hex(&pr); bn* _r = npmod( _v1, _pr, _pqr); ACE_CString* result = _r->to_hex(); ACE_DEBUG((LM_INFO, "(%P|%t:%l)pqr:%s step1:%s ", pqr->c_str(), result->c_str())); ACE_CString reply = ACE_CString("ack"); stream.send(reply.c_str() , reply.length()); stream.close(); /*send the step1 result to hub:10007 */ ACE_SOCK_Connector connector; ACE_INET_Addr hub_addr(port,hub.c_str()); ACE_DEBUG((LM_DEBUG, "(%P|%t:%l) port:%d host:%s\n", port, hub.c_str())); if(connector.connect(stream, hub_addr) == -1){ ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "connection failed"), 0); } else ACE_DEBUG ((LM_DEBUG, "(%P|%t) connected to %s at port %d\n", hub_addr.get_host_name (), hub_addr.get_port_number ())); /* * message layout: ^^pqr->digest->senderid$$ */ ACE_CString input = ACE_CString("^^"); input += *pqr; input += "->"; input += *result; input += "->"; input += id ; input += "$$"; ACE_DEBUG((LM_INFO, "(%P|%t:%l) input of step1:%s\n", input.c_str())); if(stream.send(input.c_str(),input.length()) != input.length()){ ACE_ERROR((LM_ERROR, "%p\n","send")); } stream.close(); delete str; delete pqr; delete pv1; delete _pqr; delete _v1; delete _pr; delete _r; delete result; return 0; }
int ACE_Pipe::open (int buffer_size) { ACE_TRACE ("ACE_Pipe::open"); #if defined (ACE_LACKS_SOCKETPAIR) ACE_INET_Addr my_addr; ACE_SOCK_Acceptor acceptor; ACE_SOCK_Connector connector; ACE_SOCK_Stream reader; ACE_SOCK_Stream writer; int result = 0; # if defined (ACE_WIN32) ACE_INET_Addr local_any (static_cast<u_short> (0), ACE_LOCALHOST); # else ACE_Addr local_any = ACE_Addr::sap_any; # endif /* ACE_WIN32 */ // Bind listener to any port and then find out what the port was. if (acceptor.open (local_any) == -1 || acceptor.get_local_addr (my_addr) == -1) result = -1; else { ACE_INET_Addr sv_addr (my_addr.get_port_number (), ACE_LOCALHOST); // Establish a connection within the same process. if (connector.connect (writer, sv_addr) == -1) result = -1; else if (acceptor.accept (reader) == -1) { writer.close (); result = -1; } } // Close down the acceptor endpoint since we don't need it anymore. acceptor.close (); if (result == -1) return -1; this->handles_[0] = reader.get_handle (); this->handles_[1] = writer.get_handle (); # if !defined (ACE_LACKS_TCP_NODELAY) int one = 1; // Make sure that the TCP stack doesn't try to buffer small writes. // Since this communication is purely local to the host it doesn't // affect network performance. if (writer.set_option (ACE_IPPROTO_TCP, TCP_NODELAY, &one, sizeof one) == -1) { this->close (); return -1; } # endif /* ! ACE_LACKS_TCP_NODELAY */ # if defined (ACE_LACKS_SO_RCVBUF) && defined (ACE_LACKS_SO_SNDBUF) ACE_UNUSED_ARG (buffer_size); # endif # if !defined (ACE_LACKS_SO_RCVBUF) if (reader.set_option (SOL_SOCKET, SO_RCVBUF, reinterpret_cast <void *> (&buffer_size), sizeof (buffer_size)) == -1 && errno != ENOTSUP) { this->close (); return -1; } # endif /* !ACE_LACKS_SO_RCVBUF */ # if !defined (ACE_LACKS_SO_SNDBUF) if (writer.set_option (SOL_SOCKET, SO_SNDBUF, reinterpret_cast <void *> (&buffer_size), sizeof (buffer_size)) == -1 && errno != ENOTSUP) { this->close (); return -1; } # endif /* !ACE_LACKS_SO_SNDBUF */ #elif defined (ACE_HAS_STREAM_PIPES) || defined (__QNX__) ACE_UNUSED_ARG (buffer_size); if (ACE_OS::pipe (this->handles_) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("pipe")), -1); #if !defined(__QNX__) int arg = RMSGN; // Enable "msg no discard" mode, which ensures that record // boundaries are maintained when messages are sent and received. if (ACE_OS::ioctl (this->handles_[0], I_SRDOPT, (void *) arg) == -1 || ACE_OS::ioctl (this->handles_[1], I_SRDOPT, (void *) arg) == -1) { this->close (); ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("ioctl")), -1); } #endif /* __QNX__ */ #else /* ! ACE_LACKS_SOCKETPAIR && ! ACE_HAS_STREAM_PIPES */ if (ACE_OS::socketpair (AF_UNIX, SOCK_STREAM, 0, this->handles_) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"), ACE_TEXT ("socketpair")), -1); # if defined (ACE_LACKS_SO_SNDBUF) && defined (ACE_LACKS_SO_RCVBUF) ACE_UNUSED_ARG (buffer_size); # endif # if !defined (ACE_LACKS_SO_RCVBUF) if (ACE_OS::setsockopt (this->handles_[0], SOL_SOCKET, SO_RCVBUF, reinterpret_cast <const char *> (&buffer_size), sizeof (buffer_size)) == -1 && errno != ENOTSUP) { this->close (); return -1; } # endif # if !defined (ACE_LACKS_SO_SNDBUF) if (ACE_OS::setsockopt (this->handles_[1], SOL_SOCKET, SO_SNDBUF, reinterpret_cast <const char *> (&buffer_size), sizeof (buffer_size)) == -1 && errno != ENOTSUP) { this->close (); return -1; } # endif /* ! ACE_LACKS_SO_SNDBUF */ # if defined (ACE_OPENVMS) && !defined (ACE_LACKS_TCP_NODELAY) int one = 1; // OpenVMS implements socketpair(AF_UNIX...) by returning AF_INET sockets. // Since these are plagued by Nagle as any other INET socket we need to set // TCP_NODELAY on the write handle. if (ACE_OS::setsockopt (this->handles_[1], ACE_IPPROTO_TCP, TCP_NODELAY, reinterpret_cast <const char *> (&one), sizeof (one)) == -1) { this->close (); return -1; } # endif /* ACE_OPENVMS && !ACE_LACKS_TCP_NODELAY */ #endif /* ! ACE_LACKS_SOCKETPAIR && ! ACE_HAS_STREAM_PIPES */ // Point both the read and write HANDLES to the appropriate socket // HANDLEs. return 0; }
// conduct the UnMarshalled Octet performance test using separate // send_n calls with Nagle's algorithm disabled ACE_SCTP::HIST runUnmarshalledOctetTest(ACE_CDR::Octet *buf, size_t seqLen, ACE_SOCK_Stream & stream){ ACE_CDR::ULong const testIterations = Options_Manager::test_iterations; size_t bt; ACE_CDR::ULong cnt = 0; // variables for the timing measurements ACE_hrtime_t startTime, endTime; ACE_CDR::Double messageLatency_usec = 0.0; ACE_CDR::ULong msgLen = seqLen*ACE_CDR::OCTET_SIZE; // explicity configure Nagling. Default is // Options_Manager::test_enable_nagle=0 so default configurations is // NO NAGLING ACE_CDR::Long nagle; if (Options_Manager::test_enable_nagle) nagle=0; else nagle=1; if (Options_Manager::test_transport_protocol == IPPROTO_SCTP){ // default - sctp case if (-1 == stream.set_option(IPPROTO_SCTP, SCTP_NODELAY, &nagle, sizeof nagle)) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "set_option"), 0); } else { // tcp case if (-1 == stream.set_option(IPPROTO_TCP, TCP_NODELAY, &nagle, sizeof nagle)) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "set_option"), 0); } // prime the client and server before starting the test for(cnt=0;cnt<primerIterations;++cnt){ // send message size // TODO : The message length should be CDR encoded ACE_CDR::ULong msgLenExpressed = ACE_HTONL(msgLen); if (-1 == stream.send_n (&msgLenExpressed, ACE_CDR::LONG_SIZE, 0, &bt)) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send_n"), 0); // send a message if (-1 == stream.send_n (buf, msgLen, 0, &bt)) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send_n"), 0); // block for a Short reply ACE_CDR::Short reply; if ((stream.recv_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1) ACE_ERROR_RETURN((LM_ERROR, "%p\n", "recv_n"), 0); } // AFTER PRIMING THE PUMP CREATE THE HISTOGRAM ACE_SCTP::HIST aceStream_hist = 0; aceStream_hist = createHistogram(msgLen); if (0 == aceStream_hist) ACE_ERROR_RETURN((LM_ERROR, "%p\n", "histogram create failed"), 0); iovec iov[2]; // PERFORMANCE TEST LOOP for (cnt = 0; cnt < testIterations; ++cnt){ // get the start time startTime = ACE_OS::gethrtime(); if (!startTime) ACE_ERROR_RETURN((LM_ERROR, "%p\n", "ACE_OS::gethrtime()"), 0); ACE_CDR::ULong msgLenExpressed = ACE_HTONL(msgLen); iov[0].iov_base = reinterpret_cast<char *> (&msgLenExpressed); iov[0].iov_len = ACE_CDR::LONG_SIZE; iov[1].iov_base = reinterpret_cast<char *> (buf); iov[1].iov_len = msgLen; if (-1 == stream.sendv_n (iov, 2)) ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "send_n"), 0); // block for a Short reply ACE_CDR::Short reply; if ((stream.recv_n(&reply, ACE_CDR::SHORT_SIZE, 0, &bt)) == -1) ACE_ERROR_RETURN((LM_ERROR, "%p\n", "recv_n"), 0); // get the end time endTime = ACE_OS::gethrtime(); if (!endTime) ACE_ERROR_RETURN((LM_ERROR, "%p\n", "ACE_OS::gethrtime()"), 0); // compute the message latency in micro-seconds messageLatency_usec = (static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER(endTime)) - static_cast<double> (ACE_UINT64_DBLCAST_ADAPTER(startTime))) / microsec_clock_scale_factor; // record the message latency in the histogram ACE_SCTP::record(messageLatency_usec, aceStream_hist); } // THE HEADER MESSAGE SENT TO THE SERVER CONTAINED THE NUMBER OF // PRIMER AND TEST MESSAGES TO BE SENT AFTER WHICH THE SERVER WILL // CLOSE THE STREAM SO ONCE WE REACH THIS POINT THE STREAM IS NO // LONGER VALID AND WE CLOSE IT. stream.close(); // allocated by runTest delete[] buf; return aceStream_hist; }
int ACE_SOCK_Connector::shared_connect_finish (ACE_SOCK_Stream &new_stream, const ACE_Time_Value *timeout, int result) { ACE_TRACE ("ACE_SOCK_Connector::shared_connect_finish"); // Save/restore errno. ACE_Errno_Guard error (errno); if (result == -1 && timeout != 0) { // Check whether the connection is in progress. if (error == EINPROGRESS || error == EWOULDBLOCK) { // This expression checks if we were polling. if (timeout->sec () == 0 && timeout->usec () == 0) { #if defined(ACE_WIN32) // In order to detect when the socket that has been // bound to is in TIME_WAIT we need to do the connect // (which will always return EWOULDBLOCK) and then do an // ACE::handle_timed_complete() (with timeout==0, // i.e. poll). This will do a select() on the handle // which will immediately return with the handle in an // error state. The error code is then retrieved with // getsockopt(). Good sockets however will return from // the select() with ETIME - in this case return // EWOULDBLOCK so the wait strategy can complete the // connection. if(ACE::handle_timed_complete (new_stream.get_handle (), timeout) == ACE_INVALID_HANDLE) { int const tmp = errno; if (tmp != ETIME) { error = tmp; } else error = EWOULDBLOCK; } else result = 0; #else /* ACE_WIN32 */ error = EWOULDBLOCK; #endif /* ACE_WIN32 */ } // Wait synchronously using timeout. else if (this->complete (new_stream, 0, timeout) == -1) error = errno; else return 0; } } // EISCONN is treated specially since this routine may be used to // check if we are already connected. if (result != -1 || error == EISCONN) // Start out with non-blocking disabled on the <new_stream>. new_stream.disable (ACE_NONBLOCK); else if (!(error == EWOULDBLOCK || error == ETIMEDOUT)) new_stream.close (); return result; }