Changes to attempt to silence bcc64x
[ACE_TAO.git] / ACE / examples / IPC_SAP / TLI_SAP / db-client.cpp
blobe3b59feaa4289d040e8c5b7fe33863f11c29d220
1 #include "ace/TLI_Connector.h"
2 #include "ace/Log_Msg.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "ace/OS_NS_stdlib.h"
5 #include "ace/OS_NS_string.h"
7 #if defined (ACE_HAS_TLI)
8 const int MAXLINE = 255;
10 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
12 if (argc < 2)
13 ACE_ERROR_RETURN ((LM_ERROR,
14 ACE_TEXT ("Usage: %s employee_id [server-host port-number]\n"),
15 argv[0]),
16 -1);
18 const ACE_TCHAR *emp_num = argv[1];
19 const ACE_TCHAR *host_name = argc < 3 ? ACE_DEFAULT_SERVER_HOST : argv[2];
20 unsigned short port = argc < 4 ? ACE_DEFAULT_SERVER_PORT : ACE_OS::atoi (argv[3]);
21 int n;
22 char buf[MAXLINE];
24 ACE_TLI_Stream client;
25 ACE_TLI_Connector con;
27 if (con.connect (client, ACE_INET_Addr (port, host_name)) == -1)
28 ACE_OS::t_error ((char *) host_name), ACE_OS::exit (1);
30 ACE_OS::strcpy (buf, ACE_TEXT_ALWAYS_CHAR (emp_num));
31 n = ACE_OS::strlen (buf);
33 if (client.send_n (buf, n) != n)
34 ACE_OS::t_error ("client.send error");
36 if (client.recv (buf, MAXLINE) == -1 && t_errno != TLOOK && client.look () != T_DISCONNECT)
37 ACE_OS::t_error ("client.recv error");
39 if (ACE_OS::strcmp (buf, "ERROR") == 0)
40 ACE_OS::printf ("Employee ID %s not in database\n", emp_num);
41 else
42 ACE_OS::printf ("Employee name requested is: %s\n", buf);
44 if (client.close () == -1)
45 ACE_OS::t_error ("cli_close"), ACE_OS::exit (1);
47 return 0;
49 #else
50 int ACE_TMAIN (int, ACE_TCHAR *[])
52 ACE_ERROR_RETURN ((LM_ERROR,
53 "your platform isn't configured to support TLI\n"),
54 1);
56 #endif /* ACE_HAS_TLI */