Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / protocols / tests / HTBP / Send_Large_Msg / client.cpp
blobcfe26926333e5dff6e853e9cf08399d86ed24d84
1 #include "ace/HTBP/HTBP_Session.h"
2 #include "ace/HTBP/HTBP_Stream.h"
3 #include "ace/HTBP/HTBP_Addr.h"
4 #include "ace/HTBP/HTBP_ID_Requestor.h"
5 #include "ace/HTBP/HTBP_Environment.h"
7 #include "ace/Log_Msg.h"
8 #include "ace/Get_Opt.h"
9 #include "ace/OS_NS_sys_socket.h"
11 const ssize_t Send_Size = 4*1024;
12 const size_t Loops = 10;
13 const size_t Total_Size = Send_Size * Loops;
14 const ACE_TCHAR * remote_host = 0;
15 const ACE_TCHAR * config_file = 0;
16 unsigned remote_port = 8088;
18 int
19 parse_args (int argc, ACE_TCHAR *argv[])
21 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("p:h:c:"));
22 int c;
24 while ((c = get_opts ()) != -1)
25 switch (c)
27 case 'p':
28 remote_port = static_cast<unsigned>(ACE_OS::atoi (get_opts.opt_arg()));
29 break;
30 case 'h':
31 remote_host = get_opts.opt_arg ();
32 break;
33 case 'c':
34 config_file = get_opts.opt_arg ();
35 break;
36 case '?':
37 default:
38 ACE_ERROR_RETURN ((LM_ERROR,
39 ACE_TEXT ("usage: %s ")
40 ACE_TEXT ("-h remote_host ")
41 ACE_TEXT ("-p remote_port ")
42 ACE_TEXT ("-c config_file ")
43 ACE_TEXT ("\n"),
44 argv [0]),
45 -1);
47 // Indicates successful parsing of the command line
48 return 0;
51 int
52 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
54 ACE_OS::socket_init (ACE_WSOCK_VERSION);
56 if (parse_args(argc, argv) != 0)
57 return 1;
58 if (remote_host == 0)
59 ACE_ERROR_RETURN ((LM_ERROR,
60 ACE_TEXT ("Client: No remote host specified\n")),1);
62 ACE::HTBP::Environment env;
63 if (config_file != 0)
64 env.import_config (config_file);
66 ACE::HTBP::ID_Requestor req (&env);
67 ACE::HTBP::Addr local(ACE_TEXT_ALWAYS_CHAR(req.get_HTID()));
69 unsigned proxy_port = 0;
70 ACE_TString proxy_host;
72 if (env.get_proxy_port(proxy_port) != 0 ||
73 env.get_proxy_host(proxy_host) != 0)
75 ACE_DEBUG ((LM_DEBUG,
76 ACE_TEXT("(%P|%t) Client: ")
77 ACE_TEXT("no proxy address in ")
78 ACE_TEXT("config, using direct connect\n")));
79 proxy_port = remote_port;
80 proxy_host = remote_host;
83 ACE_INET_Addr proxy(proxy_port,proxy_host.c_str());
84 ACE::HTBP::Addr remote (remote_port,ACE_TEXT_ALWAYS_CHAR(remote_host));
86 ACE::HTBP::Session session(remote,
87 local,
88 ACE::HTBP::Session::next_session_id(),
89 &proxy);
91 ACE::HTBP::Stream *stream = new ACE::HTBP::Stream(&session);
92 ACE_DEBUG ((LM_DEBUG,
93 ACE_TEXT("(%P|%t) Client: ")
94 ACE_TEXT("Sending message\n")));
95 char buffer[Send_Size];
96 ACE_OS::memset (buffer,'a',Send_Size);
97 ssize_t n = 0;
98 for (size_t i = 0; i < Loops ; ++i)
100 errno = 0;
101 while (n < Send_Size)
103 n += stream->send (buffer+n,Send_Size);
104 ACE_DEBUG ((LM_DEBUG,
105 ACE_TEXT("(%P|%t) Client: ")
106 ACE_TEXT("Sending %d of %d\n"),
107 n, Send_Size));
109 if (n == -1 && errno != 0)
111 ACE_ERROR_RETURN ((LM_ERROR,
112 ACE_TEXT("(%P|%t) Client: ")
113 ACE_TEXT("%p\n %d"),
114 ACE_TEXT("stream send"), ACE_ERRNO_GET),
115 -1);
117 ACE_DEBUG ((LM_DEBUG,
118 ACE_TEXT("(%P|%t) Client: ")
119 ACE_TEXT("In round %d, send returned %d\n"),
120 i, n));
123 buffer[0] = 0;
124 n = stream->recv (buffer,1000);
125 while (n == -1)
127 if (errno == EWOULDBLOCK)
128 n = stream->recv (buffer,1000);
129 else
130 ACE_ERROR_RETURN ((LM_ERROR,
131 ACE_TEXT("(%P|%t) Client: ")
132 ACE_TEXT("%p\n"),
133 ACE_TEXT("stream.recv")),
134 -1);
137 ACE_DEBUG ((LM_DEBUG,
138 ACE_TEXT("(%P|%t) Client: ")
139 ACE_TEXT("received %d, %s\n"),
140 n,buffer));
141 return 0;