1 // This example tests the features of the <ACE_MEM_Acceptor>,
2 // <ACE_MEM_Stream>, and <ACE_Svc_Handler> classes. If the platform
3 // supports threads it uses a thread-per-connection concurrency model.
4 // Otherwise, it uses a single-threaded iterative server model.
6 #include "ace/MEM_Acceptor.h"
7 #include "ace/Thread_Manager.h"
8 #include "ace/Handle_Set.h"
9 #include "ace/Profile_Timer.h"
13 run_event_loop (u_short port
)
15 // Create the acceptors.
16 ACE_MEM_Acceptor acceptor
;
18 ACE_MEM_Addr
server_addr (port
);
20 // Create acceptors, reuse the address.
21 if (acceptor
.open (server_addr
, 1) == -1)
22 ACE_ERROR_RETURN ((LM_ERROR
,
26 else if (acceptor
.get_local_addr (server_addr
) == -1)
27 ACE_ERROR_RETURN ((LM_ERROR
,
33 "(%P|%t) starting server at port %d\n",
34 server_addr
.get_port_number ()));
36 // Keep these objects out here to prevent excessive constructor
37 // calls within the loop.
38 ACE_MEM_Stream new_stream
;
40 // blocking wait on accept.
41 if (acceptor
.accept (new_stream
) == -1)
42 ACE_ERROR_RETURN ((LM_ERROR
,
49 while ((len
= new_stream
.recv (buf
, MAXPATHLEN
)) != -1)
51 ACE_DEBUG ((LM_DEBUG
, "%s\n", buf
));
52 new_stream
.send (buf
, len
);
55 return new_stream
.fini ();
59 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
61 u_short port
= ACE_DEFAULT_SERVER_PORT
;
64 port
= ACE_OS::atoi (argv
[1]);
66 return run_event_loop (port
);