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;
19 parse_args (int argc
, ACE_TCHAR
*argv
[])
21 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:h:c:"));
24 while ((c
= get_opts ()) != -1)
28 remote_port
= static_cast<unsigned>(ACE_OS::atoi (get_opts
.opt_arg()));
31 remote_host
= get_opts
.opt_arg ();
34 config_file
= get_opts
.opt_arg ();
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 ")
47 // Indicates successful parsing of the command line
52 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
54 ACE_OS::socket_init (ACE_WSOCK_VERSION
);
56 if (parse_args(argc
, argv
) != 0)
59 ACE_ERROR_RETURN ((LM_ERROR
,
60 ACE_TEXT ("Client: No remote host specified\n")),1);
62 ACE::HTBP::Environment env
;
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)
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
,
88 ACE::HTBP::Session::next_session_id(),
91 ACE::HTBP::Stream
*stream
= new ACE::HTBP::Stream(&session
);
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
);
98 for (size_t i
= 0; i
< Loops
; ++i
)
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"),
109 if (n
== -1 && errno
!= 0)
111 ACE_ERROR_RETURN ((LM_ERROR
,
112 ACE_TEXT("(%P|%t) Client: ")
114 ACE_TEXT("stream send"), ACE_ERRNO_GET
),
117 ACE_DEBUG ((LM_DEBUG
,
118 ACE_TEXT("(%P|%t) Client: ")
119 ACE_TEXT("In round %d, send returned %d\n"),
124 n
= stream
->recv (buffer
,1000);
127 if (errno
== EWOULDBLOCK
)
128 n
= stream
->recv (buffer
,1000);
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 ACE_TEXT("(%P|%t) Client: ")
133 ACE_TEXT("stream.recv")),
137 ACE_DEBUG ((LM_DEBUG
,
138 ACE_TEXT("(%P|%t) Client: ")
139 ACE_TEXT("received %d, %s\n"),