2 //=============================================================================
6 * receive methods, over HTBP. The test forks two processes or spawns
7 * two threads (depending upon the platform) and then executes client
8 * and server allowing them to connect and exchange data in ways
9 * designed to exercise the send and recv functions.
11 * Right now, it primarily tests the iov-like send and recv
12 * functions, but others should be added to completely cover the
15 * @author Steve Huston <shuston@riverace.com>
17 //=============================================================================
20 #include "ace/HTBP/HTBP_Stream.h"
21 #include "ace/HTBP/HTBP_Session.h"
22 #include "ace/HTBP/HTBP_ID_Requestor.h"
23 #include "ace/HTBP/HTBP_Environment.h"
25 #include "ace/Thread.h"
26 #include "ace/Thread_Manager.h"
27 #include "ace/SOCK_Connector.h"
28 #include "ace/SOCK_Acceptor.h"
29 #include "ace/SOCK_Stream.h"
30 #include "ace/Get_Opt.h"
31 #include "ace/OS_NS_sys_socket.h"
33 // Change to non-zero if test fails
34 static int Test_Result
= 0;
36 const size_t Test3_Send_Size
= 4*1024;
37 const size_t Test3_Loops
= 10;
38 const size_t Test3_Total_Size
= Test3_Send_Size
* Test3_Loops
;
40 const ACE_TCHAR
* remote_host
= 0;
41 const ACE_TCHAR
* config_file
= 0;
42 unsigned remote_port
= 8088;
45 parse_args (int argc
, ACE_TCHAR
*argv
[])
47 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("p:h:c:"));
50 while ((c
= get_opts ()) != -1)
54 remote_port
= static_cast<unsigned>(ACE_OS::atoi (get_opts
.opt_arg()));
57 remote_host
= get_opts
.opt_arg ();
60 config_file
= get_opts
.opt_arg ();
64 ACE_ERROR_RETURN ((LM_ERROR
,
65 ACE_TEXT ("usage: %s ")
66 ACE_TEXT ("-h remote_host ")
67 ACE_TEXT ("-p remote_port ")
68 ACE_TEXT ("-c config_file ")
73 // Indicates successful parsing of the command line
78 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
80 ACE_OS::socket_init (ACE_WSOCK_VERSION
);
82 if (parse_args(argc
, argv
) != 0)
85 ACE_ERROR_RETURN ((LM_ERROR
,
86 ACE_TEXT ("Client: No remote host specified\n")),1);
88 ACE::HTBP::Environment env
;
90 env
.import_config (config_file
);
92 ACE::HTBP::ID_Requestor
req (&env
);
93 ACE::HTBP::Addr
local(ACE_TEXT_ALWAYS_CHAR(req
.get_HTID()));
95 unsigned proxy_port
= 0;
96 ACE_TString proxy_host
;
98 if (env
.get_proxy_port(proxy_port
) != 0 ||
99 env
.get_proxy_host(proxy_host
) != 0)
101 ACE_DEBUG ((LM_DEBUG
,
102 ACE_TEXT("(%P|%t) Client: ")
103 ACE_TEXT("no proxy address in ")
104 ACE_TEXT("config, using direct connect\n")));
105 proxy_port
= remote_port
;
106 proxy_host
= remote_host
;
109 ACE_INET_Addr
proxy(proxy_port
,proxy_host
.c_str());
110 ACE::HTBP::Addr
remote (remote_port
,
111 ACE_TEXT_ALWAYS_CHAR(remote_host
));
113 ACE::HTBP::Session
session(remote
,
115 ACE::HTBP::Session::next_session_id(),
118 ACE::HTBP::Stream
stream(&session
);
120 ACE_DEBUG ((LM_DEBUG
,
121 ACE_TEXT ("(%P|%t) Connecting to port %d\n"),
122 remote
.get_port_number()));
124 ACE_DEBUG ((LM_DEBUG
,
125 ACE_TEXT ("(%P|%t) connected to %C\n"),
126 remote
.get_host_name ()));
128 ACE_DEBUG ((LM_DEBUG
, "(%P) ***** client TEST 1 *****\n"));
130 //******************* TEST 1 ******************************
132 // Do a iovec sendv - send the 255 byte buffer in 5 chunks. The
133 // server will verify that the correct data is sent, and that there
134 // is no more and no less.
140 // The server will verify that this data pattern gets there intact.
142 for (i
= 0; i
< sizeof buffer
; ++i
)
143 buffer
[i
] = static_cast<u_char
> (i
);
147 iov
[0].iov_base
= reinterpret_cast<char *> (&buffer
[0]);
150 iov
[1].iov_base
= reinterpret_cast<char *> (&buffer
[50]);
153 iov
[2].iov_base
= reinterpret_cast<char *> (&buffer
[75]);
154 iov
[2].iov_len
= 150;
156 iov
[3].iov_base
= reinterpret_cast<char *> (&buffer
[225]);
159 iov
[4].iov_base
= reinterpret_cast<char *> (&buffer
[254]);
162 len
= stream
.sendv (iov
, 5);
163 ACE_DEBUG ((LM_DEBUG
,"(%P) after send, len = %d\n"));
166 ACE_ERROR ((LM_ERROR
,
167 ACE_TEXT ("(%P|%t) %p\n"),
168 ACE_TEXT ("Test 1, sendv failed")));
174 ACE_ERROR ((LM_ERROR
,
175 ACE_TEXT ("(%P|%t) %p\n"),
176 ACE_TEXT ("Test 1, len = %d != 255\n"), len
));
180 // ACE_OS::sleep (10);
181 ACE_DEBUG ((LM_DEBUG
, "(%P) ***** client TEST 2 *****\n"));
183 //******************* TEST 2 ******************************
185 // The same data is coming back - receive it using recv (size_t n,
186 // ...) and compare it to the original data.
192 len
= stream
.recv (buffer2
+total
, 145 - total
);
193 ACE_DEBUG ((LM_DEBUG
,
194 ACE_TEXT("(%P) Test 2: want %d bytes, got %d\n"),
196 if (len
== -1 || errno
== EWOULDBLOCK
)
200 } while ((len
== -1 && errno
== EWOULDBLOCK
) || total
< 145);
205 len
= stream
.recv (buffer2
+ total
, 110);
206 ACE_DEBUG ((LM_DEBUG
,
207 ACE_TEXT("(%P) Test 2: second read want 110 bytes, got %d\n"),
213 for (i
= 0; Test_Result
== 0 && i
< 255; i
++)
214 if (buffer2
[i
] != buffer
[i
])
216 ACE_ERROR ((LM_ERROR
,
217 ACE_TEXT ("(%P|%t) Test 2, rcvd byte %d is %d, not %d\n"),
218 i
, buffer2
[i
], buffer
[i
]));