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
[])
14 ACE_ERROR_RETURN ((LM_ERROR
,
15 "Usage: %s [-s selector] hostname [QoS in KB/sec]\n",
19 unsigned char selector
= ACE_ATM_Addr::DEFAULT_SELECTOR
;
20 int selector_specified
= 0;
23 while ((opt
= ACE_OS::getopt (argc
, argv
, "s:?h")) != EOF
)
28 selector
= ACE_OS::atoi (optarg
);
29 selector_specified
= 1;
33 ACE_ERROR_RETURN ((LM_ERROR
,
34 "Usage: %s hostname [-s selector] [QoS in KB/s]\n",
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
;
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
,
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
76 qos
.set_rate(cli_stream
.get_handle (),
78 ACE_ATM_QoS::OPT_FLAGS_CPID
);
80 struct netbuf optbuf
= qos
.get_qos();
82 // char *options = remote_addr.construct_options (cli_stream.get_handle (),
84 // ACE_ATM_Addr::OPT_FLAGS_CPID,
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
,
94 (ACE_Time_Value
*) &ACE_Time_Value::zero
,
105 if (errno
!= EWOULDBLOCK
)
106 ACE_ERROR_RETURN ((LM_ERROR
,
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
,
121 ACE_ERROR_RETURN ((LM_ERROR
,
123 "connection failed"),
126 ACE_DEBUG ((LM_DEBUG
,
128 remote_addr
.addr_to_string ()));
131 // Send data to server (correctly handles "incomplete writes").
134 (r_bytes
= ACE_OS::read (ACE_STDIN
, buf
, sizeof buf
)) > 0;
136 if (cli_stream
.send_n (buf
,
139 ACE_ERROR_RETURN ((LM_ERROR
,
144 // Explicitly close the connection.
145 if (cli_stream
.close () == -1)
146 ACE_ERROR_RETURN ((LM_ERROR
,
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 */