Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / SOCK_SAP / CPP-memserver.cpp
blob77916986d5d1cb95aa0a8644e82a2fbfb1bcfd25
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"
12 static int
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,
23 "%p\n",
24 "open"),
25 1);
26 else if (acceptor.get_local_addr (server_addr) == -1)
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "%p\n",
29 "get_local_addr"),
30 1);
32 ACE_DEBUG ((LM_DEBUG,
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,
43 "%p\n",
44 "accept"),
45 -1);
47 char buf[MAXPATHLEN];
48 int len = 0;
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 ();
58 int
59 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
61 u_short port = ACE_DEFAULT_SERVER_PORT;
63 if (argc > 1)
64 port = ACE_OS::atoi (argv[1]);
66 return run_event_loop (port);