本文整理汇总了C++中ACE_SOCK_Acceptor::close方法的典型用法代码示例。如果您正苦于以下问题:C++ ACE_SOCK_Acceptor::close方法的具体用法?C++ ACE_SOCK_Acceptor::close怎么用?C++ ACE_SOCK_Acceptor::close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ACE_SOCK_Acceptor
的用法示例。
在下文中一共展示了ACE_SOCK_Acceptor::close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: local_any
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
//.........这里部分代码省略.........
示例4: buffer
void
TestDriver::run_i()
{
ACE_Message_Block buffer (1000000);
ACE_SOCK_Acceptor acceptor;
if (acceptor.open(sub_addr_) == -1) {
ACE_ERROR((LM_ERROR,
"%p\n",
"open"));
throw TestException();
}
ACE_SOCK_Stream peer;
if (acceptor.accept(peer) == -1) {
ACE_ERROR((LM_ERROR,
"%p\n",
"accept"));
throw TestException();
}
#if defined (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
# if !defined (ACE_LACKS_SOCKET_BUFSIZ)
// set connection options
int snd_size = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
int rcv_size = ACE_DEFAULT_MAX_SOCKET_BUFSIZ;
int nodelay =1;
if (peer.set_option (IPPROTO_TCP, TCP_NODELAY, &nodelay, sizeof (nodelay)) == -1) {
ACE_ERROR((LM_ERROR, "(%P|%t) Subscriber failed to set TCP_NODELAY\n"));
}
if (peer.set_option (SOL_SOCKET, SO_SNDBUF, (void *) &snd_size, sizeof (snd_size)) == -1
&& errno != ENOTSUP)
{
ACE_ERROR((LM_ERROR,
"(%P|%t) TcpSubscriber failed to set the send buffer size to %d errno %m\n",
snd_size));
}
if (peer.set_option (SOL_SOCKET, SO_RCVBUF, (void *) &rcv_size, sizeof (int)) == -1
&& errno != ENOTSUP)
{
ACE_ERROR((LM_ERROR,
"(%P|%t) TcpSubscriber failed to set the receive buffer size to %d errno %m \n",
rcv_size));
}
# endif /* !ACE_LACKS_SOCKET_BUFSIZ */
#endif /* !ACE_DEFAULT_MAX_SOCKET_BUFSIZ */
ACE_DEBUG((LM_DEBUG, "(%T) Subscriber running.\n"));
unsigned total_packets = num_packets_ + 500;
int result;
for (unsigned pkt_cnt = 0; pkt_cnt < total_packets; ++pkt_cnt)
{
if ((result = peer.recv(buffer.wr_ptr(), num_bytes_per_packet_)) == 0) {
// The publisher has disconnected - check if this was unexpected.
ACE_ERROR((LM_ERROR,
"(%P|%t) Publisher disconnected at packet %d.\n",
pkt_cnt));
throw TestException();
}
else if (result < 0) {
// Something bad happened
ACE_ERROR((LM_ERROR, "(%P|%t) bad read\n"));
throw TestException();
}
else if ((unsigned) result != num_bytes_per_packet_) {
// Something bad happened
ACE_ERROR((LM_ERROR,
"(%P|%t) read %d bytes but expected %d\n",
result, num_bytes_per_packet_));
throw TestException();
}
// only send 4 back
result = 4;
peer.send_n(buffer.wr_ptr(), result);
}
// Close the acceptor so that no more clients will be taken in.
acceptor.close();
if (verbose_) {
ACE_DEBUG((LM_DEBUG, "(%P|%t) Subscriber has completed.\n"));
}
}