本文整理汇总了C++中ACE_SOCK_Connector::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Connector::connect方法的具体用法?C++ ACE_SOCK_Connector::connect怎么用?C++ ACE_SOCK_Connector::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Connector
的用法示例。
在下文中一共展示了ACE_SOCK_Connector::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addr
int
ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
#if !defined (ACE_LACKS_ACE_IOSTREAM)
const ACE_TCHAR *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;
}
示例2: open
int 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;
}
示例3: ACE_ERROR_RETURN
int
Sender::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;
}
示例4: remote_sap
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;
}
示例5: 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;
}
示例6: addr
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;
}
示例7: connect
int 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;
}
示例8: open
int SocketTwoWayStream::open(const Contact& address) {
if (address.getPort()==-1) {
return -1;
}
String host = address.getHost();
#ifdef YARP_HAS_ACE
ACE_SOCK_Connector connector;
if (address.getHost() == "localhost") {
// ACE does not like localhost. At all.
NameConfig config;
host = config.getHostName(true);
}
ACE_INET_Addr addr(address.getPort(),host.c_str());
ACE_Time_Value openTimeout;
ACE_Time_Value *timeout = NULL;
if (address.hasTimeout()) {
openTimeout.set(address.getTimeout());
timeout = &openTimeout;
}
int result = connector.connect(stream,addr,timeout,ACE_Addr::sap_any,1);
#else
TcpConnector connector;
int result = connector.connect(stream, address);
#endif
if (result>=0) {
happy = true;
} else {
YARP_SPRINTF2(Logger::get(),
debug,
"TCP connection to tcp://%s:%d failed to open",
host.c_str(),
address.getPort());
}
updateAddresses();
return result;
}
示例9: make_handler
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;
}
示例10: do_connect_svr
int 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;
}
示例11: 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;
}
示例12: main
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();
}
示例13: sv_addr
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;
}
示例14: 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. */
int
Client::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;
}
示例15: remote_addr
int
ACE::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;
}