本文整理汇总了C++中ACE_SOCK_Stream::get_handle方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Stream::get_handle方法的具体用法?C++ ACE_SOCK_Stream::get_handle怎么用?C++ ACE_SOCK_Stream::get_handle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Stream
的用法示例。
在下文中一共展示了ACE_SOCK_Stream::get_handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: while
int
ACE_SOCK_Acceptor::accept (ACE_SOCK_Stream &new_stream,
ACE_Addr *remote_addr,
ACE_Time_Value *timeout,
int restart,
int reset_new_handle) const
{
ACE_TRACE ("ACE_SOCK_Acceptor::accept");
int in_blocking_mode = 0;
if (this->shared_accept_start (timeout,
restart,
in_blocking_mode) == -1)
return -1;
else
{
// On Win32 the third parameter to <accept> must be a NULL
// pointer if we want to ignore the client's address.
int *len_ptr = 0;
sockaddr *addr = 0;
int len = 0;
if (remote_addr != 0)
{
len = remote_addr->get_size ();
len_ptr = &len;
addr = (sockaddr *) remote_addr->get_addr ();
}
do
new_stream.set_handle (ACE_OS::accept (this->get_handle (),
addr,
len_ptr));
while (new_stream.get_handle () == ACE_INVALID_HANDLE
&& restart != 0
&& errno == EINTR
&& timeout == 0);
// Reset the size of the addr, so the proper UNIX/IPv4/IPv6 family
// is known.
if (new_stream.get_handle () != ACE_INVALID_HANDLE
&& remote_addr != 0)
{
remote_addr->set_size (len);
if (addr)
remote_addr->set_type (addr->sa_family);
}
}
return this->shared_accept_finish (new_stream,
in_blocking_mode,
reset_new_handle);
}
示例2: time
int
ACE_SOCK_Connector::complete (ACE_SOCK_Stream &new_stream,
ACE_Addr *remote_sap,
const ACE_Time_Value *tv)
{
ACE_TRACE ("ACE_SOCK_Connector::complete");
ACE_HANDLE h = ACE::handle_timed_complete (new_stream.get_handle (),
tv);
// We failed to get connected.
if (h == ACE_INVALID_HANDLE)
{
#if defined (ACE_WIN32)
// Win32 has a timing problem - if you check to see if the
// connection has completed too fast, it will fail - so wait
// <ACE_NON_BLOCKING_BUG_DELAY> microseconds to let it catch up
// then retry to see if it's a real failure.
ACE_Time_Value time (0, ACE_NON_BLOCKING_BUG_DELAY);
ACE_OS::sleep (time);
h = ACE::handle_timed_complete (new_stream.get_handle (),
tv);
if (h == ACE_INVALID_HANDLE)
{
#endif /* ACE_WIN32 */
// Save/restore errno.
ACE_Errno_Guard error (errno);
new_stream.close ();
return -1;
#if defined (ACE_WIN32)
}
#endif /* ACE_WIN32 */
}
if (remote_sap != 0)
{
int len = remote_sap->get_size ();
sockaddr *addr = reinterpret_cast<sockaddr *> (remote_sap->get_addr ());
if (ACE_OS::getpeername (h,
addr,
&len) == -1)
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
new_stream.close ();
return -1;
}
}
// Start out with non-blocking disabled on the <new_stream>.
new_stream.disable (ACE_NONBLOCK);
return 0;
}
示例3: if
/*
fence: 1) send the heartbeat message to repo at regular basis. 1/1 minute, get back the messages,
calculate the digest, and send to localhost:9907
2)listens on localhost:9901, for the incoming raw inputs, calculate the digest, and send it to hub:10007
*/
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
ACE_SOCK_Acceptor _9901acceptor;
ACE_INET_Addr _9901addr(9901);
//create the acceptor
if(_9901acceptor.open(_9901addr,1)==-1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n","open"),1);
}else if(_9901acceptor.get_local_addr(_9901addr)== -1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n","get_local_addr"),1);
}
ACE_DEBUG((LM_INFO,
"(%P|%t) starting server at port %d\n",
_9901addr.get_port_number()));
// ACE_INET_Addr repo_addr(repo_port,repo_host.c_str());
ACE_SOCK_Connector con;
// ACE_SOCK_Stream cli_stream ;
ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
// if(con.connect(cli_stream,repo_addr)==-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",repo_addr.get_host_name(),repo_addr.get_port_number()));
// }
/*connector side; do in a seperate thread;
*/
if(mgr->spawn(fetch_step2,
0,
THR_DETACHED) == -1){
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
/*
run the accept loop ;
*/
do{
ACE_SOCK_Stream stream;
if(_9901acceptor.accept(stream)== -1){
ACE_ERROR_RETURN((LM_ERROR,
"(%P|%t:%l) %p\n","accept failed"),0);
}else{
ACE_DEBUG((LM_DEBUG,
"(%P|%t:%l) connected to %s at port %d\n",_9901addr.get_host_name(),_9901addr.get_port_number()));
}
if(mgr->spawn(accept_step1,
reinterpret_cast<void *> (stream.get_handle()),
THR_DETACHED) == -1){
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"spawn"));
}
}while(true);
return 0;
}
示例4: error
int
ACE_SOCK_Acceptor::shared_accept_finish (ACE_SOCK_Stream new_stream,
int in_blocking_mode,
int reset_new_handle) const
{
ACE_TRACE ("ACE_SOCK_Acceptor::shared_accept_finish ()");
ACE_HANDLE new_handle = new_stream.get_handle ();
// Check to see if we were originally in blocking mode, and if so,
// set the <new_stream>'s handle and <this> handle to be in blocking
// mode.
if (in_blocking_mode)
{
// Save/restore errno.
ACE_Errno_Guard error (errno);
// Only disable ACE_NONBLOCK if we weren't in non-blocking mode
// originally.
ACE::clr_flags (this->get_handle (),
ACE_NONBLOCK);
ACE::clr_flags (new_handle,
ACE_NONBLOCK);
}
#if defined (ACE_HAS_WINSOCK2) && (ACE_HAS_WINSOCK2 != 0)
if (reset_new_handle)
// Reset the event association inherited by the new handle.
::WSAEventSelect ((SOCKET) new_handle, 0, 0);
#else
ACE_UNUSED_ARG (reset_new_handle);
#endif /* ACE_WIN32 */
return new_handle == ACE_INVALID_HANDLE ? -1 : 0;
}
示例5: if
int
ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
const ACE_Addr &remote_sap,
const ACE_Time_Value *timeout,
const ACE_Addr &local_sap,
int reuse_addr,
int /* flags */,
int /* perms */,
int protocol)
{
ACE_TRACE ("ACE_SOCK_Connector::connect");
if (this->shared_open (new_stream,
remote_sap.get_type (),
protocol,
reuse_addr) == -1)
return -1;
else if (this->shared_connect_start (new_stream,
timeout,
local_sap) == -1)
return -1;
int result = ACE_OS::connect (new_stream.get_handle (),
reinterpret_cast<sockaddr *> (remote_sap.get_addr ()),
remote_sap.get_size ());
return this->shared_connect_finish (new_stream,
timeout,
result);
}
示例6: addr
int
ACE_TMAIN(int argc, ACE_TCHAR* argv[]){
ACE_SOCK_Acceptor acceptor;
ACE_INET_Addr addr(10009);
if(acceptor.open(addr,1)){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n", "open"),1);
}
else if(acceptor.get_local_addr(addr) == -1){
ACE_ERROR_RETURN((LM_ERROR,
"%p\n", "get_local_addr"),1);
}
ACE_DEBUG((LM_INFO,
"(%P|%t) starting server at port %d\n",addr.get_port_number()));
ACE_Thread_Manager* mgr = ACE_Thread_Manager::instance();
while(true){
ACE_SOCK_Stream stream;
if(acceptor.accept(stream) == -1){
ACE_ERROR((LM_ERROR,
"%p\n","accept"));
continue;
}else{
ACE_DEBUG((LM_DEBUG,
"(%P|%t) spawning one thread\n"));
handle_input(mgr, commu, stream.get_handle());
}
}
return 0;
}
示例7: error
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 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;
}
示例8:
int
Synch_Thread_Pool_Task::svc (void)
{
// Creates a factory of HTTP_Handlers binding to synchronous I/O strategy
Synch_HTTP_Handler_Factory factory;
for (;;)
{
ACE_SOCK_Stream stream;
// Lock in this accept. When it returns, we have a connection.
if (this->acceptor_.accept (stream) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::accept"), -1);
ACE_Message_Block *mb;
ACE_NEW_RETURN (mb,
ACE_Message_Block (HTTP_Handler::MAX_REQUEST_SIZE + 1),
-1);
// Create an HTTP Handler to handle this request
HTTP_Handler *handler = factory.create_http_handler ();
handler->open (stream.get_handle (), *mb);
// Handler is destroyed when the I/O puts the Handler into the
// done state.
mb->release ();
ACE_DEBUG ((LM_DEBUG,
" (%t) in Synch_Thread_Pool_Task::svc, recycling\n"));
}
ACE_NOTREACHED(return 0);
}
示例9: if
int
ACE_SOCK_Connector::connect (ACE_SOCK_Stream &new_stream,
const ACE_Addr &remote_sap,
ACE_QoS_Params qos_params,
const ACE_Time_Value *timeout,
const ACE_Addr &local_sap,
ACE_Protocol_Info * protocolinfo,
ACE_SOCK_GROUP g,
u_long flags,
int reuse_addr,
int /* perms */)
{
ACE_TRACE ("ACE_SOCK_Connector::connect");
if (this->shared_open (new_stream,
remote_sap.get_type (),
0,
protocolinfo,
g,
flags,
reuse_addr) == -1)
return -1;
else if (this->shared_connect_start (new_stream,
timeout,
local_sap) == -1)
return -1;
int result = ACE_OS::connect (new_stream.get_handle (),
reinterpret_cast<sockaddr *> (remote_sap.get_addr ()),
remote_sap.get_size (),
qos_params);
return this->shared_connect_finish (new_stream, timeout, result);
}
示例10: 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;
}
示例11: wait_time
int
HTTP_Server::thread_per_request (HTTP_Handler_Factory &factory)
{
int grp_id = -1;
// thread per request
// Main thread opens the acceptor
if (this->acceptor_.open (ACE_INET_Addr (this->port_), 1,
PF_INET, this->backlog_) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("HTTP_Acceptor::open")), -1);
ACE_SOCK_Stream stream;
// When we are throttling, this is the amount of time to wait before
// checking for runnability again.
const ACE_Time_Value wait_time (0, 10);
for (;;)
{
if (this->acceptor_.accept (stream) == -1)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("HTTP_Acceptor::accept")), -1);
Thread_Per_Request_Task *t;
// Pass grp_id as a constructor param instead of into open.
ACE_NEW_RETURN (t, Thread_Per_Request_Task (stream.get_handle (),
this->tm_,
grp_id,
factory),
-1);
if (t->open () != 0)
ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("%p\n"),
ACE_TEXT ("Thread_Per_Request_Task::open")),
-1);
// Throttling is not allowing too many threads to run away.
// Should really use some sort of condition variable here.
if (!this->throttle_)
continue;
// This works because each task has only one thread.
while (this->tm_.num_tasks_in_group (grp_id) > this->threads_)
this->tm_.wait (&wait_time);
}
ACE_NOTREACHED(return 0);
}
示例12: 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;
}
示例13: 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;
}
示例14:
int
ACE_SOCK_Connector::shared_open (ACE_SOCK_Stream &new_stream,
int protocol_family,
int protocol,
int reuse_addr)
{
ACE_TRACE ("ACE_SOCK_Connector::shared_open");
// Only open a new socket if we don't already have a valid handle.
if (new_stream.get_handle () == ACE_INVALID_HANDLE
&& new_stream.open (SOCK_STREAM,
protocol_family,
protocol,
reuse_addr) == -1)
return -1;
else
return 0;
}
示例15: addr
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;
}