Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / TLI_SAP / CPP-ATM-client.cpp
blob618133a284cd03d7739e70dcf5aa5150285be42c
1 #include "ace/TLI_Connector.h"
2 #include "ace/ATM_QoS.h"
3 #include "ace/ATM_Addr.h"
4 #include "ace/Log_Msg.h"
7 #if defined (ACE_HAS_FORE_ATM_XTI)
9 /* ACE_XTI/ATM Client */
11 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
13 if (argc < 2)
14 ACE_ERROR_RETURN ((LM_ERROR,
15 "Usage: %s [-s selector] hostname [QoS in KB/sec]\n",
16 argv[0]),
17 1);
19 unsigned char selector = ACE_ATM_Addr::DEFAULT_SELECTOR;
20 int selector_specified = 0;
21 extern int optind;
22 int opt;
23 while ((opt = ACE_OS::getopt (argc, argv, "s:?h")) != EOF)
25 switch(opt)
27 case 's':
28 selector = ACE_OS::atoi (optarg);
29 selector_specified = 1;
30 break;
31 case '?':
32 case 'h':
33 ACE_ERROR_RETURN ((LM_ERROR,
34 "Usage: %s hostname [-s selector] [QoS in KB/s]\n",
35 argv[0]),
36 1);
37 } // switch
38 } // while getopt
40 const char *host = argv[optind];
42 int rate = (argc == 3) ? ACE_OS::atoi (argv[2]) :
43 (argc == 5) ? ACE_OS::atoi (argv[4]) : 0;
44 // The timeout really gets ignored since FORE's drivers don't work when
45 // ioctl or fcntl calls are made on the transport id/file descriptor
46 int timeout = ACE_DEFAULT_TIMEOUT;
48 char buf[BUFSIZ];
50 ACE_TLI_Stream cli_stream;
52 ACE_ATM_Addr remote_addr (host);
53 if (selector_specified)
54 remote_addr.set_selector(selector);
55 char hostname[MAXNAMELEN];
56 ACE_OS::hostname(hostname, MAXNAMELEN);
57 ACE_ATM_Addr local_addr (hostname);
59 // In order to construct connections options the file handle is
60 // needed. Therefore, we need to open the TLI_Stream before we
61 // construct the options.
62 if (cli_stream.open (ACE_XTI_ATM_DEVICE, O_RDWR, 0) == -1)
63 ACE_ERROR_RETURN ((LM_ERROR,
64 "%p\n",
65 "open failed"),
66 1);
68 ACE_DEBUG ((LM_DEBUG,
69 "starting non-blocking connect\n"));
71 // Initiate timed, non-blocking connection with server.
72 ACE_TLI_Connector con;
74 // Construct QoS options - currently FORE only supports bandwidth
75 ACE_ATM_QoS qos;
76 qos.set_rate(cli_stream.get_handle (),
77 rate,
78 ACE_ATM_QoS::OPT_FLAGS_CPID);
80 struct netbuf optbuf = qos.get_qos();
81 // long optlen = 0;
82 // char *options = remote_addr.construct_options (cli_stream.get_handle (),
83 // rate,
84 // ACE_ATM_Addr::OPT_FLAGS_CPID,
85 // &optlen);
86 // struct netbuf optbuf;
87 // optbuf.len = optlen;
88 // optbuf.buf = options;
90 // Not sure why but reuse_addr set to true/1 causes problems for
91 // FORE/XTI/ATM - this is now handled in ACE_TLI_Connector::connect()
92 if (con.connect (cli_stream,
93 remote_addr,
94 (ACE_Time_Value *) &ACE_Time_Value::zero,
95 local_addr,
97 O_RDWR,
99 ACE_XTI_ATM_DEVICE,
103 &optbuf) == -1)
105 if (errno != EWOULDBLOCK)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "%p\n",
108 "connection failed"),
111 ACE_DEBUG ((LM_DEBUG,
112 "starting timed connect\n"));
114 // Check if non-blocking connection is in progress, and wait up
115 // to timeout seconds for it to complete.
116 ACE_Time_Value tv (timeout);
118 if (con.complete (cli_stream,
119 &remote_addr,
120 &tv) == -1)
121 ACE_ERROR_RETURN ((LM_ERROR,
122 "%p\n",
123 "connection failed"),
125 else
126 ACE_DEBUG ((LM_DEBUG,
127 "connected to %s\n",
128 remote_addr.addr_to_string ()));
131 // Send data to server (correctly handles "incomplete writes").
133 for (int r_bytes;
134 (r_bytes = ACE_OS::read (ACE_STDIN, buf, sizeof buf)) > 0;
136 if (cli_stream.send_n (buf,
137 r_bytes,
138 0) == -1)
139 ACE_ERROR_RETURN ((LM_ERROR,
140 "%p\n",
141 "send_n"),
144 // Explicitly close the connection.
145 if (cli_stream.close () == -1)
146 ACE_ERROR_RETURN ((LM_ERROR,
147 "%p\n",
148 "close"),
149 -1);
150 return 0;
152 #else
153 int ACE_TMAIN (int, ACE_TCHAR *[])
155 ACE_ERROR_RETURN ((LM_ERROR,
156 "your platform isn't configured to support XTI/ATM\n"),
159 #endif /* ACE_HAS_TLI */