本文整理汇总了C++中ACE_SOCK_Stream::close方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Stream::close方法的具体用法?C++ ACE_SOCK_Stream::close怎么用?C++ ACE_SOCK_Stream::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Stream
的用法示例。
在下文中一共展示了ACE_SOCK_Stream::close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: factory_addr
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;
}
示例2: 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 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;
}
示例3: main
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;
}
示例4: unmarshalledOctetServer
// 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;
}
示例5: while
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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: handle_connection
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;
}
示例10: 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();
}
示例11: 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;
}
示例12: another_host
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;
}
示例13: 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;
}
示例14: main
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;
}
示例15: htonl
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;
}