这篇教程C++ ACE_SOCK_Connector类代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中ACE_SOCK_Connector类的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Connector类的具体用法?C++ ACE_SOCK_Connector怎么用?C++ ACE_SOCK_Connector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。 在下文中一共展示了ACE_SOCK_Connector类的28个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: mainint main(int argc, char** argv){ if(argc < 2){ cerr << "Invalid arguments!"<<endl; return returnType::invalid_argument; } const unsigned short port = 2000; ACE_INET_Addr addr(port, ACE_LOCALHOST); ACE_SOCK_Connector connector; ACE_SOCK_Stream stream; if(connector.connect(stream,addr) < 0){ cerr << endl << "Can not connect to server!" <<endl; return -1; } Client *client; ACE_NEW_RETURN(client, Client(argc, argv, stream), -1); ACE_Time_Value value(3,0); ACE_Reactor::instance()->schedule_timer(client, 0, value, value); while(true){ if(SignalHandler::is_interrupted()){ break; } ACE_Reactor::instance()->handle_events(); } return returnType::success;}
开发者ID:higerra,项目名称:cse532,代码行数:28,
示例2: connectGatevoid ManageGateSession::connectGate(){ const GateCfgVec_t & gate_cfg_vec = ManageConfig::instance()->getGateCfg(); ACE_SOCK_Connector connector; ACE_INET_Addr addr; for (GateCfgVec_t::const_iterator it = gate_cfg_vec.begin(); it != gate_cfg_vec.end(); ) { addr.set(it->port, it->ip.c_str()); GateSession * gate_session = new GateSession(); if (connector.connect(gate_session->peer(), addr) == -1) { DEF_LOG_ERROR("Failed to connector gate, ip is <%s>, port is <%d>, last error is <%d>/n", it->ip.c_str(), it->port, ACE_OS::last_error()); ACE_OS::sleep(1); continue; } else { gate_session->setPacketHandler(RouteGatePacket::instance()); gate_session->netConnected(); gate_session->peer().enable(ACE_NONBLOCK); int flag = 1; gate_session->peer().set_option(IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag)); m_reactor->register_handler(gate_session, ACE_Event_Handler::READ_MASK); ++it; } }}
开发者ID:BianJian,项目名称:steppingstone,代码行数:28,
示例3: sizeofvoidACE::HTBP::Session::reconnect_i (ACE::HTBP::Channel *s) const{ ACE_SOCK_Connector conn; if (conn.connect (s->ace_stream(),*this->proxy_addr_) == -1) { ACE_TCHAR buffer[128]; this->proxy_addr_->addr_to_string(buffer, 128, 0); ACE_ERROR ((LM_ERROR, ACE_TEXT("(%P|%t) ACE::HTBP::Session::reconnect") ACE_TEXT(" failed to %s, %p/n"), buffer, s == this->inbound_ ? ACE_TEXT("inbound") : ACE_TEXT ("outbound"))); } else {#if !defined (ACE_LACKS_TCP_NODELAY) int no_delay = 1; int result = s->ace_stream().set_option (ACE_IPPROTO_TCP, TCP_NODELAY, (void *) &no_delay, sizeof (no_delay)); if (result == -1) ACE_DEBUG ((LM_DEBUG, "HTBP::Session::reconnect_i, %p/n", "set_option" ));#endif /* ! ACE_LACKS_TCP_NODELAY */ } s->register_notifier(this->reactor_); if (s == this->inbound_) s->send_ack();}
开发者ID:INMarkus,项目名称:ATCD,代码行数:31,
示例4: tvint extractCron::do_job(char *jobdesc){ ACE_SOCK_Connector conn; ACE_SOCK_Stream peer; ACE_Time_Value tv(3, 0); ACE_INET_Addr addr(harvestPort, harvestIPaddr); char urlbuff[1024]; StrStream httpreq; int ret; printf("JobDesc: %s/n", jobdesc); CGI::escape(urlbuff, jobdesc); httpreq.init(2); // 2 kilobytes buff httpreq.rawadd("GET /harvest?expr="); httpreq.rawadd(urlbuff); httpreq.rawadd(" HTTP/1.1/n/n"); httpreq.print(); if ( conn.connect(peer, addr) < 0) { printf("conn failed!/n"); return 0; } ret = peer.send( httpreq.str(), httpreq.len() ); return 0; }
开发者ID:handol,项目名称:OldWorks,代码行数:28,
示例5: factory_addrintFT_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;}
开发者ID:CCJY,项目名称:ATCD,代码行数:33,
示例6: clientstatic void *client (void *arg){ ACE_INET_Addr *remote_addr = (ACE_INET_Addr *) arg; ACE_INET_Addr server_addr (remote_addr->get_port_number (), ACE_IPV6_LOCALHOST); ACE_SOCK_Stream cli_stream; ACE_SOCK_Connector con; ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) starting non-blocking connect/n"))); // Initiate timed, non-blocking connection with server. // Attempt a non-blocking connect to the server. if (con.connect (cli_stream, server_addr, (ACE_Time_Value *) &ACE_Time_Value::zero) == -1) { if (errno != EWOULDBLOCK) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("connection failed"))); ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) starting timed connect/n"))); // Check if non-blocking connection is in progress, // and wait up to ACE_DEFAULT_TIMEOUT seconds for it to complete. ACE_Time_Value tv (ACE_DEFAULT_TIMEOUT); if (con.complete (cli_stream, &server_addr, &tv) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("connection failed")), 0); else ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) connected to %C/n"), server_addr.get_host_name ())); } if (cli_stream.disable (ACE_NONBLOCK) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("disable"))); // Send data to server (correctly handles "incomplete writes"). for (const char *c = ACE_ALPHABET; *c != '/0'; c++) if (cli_stream.send_n (c, 1) == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("send_n"))); // Explicitly close the writer-side of the connection. if (cli_stream.close_writer () == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("close_writer"))); char buf[1]; // Wait for handshake with server. if (cli_stream.recv_n (buf, 1) != 1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("recv_n"))); // Close the connection completely. if (cli_stream.close () == -1) ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%P|%t) %p/n"), ACE_TEXT ("close"))); return 0;}
开发者ID:INMarkus,项目名称:ATCD,代码行数:58,
示例7: processint logClient::process(ACE_CString* s){ ACE_SOCK_Stream logger; ACE_SOCK_Connector connector; ACE_INET_Addr addr(9876, "127.0.0.1"); if(connector.connect(logger, addr) == -1){ ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%p /n"), ACE_TEXT("open")), -1); } ACE_Log_Record record(LM_DEBUG, ACE_OS::time ((time_t *) 0), ACE_OS::getpid()); record.msg_data(s.c_str()); const size_t max_payload_size = 4 + 8 + 4 + 4 + ACE_Log_Record::MAXLOGMSGLEN + ACE_CDR::MAX_ALIGNMENT; ACE_OutputCDR payload(max_payload_size); payload<< record; ACE_CDR::ULong length = ACE_Utils::truncate_cast<ACE_CDR::ULong> (payload.total_length()); ACE_OutputCDR header (ACE_CDR::MAX_ALIGNMENT + 8); header << ACE_OutputCDR::from_boolean (ACE_CDR_BYTE_ORDER); header << ACE_CDR::ULong(length); iovec iov[2]; iov[0].iov_base = header.begin() -> rd_ptr(); iov[0].iov_len = 8; iov[1].iov_base = payload.begin() -> rd_ptr(); iov[1].iov_len = length; if (logger.sendv_n(iov, 2) == -1) ACE_ERROR_RETURN((LM_ERROR,"%p/n","send"), -1); /* */ ACE_Message_Block* header_p; auto_ptr<ACE_Message_Block> header(header_p); ACE_CDR::mb_align(header.get()); ACE_Message_Block* payload_p; ssize_t count = logger.recv_n(header->wr_ptr(),8); switch(count){ default: case -1: case 0: case 8: break; } header->wr_ptr(8); }
开发者ID:jungu,项目名称:brokenseal,代码行数:58,
示例8: server_addrint connection::connect(char *hostname_opt_port, int tcp_nodelay, int sockbufsiz) { if(!hostname_opt_port) return 1; char *hostname_with_port; // Check to see if portnumber is specified in the hostnameport // If not, append :80 if(!ACE_OS::strchr(hostname_opt_port,':')) { hostname_with_port = new char[ACE_OS::strlen(hostname_opt_port) + 3]; ACE_OS::sprintf(hostname_with_port, "%s:%d", hostname_opt_port, 80); } else { hostname_with_port = hostname_opt_port; } // Beyond this point, hostname_with_port is of the form hostname:port ACE_INET_Addr server_addr(hostname_with_port); // Connect to server ACE_SOCK_Connector con; if(con.connect(stream_, server_addr) == -1) { ACE_OS::perror("ACE_SOCK_Connector::connect"); return 1; } // tcp_nodelay processing. // turn off weird ack things if(tcp_nodelay) { struct protoent *p = ACE_OS::getprotobyname ("tcp"); int one = 1; if (p && stream_.set_option (p->p_proto, TCP_NODELAY, (char *)& one, sizeof (one))) { ACE_OS::perror("tcp_nodelay"); return 1; } } if(sockbufsiz) if (stream_.set_option (SOL_SOCKET, SO_RCVBUF, (char *) &sockbufsiz, sizeof sockbufsiz) == -1) { ACE_OS::perror("socket_queue_size"); return 1; } return 0;}
开发者ID:azraelly,项目名称:knetwork,代码行数:57,
示例9: ACE_TMAINintACE_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;}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:56,
示例10: openint Client::open(const char *server, u_short port){ ACE_SOCK_Connector connector; ACE_INET_Addr addr(port, server); if(connector.connect(*this, addr) == -1) { ACE_ERROR_RETURN((LM_ERROR, "%p/n", "open"), -1); } initialized_ = 1; return 0;}
开发者ID:heihachi,项目名称:AceBot,代码行数:11,
示例11: mainintmain (int argc, char *argv[]){#if !defined (ACE_LACKS_ACE_IOSTREAM) const char *server_host = argc > 1 ? argv[1] : ACE_DEFAULT_SERVER_HOST; u_short server_port = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_SERVER_PORT; ACE_IOStream<ACE_SOCK_Stream> server; ACE_SOCK_Connector connector; ACE_INET_Addr addr (server_port, server_host); if (connector.connect (server, addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "open"), -1); // Buffer up some things to send to the server. server << "1 2.3 testing" << endl; int i; float f;#if defined (ACE_HAS_STRING_CLASS) ACE_IOStream_String s1; ACE_IOStream_String s2; server >> s1 >> i >> f >> s2; cerr << "Server said:/n/t"; cerr << s1 << " "; cerr << i << " "; cerr << f << " "; cerr << s2 << endl;#else server >> i >> f; cerr << "(" << ACE_OS::getpid () << ") Server sent:/n/t"; cerr << "(" << i << ") "; cerr << "(" << f << ")" << endl;#endif /* ACE_HAS_STRING_CLASS */ if (server.close () == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "close"), -1);#else ACE_UNUSED_ARG (argc); ACE_UNUSED_ARG (argv); ACE_ERROR ((LM_ERROR, "ACE_IOSTREAM not supported on this platform/n"));#endif /* !ACE_LACKS_ACE_IOSTREAM */ return 0;}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:54,
示例12: ACE_ERROR_RETURNintSender::open (const ACE_TCHAR *host, u_short port){ // Initialize stuff // Open input file (in OVERLAPPED mode) this->input_file_ = ACE_OS::open (file, GENERIC_READ | FILE_FLAG_OVERLAPPED); if (this->input_file_ == ACE_INVALID_HANDLE) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_OS::open"), -1); // Find file size this->file_size_ = ACE_OS::filesize (this->input_file_); // Connect to remote host ACE_INET_Addr address (port, host); ACE_SOCK_Connector connector; if (connector.connect (this->stream_, address) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_SOCK_Connector::connect"), -1); // Open ACE_Asynch_Write_Stream if (this->ws_.open (*this) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_Asynch_Write_Stream::open"), -1); // Open ACE_Asynch_Read_File if (this->rf_.open (*this, this->input_file_) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_Asynch_Read_File::open"), -1); // Start an asynchronous transmit file if (this->transmit_file () == -1) return -1; // Start an asynchronous read file if (this->initiate_read_file () == -1) return -1; return 0;}
开发者ID:binghuo365,项目名称:BaseLab,代码行数:52,
示例13: ACE_DEBUGintScavenger_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;}
开发者ID:OspreyHub,项目名称:ATCD,代码行数:51,
示例14: open bool open() { ACE_SOCK_Connector connector; ACE_INET_Addr addr(80,"127.0.0.1"); ACE_Time_Value timeout(5,0); if(connector.connect(peer,addr,&timeout) != 0) { cout<<"connecetd fail"<<endl; return false; } ACE_Reactor::instance()->register_handler(this,ACE_Event_Handler::READ_MASK); cout<<"connecetd "<<endl; return true; }
开发者ID:walterfan,项目名称:snippets,代码行数:14,
示例15: workerstatic ACE_THR_FUNC_RETURNworker (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;}
开发者ID:PGSeungminLee,项目名称:CGSF,代码行数:49,
示例16: connectint ShmemHybridStream::connect(const ACE_INET_Addr& ace_address){ if (m_bLinked) return -1; ACE_SOCK_Connector connector; YARP_SSIZE_T result=connector.connect(m_SockStream,ace_address); if (result<0) { YARP_ERROR(Logger::get(),ConstString("ShmemHybridStream client returned ")+NetType::toString((int)result)); close(); return -1; } ACE_INET_Addr local,remote; m_SockStream.get_local_addr(local); m_SockStream.get_remote_addr(remote); m_LocalAddress=Contact(local.get_host_addr(),local.get_port_number()); m_RemoteAddress=Contact(remote.get_host_addr(),remote.get_port_number()); out.open(m_LocalAddress.getPort()); ShmemPacket_t send_conn_data; send_conn_data.command=CONNECT; send_conn_data.size=SHMEM_DEFAULT_SIZE; result=m_SockStream.send_n(&send_conn_data,sizeof send_conn_data); if (result<=0) { YARP_ERROR(Logger::get(),ConstString("Socket returned ")+NetType::toString((int)result)); close(); return -1; } ShmemPacket_t recv_conn_data; result=m_SockStream.recv_n(&recv_conn_data,sizeof recv_conn_data); if (result<=0) { YARP_ERROR(Logger::get(),ConstString("Socket returned ")+NetType::toString((int)result)); close(); return -1; } in.open(m_RemoteAddress.getPort(),&m_SockStream); m_bLinked=true; m_SockStream.enable(ACE_NONBLOCK); return 0;}
开发者ID:giuliavezzani,项目名称:yarp,代码行数:49,
示例17: addrint 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;}
开发者ID:nykma,项目名称:ykt4sungard,代码行数:48,
示例18: do_connect_svrint GDCT_Transfer::do_connect_svr(){ ACE_SOCK_Connector conn; ACE_INET_Addr addr(svr_port_,svr_ip_.c_str()); ACE_Time_Value to = default_timeout_; if(conn.connect(connector_,addr,&default_timeout_)!=0) { int r = ACE_OS::last_error(); ACE_DEBUG((LM_ERROR,"连接讯源服务器失败[%s:%d]ret[%d:%s]",svr_ip_.c_str(),svr_port_, r,ACE_OS::strerror(r))); return -1; } ACE_DEBUG((LM_INFO,"连接讯源服务器成功[%s:%d]",svr_ip_.c_str(),svr_port_)); is_connected_ = 1; return 0;}
开发者ID:nykma,项目名称:ykt4sungard,代码行数:16,
示例19: open bool open() { ACE_SOCK_Connector connector; ACE_INET_Addr addr(7777,"127.0.0.1"); ACE_Time_Value timeout(5,0); if(connector.connect(peer,addr,&timeout) != 0) { cout<<endl<<"connect fail."; return false; } ACE_Reactor::instance()->register_handler(this,ACE_Event_Handler::READ_MASK); cout<<endl<<"connected."; strcpy(buf, "hello,Server/n"); peer.send(buf,strlen(buf)); return true; }
开发者ID:hzsunzixiang,项目名称:programming,代码行数:16,
示例20: TryToConnectbool Collector::TryToConnect(ACE_SOCK_Connector& con,ACE_SOCK_Stream& peer){ if(data_source_.node_list.size() == 0) { std::ostringstream oss; oss << data_source_.name << " have no legal IP"; LOG4CXX_WARN(log_,oss.str()); return false; } for(int i=0;i<data_source_.node_list.size();i++) { std::string ip_temp = data_source_.node_list[i].ip; unsigned int port = data_source_.node_list[i].port; ACE_INET_Addr addr(port,ip_temp.c_str()); if(con.connect(peer,addr)==0) { return true; } } std::ostringstream oss; oss << "can not connect every host in cluster:" << data_source_.name; LOG4CXX_WARN(log_,oss.str()); return false;}
开发者ID:keyboard-man,项目名称:kelp,代码行数:29,
示例21: mainint 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();}
开发者ID:qingxia,项目名称:IvanChenGit,代码行数:47,
示例22: sv_addrintPipe::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;}
开发者ID:helixum,项目名称:wow-cata,代码行数:46,
示例23: addr/* Open a connection to the server. This hides the use of ACE_SOCK_Connector from our caller. Since our caller probably doesn't care *how* we connect, this is a good thing. */intClient::open (const char *server, u_short port){ /* This is right out of Tutorial 3. The only thing we've added is to set the initialized_ member variable on success. */ ACE_SOCK_Connector connector; ACE_INET_Addr addr (port, server); if (connector.connect (*this, addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "open"), -1); initialized_ = 1; return 0;}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:21,
示例24: ACE_ERROR_RETURNintACE::HTBP::ID_Requestor::connect_to_server (ACE_SOCK_Stream *cli_stream){ if (port_ == 0 || host_.length() == 0) { int host_start = url_.find (ACE_TEXT("http://")) + 7; int port_sep = 0; int sep = 0; if (host_start == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") ACE_TEXT("connect_to_server: ") ACE_TEXT("invalid URL: /"%s/"/n"), url_.c_str()), -1); port_sep = url_.find (ACE_TEXT(":"),(size_t)host_start); sep = url_.find (ACE_TEXT("/"),(size_t)host_start); if (sep == -1 || sep == host_start +1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") ACE_TEXT("connect_to_server: ") ACE_TEXT("invalid URL: /"%s/"/n"), url_.c_str()), -1); if (port_sep == -1) { port_sep = sep; port_ = 80; // should be a default? } host_ = url_.substr(host_start,port_sep - host_start); } ACE_INET_Addr remote_addr (static_cast<u_short> (port_), host_.c_str()); ACE_SOCK_Connector con; if (con.connect (*cli_stream, remote_addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") ACE_TEXT("connect_to_server: ") ACE_TEXT("%p/n"), ACE_TEXT("socket connect")), -1); return 0;}
开发者ID:CCJY,项目名称:ACE,代码行数:44,
示例25: host_is_upstatic u_inthost_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;}
开发者ID:INMarkus,项目名称:ATCD,代码行数:19,
示例26: addressint Sender::open (const ACE_TCHAR *host, u_short port){ // Initialize stuff // Connect to remote host ACE_INET_Addr address (port, host); ACE_SOCK_Connector connector; if (connector.connect (this->stream_, address) == -1) { ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_SOCK_Connector::connect"), -1); } // Open ACE_Asynch_Write_Stream if (this->ws_.open (*this) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_Asynch_Write_Stream::open"), -1); // Open ACE_Asynch_Read_Stream if (this->rs_.open (*this) == -1) ACE_ERROR_RETURN ((LM_ERROR, "%p/n", "ACE_Asynch_Read_File::open"), -1); // Start an asynchronous transmit file if ( this->initiate_write_stream () == -1) return -1; if ( duplex != 0 ) { // Start an asynchronous read file if (this->initiate_read_stream () == -1) return -1; } return 0;}
开发者ID:BackupTheBerlios,项目名称:pyasynchio-svn,代码行数:43,
示例27: clientstatic 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;}
开发者ID:asdlei00,项目名称:ACE,代码行数:42,
示例28: cli_workerstatic ACE_THR_FUNC_RETURNcli_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;}
开发者ID:INMarkus,项目名称:ATCD,代码行数:42,
注:本文中的ACE_SOCK_Connector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ ACE_SOCK_Stream类代码示例 C++ ACE_Reactor_Impl类代码示例 |