Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / TLI_SAP / CPP-ATM-server.cpp
blobb35ba5910ee6507d7f1c1229979820ffa7e0c519
1 #include "ace/TLI_Acceptor.h"
2 #include "ace/ATM_Addr.h"
3 #include "ace/Log_Msg.h"
6 #if defined (ACE_HAS_FORE_ATM_XTI)
7 // ACE_TLI Server
9 int
10 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
12 ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);
14 unsigned char selector = ACE_ATM_Addr::DEFAULT_SELECTOR;
15 int selector_specified = 0;
16 int opt;
17 while ((opt = ACE_OS::getopt (argc, argv, "s:?h")) != EOF)
19 switch(opt)
21 case 's':
22 selector = ACE_OS::atoi (optarg);
23 selector_specified = 1;
24 break;
25 case '?':
26 case 'h':
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "Usage: %s [-s selector]\n", argv[0]),
29 1);
30 } // switch
31 } // while getopt
33 // Create a server address.
34 ACE_ATM_Addr addr;
35 if (selector_specified)
36 addr.set_selector(selector);
38 // Create a server, reuse the addr.
39 ACE_TLI_Acceptor peer_acceptor;
41 // Not sure why but reuse_addr set to true/1 causes problems for
42 // FORE/XTI/ATM - this is now handled in ACE_TLI_Acceptor::open()
43 if (peer_acceptor.open (addr,
45 O_RDWR,
48 ACE_XTI_ATM_DEVICE) == -1)
49 ACE_ERROR_RETURN ((LM_ERROR,
50 "%p\n",
51 "open"),
52 -1);
54 ACE_TLI_Stream new_stream;
56 ACE_DEBUG ((LM_DEBUG,
57 "starting server at address %s\n",
58 addr.addr_to_string ()));
61 // Performs the iterative server activities
63 for (;;)
65 char buf[BUFSIZ];
67 // Create a new ACE_TLI_Stream endpoint (note automatic restart
68 // if errno == EINTR).
69 if (peer_acceptor.accept (new_stream,
70 &addr,
71 &timeout) == -1)
73 ACE_ERROR ((LM_ERROR,
74 "%p\n",
75 "accept"));
76 continue;
79 ACE_DEBUG ((LM_DEBUG,
80 "client %s connected\n",
81 addr.addr_to_string ()));
83 // Read data from client (terminate on error).
85 for (int r_bytes;
86 (r_bytes = new_stream.recv (buf, sizeof buf, 0)) > 0; )
87 if (ACE_OS::write (ACE_STDOUT,
88 buf,
89 r_bytes) != r_bytes)
90 ACE_ERROR ((LM_ERROR,
91 "%p\n",
92 "ACE::send_n"));
94 // Close new endpoint (listening endpoint stays open).
95 if (new_stream.close () == -1)
96 ACE_ERROR ((LM_ERROR,
97 "%p\n",
98 "close"));
100 /* NOTREACHED */
101 return 0;
103 #else
104 int ACE_TMAIN (int, ACE_TCHAR *[])
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "your platform isn't configured to support XTI/ATM\n"),
110 #endif /* ACE_HAS_TLI */