1 #include "ace/os_include/os_netdb.h"
2 #include "ace/OS_NS_errno.h"
3 #include "ace/INET_Addr.h"
4 #include "ace/SOCK_Stream.h"
5 #include "ace/SOCK_Acceptor.h"
6 #include "ace/Log_Msg.h"
7 #include "ace/Time_Value.h"
9 int ACE_TMAIN (int, ACE_TCHAR
*[])
11 // Listing 1 code/ch06
12 ACE_INET_Addr
port_to_listen ("HAStatus");
13 ACE_SOCK_Acceptor acceptor
;
15 if (acceptor
.open (port_to_listen
, 1) == -1)
16 ACE_ERROR_RETURN ((LM_ERROR
,
18 ACE_TEXT ("acceptor.open")),
22 //FUZZ: disable check_for_lack_ACE_OS
24 * The complete open signature:
26 // Listing 2 code/ch06
27 int open (const ACE_Addr &local_sap,
29 int protocol_family = PF_INET,
30 int backlog = ACE_DEFAULT_BACKLOG,
35 //FUZZ: enable check_for_lack_ACE_OS
40 ACE_INET_Addr peer_addr
;
41 ACE_Time_Value
timeout (10, 0);
44 * Basic acceptor usage
47 // Listing 3 code/ch06
48 if (acceptor
.accept (peer
) == -1)
49 ACE_ERROR_RETURN ((LM_ERROR
,
50 ACE_TEXT ("(%P|%t) Failed to accept ")
51 ACE_TEXT ("client connection\n")),
56 // Listing 4 code/ch06
57 if (acceptor
.accept (peer
, &peer_addr
, &timeout
, 0) == -1)
59 if (ACE_OS::last_error() == EINTR
)
61 ACE_TEXT ("(%P|%t) Interrupted while ")
62 ACE_TEXT ("waiting for connection\n")));
64 if (ACE_OS::last_error() == ETIMEDOUT
)
66 ACE_TEXT ("(%P|%t) Timeout while ")
67 ACE_TEXT ("waiting for connection\n")));
70 // Listing 5 code/ch06
73 ACE_TCHAR peer_name
[MAXHOSTNAMELEN
];
74 peer_addr
.addr_to_string (peer_name
, MAXHOSTNAMELEN
);
76 ACE_TEXT ("(%P|%t) Connection from %s\n"),
79 // Listing 7 code/ch06
81 ssize_t bytes_received
;
83 while ((bytes_received
=
84 peer
.recv (buffer
, sizeof(buffer
))) != -1)
86 peer
.send_n (buffer
, bytes_received
);
94 ACE_NOTREACHED (return 0);