From 3c924c23fd65f5934b8ce2240aca679cb45dbbf4 Mon Sep 17 00:00:00 2001 From: Phil Mesnier Date: Tue, 14 Aug 2007 21:49:55 +0000 Subject: Tue Aug 14 19:11:06 UTC 2007 Phil Mesnier --- ACE/ChangeLog | 45 ++- ACE/protocols/ace/HTBP/HTBP_Channel.cpp | 75 ++-- ACE/protocols/ace/HTBP/HTBP_Environment.cpp | 8 +- ACE/protocols/ace/HTBP/HTBP_ID_Requestor.cpp | 10 +- .../ace/HTBP/HTBP_Inside_Squid_Filter.cpp | 23 +- ACE/protocols/ace/HTBP/HTBP_Notifier.cpp | 10 +- .../ace/HTBP/HTBP_Outside_Squid_Filter.cpp | 26 +- ACE/protocols/ace/HTBP/HTBP_Session.cpp | 4 +- ACE/protocols/ace/HTBP/HTBP_Stream.cpp | 75 ++-- ACE/protocols/tests/HTBP/Reactor_Tests/client.cpp | 81 ++++- ACE/protocols/tests/HTBP/Reactor_Tests/run_test.pl | 11 +- ACE/protocols/tests/HTBP/Reactor_Tests/server.cpp | 67 +++- ACE/protocols/tests/HTBP/Send_Large_Msg/client.cpp | 92 +++-- .../tests/HTBP/Send_Large_Msg/run_test.pl | 13 +- ACE/protocols/tests/HTBP/Send_Large_Msg/server.cpp | 70 +++- .../tests/HTBP/Send_Recv_Tests/SendRecv_Test.cpp | 388 --------------------- .../tests/HTBP/Send_Recv_Tests/SendRecv_Test.mpc | 16 +- .../tests/HTBP/Send_Recv_Tests/client.cpp | 224 ++++++++++++ .../tests/HTBP/Send_Recv_Tests/run_test.pl | 46 +++ .../tests/HTBP/Send_Recv_Tests/server.cpp | 237 +++++++++++++ ACE/protocols/tests/HTBP/ping/client.cpp | 106 ++++-- ACE/protocols/tests/HTBP/ping/run_test.pl | 12 +- ACE/protocols/tests/HTBP/ping/server.cpp | 54 ++- 23 files changed, 1116 insertions(+), 577 deletions(-) delete mode 100644 ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.cpp create mode 100644 ACE/protocols/tests/HTBP/Send_Recv_Tests/client.cpp create mode 100755 ACE/protocols/tests/HTBP/Send_Recv_Tests/run_test.pl create mode 100644 ACE/protocols/tests/HTBP/Send_Recv_Tests/server.cpp diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 3d5acc192de..6b5425ce5f9 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,11 +1,52 @@ +Tue Aug 14 19:11:06 UTC 2007 Phil Mesnier + + * protocols/ace/HTBP/HTBP_Channel.cpp: + * protocols/ace/HTBP/HTBP_Environment.cpp: + * protocols/ace/HTBP/HTBP_ID_Requestor.cpp: + * protocols/ace/HTBP/HTBP_Inside_Squid_Filter.cpp: + * protocols/ace/HTBP/HTBP_Notifier.cpp: + * protocols/ace/HTBP/HTBP_Outside_Squid_Filter.cpp: + * protocols/ace/HTBP/HTBP_Stream.cpp: + + Clean up the debug output. + + * protocols/tests/HTBP/Reactor_Tests/client.cpp: + * protocols/tests/HTBP/Reactor_Tests/run_test.pl: + * protocols/tests/HTBP/Reactor_Tests/server.cpp: + + * protocols/tests/HTBP/Send_Large_Msg/client.cpp: + * protocols/tests/HTBP/Send_Large_Msg/run_test.pl: + * protocols/tests/HTBP/Send_Large_Msg/server.cpp: + + * protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.cpp: + * protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.mpc: + * protocols/tests/HTBP/Send_Recv_Tests/server.cpp: + * protocols/tests/HTBP/Send_Recv_Tests/client.cpp: + * protocols/tests/HTBP/Send_Recv_Tests/run_test.pl: + + * protocols/tests/HTBP/ping/client.cpp: + * protocols/tests/HTBP/ping/run_test.pl: + * protocols/tests/HTBP/ping/server.cpp: + + Fix up the tests to run cleanly in a nightly build environment + This is primarily fixing the configuration so that it does not + depend on an external proxy, but will use one if locally + configured to do so. Also fixed up the test output and command + line processing to make it more consistent with other tests. + + I've not turned on the automatic running of these tests just + yet, I'd rather wait and just make sure the build is clean. We + can turn on the automatic run at some point later now that the + tests are cleaned up. + Tue Aug 14 18:44:12 UTC 2007 Johnny Willemsen * include/makeinclude/platform_linux.GNU: * include/makeinclude/platform_linux_icc.GNU: * include/makeinclude/platform_linux_pgi.GNU: * include/makeinclude/platform_linux_suncc.GNU: - Added a check whether we run on a kernel with NPTL. If this is the case - we add ACE_HAS_LINUX_NPTL to the compiler flags + Added a check whether we run on a kernel with NPTL. If this is + the case we add ACE_HAS_LINUX_NPTL to the compiler flags Tue Aug 14 18:06:16 UTC 2007 Abdullah Sowayan diff --git a/ACE/protocols/ace/HTBP/HTBP_Channel.cpp b/ACE/protocols/ace/HTBP/HTBP_Channel.cpp index 064312377ba..483f107ab6c 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Channel.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Channel.cpp @@ -31,7 +31,7 @@ ACE::HTBP::Channel::Channel (ACE::HTBP::Session *s) session_ (s), ace_stream_ (), notifier_ (0), - leftovers_ (1000), + leftovers_ (1001), data_len_ (0), data_consumed_ (0), state_ (Init), @@ -48,7 +48,7 @@ ACE::HTBP::Channel::Channel (ACE_SOCK_Stream &s) session_ (0), ace_stream_ (s.get_handle()), notifier_ (0), - leftovers_ (1000), + leftovers_ (1001), data_len_ (0), data_consumed_ (0), state_ (Init), @@ -64,7 +64,7 @@ ACE::HTBP::Channel::Channel (ACE_HANDLE h) session_ (0), ace_stream_ (h), notifier_ (0), - leftovers_ (1000), + leftovers_ (1001), data_len_ (0), data_consumed_ (0), state_ (Init), @@ -77,8 +77,8 @@ ACE::HTBP::Channel::Channel (ACE_HANDLE h) /// Destructor. ACE::HTBP::Channel::~Channel (void) { - delete this->filter_; delete this->notifier_; + delete this->filter_; } /// Dump the state of an object. @@ -163,7 +163,7 @@ ACE::HTBP::Channel::load_buffer (void) } if (nread != -1) nread = this->ace_stream().recv (this->leftovers_.wr_ptr(), - this->leftovers_.space()); + this->leftovers_.space()-1); if (nread < 1) { if (nread == 0 || (errno != EWOULDBLOCK && errno != EAGAIN)) @@ -179,11 +179,6 @@ ACE::HTBP::Channel::load_buffer (void) } this->leftovers_.wr_ptr(nread); *this->leftovers_.wr_ptr() = '\0'; -#if 0 - ACE_DEBUG ((LM_DEBUG,"load_buffer[%d] received %d \n", - this->ace_stream_.get_handle(),leftovers_.length())); - ACE_HEX_DUMP ((LM_DEBUG,leftovers_.rd_ptr(),leftovers_.length())); -#endif return nread; } @@ -255,8 +250,11 @@ ACE::HTBP::Channel::consume_error (void) if (this->data_consumed_ == this->data_len_) { *this->error_buffer_->wr_ptr() = '\0'; - ACE_DEBUG ((LM_DEBUG,"Received entire error buffer: \n%s\n", - this->error_buffer_->rd_ptr())); + if (ACE::debug()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE::HTBP::Channel::consume_error ") + ACE_TEXT("Received entire error buffer: \n%s\n"), + this->error_buffer_->rd_ptr())); delete error_buffer_; error_buffer_ = 0; @@ -277,6 +275,10 @@ ACE::HTBP::Channel::consume_error (void) int ACE::HTBP::Channel::pre_recv(void) { + if (ACE::debug()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE::HTBP::Channel::pre_recv ") + ACE_TEXT ("in initial state = %d\n"),state_)); if (this->state_ == Init || this->state_ == Detached || this->state_ == Header_Pending || @@ -286,11 +288,18 @@ ACE::HTBP::Channel::pre_recv(void) { if (errno != EWOULDBLOCK) this->state_ = Closed; - ACE_DEBUG ((LM_DEBUG,"pre_recv returning -1, state = %d\n",state_)); + if (ACE::debug()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE::HTBP::Channel::pre_recv ") + ACE_TEXT ("pre_recv returning -1, state = %d, %p\n"), + state_, ACE_TEXT("load_buffer()"))); return -1; } if (this->filter_->recv_data_header(this) == -1) - ACE_DEBUG ((LM_DEBUG,"recv_data_header failed, %p\n","pre_recv")); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("ACE::HTBP::Channel::pre_recv ") + ACE_TEXT ("recv_data_header failed, %p\n"), + ACE_TEXT("pre_recv"))); } switch (this->state_) { @@ -302,9 +311,13 @@ ACE::HTBP::Channel::pre_recv(void) errno = EWOULDBLOCK; return -1; default: - ACE_DEBUG ((LM_DEBUG,"channel[%d] state = %d, %p\n", - this->get_handle(), - this->state_,"pre_recv")); + if (ACE::debug()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE::HTBP::Channel::pre_recv ") + ACE_TEXT("channel[%d] state = %d, %p\n"), + this->get_handle(), + this->state_, + ACE_TEXT("pre_recv"))); } return -1; } @@ -419,9 +432,11 @@ ACE::HTBP::Channel::recvv (iovec *io_vec, ssize_t result = 0; if (this->pre_recv() == -1) return -1; - - ACE_DEBUG ((LM_DEBUG,"recvv, leftover len = %d\n", - this->leftovers_.length())); + if (ACE::debug()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE::HTBP::Channel::recvv ") + ACE_TEXT("recvv, leftover len = %d\n"), + this->leftovers_.length())); if (this->leftovers_.length()) { io_vec->iov_base = 0; @@ -467,7 +482,9 @@ ACE::HTBP::Channel::send (const void *buf, { ssize_t result = 0; if (this->filter_ == 0) - ACE_ERROR_RETURN ((LM_DEBUG, "ACE::HTBP::Channel::send: filter is null\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) ACE::HTBP::Channel::send: filter ") + ACE_TEXT ("is null\n")),-1); if (this->filter_->send_data_header(n,this) == -1) return -1; result = this->ace_stream_.send (buf,n,timeout); @@ -491,16 +508,24 @@ ACE::HTBP::Channel::sendv (const iovec iov[], for (int i = 0; i < iovcnt; n += iov[i++].iov_len); if (this->filter_->send_data_header(n,this) == -1) - ACE_ERROR_RETURN ((LM_ERROR,"sendv, %p\n","send_data_header"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) ACE::HTBP::Channel::sendv ") + ACE_TEXT("%p\n"), + ACE_TEXT("send_data_header")),-1); result = this->ace_stream_.sendv (iov,iovcnt,timeout); if (result == -1) - ACE_ERROR_RETURN ((LM_ERROR,"sendv, %p\n","ace_stream_.sendv"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) ACE::HTBP::Channel::sendv ") + ACE_TEXT("%p\n"), + ACE_TEXT("ace_stream_.sendv")),-1); if (this->filter_->send_data_trailer(this) == -1) - ACE_ERROR_RETURN ((LM_ERROR,"sendv, %p\n","send_data_trailer\n"),-1); - + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) ACE::HTBP::Channel::sendv ") + ACE_TEXT("%p\n"), + ACE_TEXT("send_data_trailer\n")),-1); return result; } diff --git a/ACE/protocols/ace/HTBP/HTBP_Environment.cpp b/ACE/protocols/ace/HTBP/HTBP_Environment.cpp index 1270b681e0e..939c5225fe6 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Environment.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Environment.cpp @@ -52,7 +52,8 @@ ACE::HTBP::Environment::initialize (int use_registry, if (result != 0) { ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("ACE::HTBP::Environment::initialize (): ") + ACE_TEXT("(%P|%t) ACE::HTBP::Environment") + ACE_TEXT("::initialize ") ACE_TEXT("Open Config failed")), -1); } @@ -67,7 +68,7 @@ ACE::HTBP::Environment::initialize (int use_registry, ACE_TEXT("htbp"), 1, this->htbp_key_) != 0) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("ACE::HTBP::Environment::initialize (). ") + ACE_TEXT("(%P|%t) ACE::HTBP::Environment::initialize ") ACE_TEXT("Open HTBP Section failed")), -1); return 0; @@ -105,7 +106,8 @@ ACE::HTBP::Environment::open_persistent_config (const ACE_TCHAR *persistent_file else if (heap->open (persistent_file) != 0) ACE_ERROR_RETURN (( LM_ERROR, - ACE_TEXT ("ACE::HTBP::Environment::open_config: %p\n"), + ACE_TEXT ("(%P|%t) ACE::HTBP::Environment::") + ACE_TEXT ("open_config: %p\n"), persistent_file), -1 ); return 0; diff --git a/ACE/protocols/ace/HTBP/HTBP_ID_Requestor.cpp b/ACE/protocols/ace/HTBP/HTBP_ID_Requestor.cpp index 26fc7fef48b..0f400522143 100644 --- a/ACE/protocols/ace/HTBP/HTBP_ID_Requestor.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_ID_Requestor.cpp @@ -43,7 +43,7 @@ ACE::HTBP::ID_Requestor::connect_to_server (ACE_SOCK_Stream *cli_stream) int sep = 0; if (host_start == -1) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("ACE::HTBP::ID_Requestor::") + ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") ACE_TEXT("connect_to_server: ") ACE_TEXT("invalid URL: \"%s\"\n"), url_.c_str()), @@ -52,7 +52,7 @@ ACE::HTBP::ID_Requestor::connect_to_server (ACE_SOCK_Stream *cli_stream) sep = url_.find (ACE_TEXT("/"),(size_t)host_start); if (sep == -1 || sep == host_start +1) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("ACE::HTBP::ID_Requestor::") + ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") ACE_TEXT("connect_to_server: ") ACE_TEXT("invalid URL: \"%s\"\n"), url_.c_str()), @@ -70,7 +70,8 @@ ACE::HTBP::ID_Requestor::connect_to_server (ACE_SOCK_Stream *cli_stream) if (con.connect (*cli_stream, remote_addr) == -1) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("ACE::HTBP::ID_Requestor::connect_to_server: ") + ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") + ACE_TEXT("connect_to_server: ") ACE_TEXT("%p\n"), ACE_TEXT("socket connect")), -1); @@ -88,7 +89,8 @@ ACE::HTBP::ID_Requestor::send_request (ACE_SOCK_Stream *cli_stream) delete [] buffer; if (result == -1) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("ACE::HTBP::ID_Requestor::send_request %p\n"), + ACE_TEXT("(%P|%t) ACE::HTBP::ID_Requestor::") + ACE_TEXT("send_request %p\n"), ACE_TEXT("socket send")), -1); return 0; } diff --git a/ACE/protocols/ace/HTBP/HTBP_Inside_Squid_Filter.cpp b/ACE/protocols/ace/HTBP/HTBP_Inside_Squid_Filter.cpp index 7433ac34d7c..1bc9f4a208b 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Inside_Squid_Filter.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Inside_Squid_Filter.cpp @@ -50,7 +50,7 @@ ACE::HTBP::Inside_Squid_Filter::make_request_header (ACE::HTBP::Channel *ch, tempId = ch->request_count(); while (tempId /= 10) rid_size++; - // This test was originally get_host_name() == -1, but this is + // This test was originally get_host_name() == -1, but this is // problematic if the address doesn't resolve to a name. I think // that it should be configurable, or maybe the hostname needs to // be carried independent of the address to work with hosts that may @@ -116,10 +116,11 @@ ACE::HTBP::Inside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) { if (this->http_code() != 200 && this->http_code() != 0) { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("Inside_Squid_Filter::recv_data_header, ") - ACE_TEXT("non-OK result code %d recvd\n"), - this->http_code())); + if (ACE::debug()) + ACE_ERROR ((LM_ERROR, + ACE_TEXT("HTBP::Inside_Squid_Filter::recv_data_header, ") + ACE_TEXT("non-OK result code %d recvd\n"), + this->http_code())); errno = ch->consume_error () ? EINVAL : EWOULDBLOCK; return 0; @@ -133,7 +134,8 @@ ACE::HTBP::Inside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) errno = EWOULDBLOCK; } ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("Inside_Squid_Filter::recv_data_header, ") + ACE_TEXT("HTBP::Inside_Squid_Filter::") + ACE_TEXT("recv_data_header, ") ACE_TEXT("header not complete\n")), 0); } @@ -152,8 +154,8 @@ ACE::HTBP::Inside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) ch->leftovers().rd_ptr(header_end); if (this->http_code() != 200) { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("Inside_Squid_Filter::recv_data_header, ") + ACE_ERROR ((LM_ERROR, + ACE_TEXT("HTBP::Inside_Squid_Filter::recv_data_header, ") ACE_TEXT("non-OK result code %d recvd\n"), this->http_code())); @@ -180,7 +182,7 @@ ACE::HTBP::Inside_Squid_Filter::send_ack (ACE::HTBP::Channel *ch) if (ch->state() == ACE::HTBP::Channel::Ack_Sent) { ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("Inside Filter::send_ack: ") + ACE_TEXT("HTBP::Inside Filter::send_ack: ") ACE_TEXT("state is already ACK_SENT\n")), 1); } @@ -206,7 +208,8 @@ ACE::HTBP::Inside_Squid_Filter::recv_ack (ACE::HTBP::Channel *ch) if (ch->state() != ACE::HTBP::Channel::Closed) errno = EWOULDBLOCK; ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("Inside_Squid_Filter::recv_data_header, ") + ACE_TEXT("HTBP::Inside_Squid_Filter::") + ACE_TEXT("recv_data_header, ") ACE_TEXT("header not complete\n")),0); } if (this->http_code() == 200) diff --git a/ACE/protocols/ace/HTBP/HTBP_Notifier.cpp b/ACE/protocols/ace/HTBP/HTBP_Notifier.cpp index 70a6df54023..1e02fbee29c 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Notifier.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Notifier.cpp @@ -51,13 +51,19 @@ ACE::HTBP::Notifier::handle_input(ACE_HANDLE ) this->reactor()->notify(h, ACE_Event_Handler::READ_MASK); else - ACE_DEBUG ((LM_DEBUG,"Notifier cannot notify, session has no handler (%x), or reactor (%x)\n",h,this->reactor())); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) ACE::HTBP::Notifier::handle_input ") + ACE_TEXT ("Notifier cannot notify, session has no ") + ACE_TEXT ("handler (%x), or reactor (%x)\n"), + h,this->reactor())); } else this->channel_->flush_buffer(); } else - ACE_DEBUG ((LM_DEBUG,"Notifier has no session to notify!\n")); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) ACE::HTBP::Notifier::handle_input ") + ACE_TEXT ("Notifier has no session to notify!\n"))); return 0; } diff --git a/ACE/protocols/ace/HTBP/HTBP_Outside_Squid_Filter.cpp b/ACE/protocols/ace/HTBP/HTBP_Outside_Squid_Filter.cpp index 76cf7b7af4f..5e626170457 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Outside_Squid_Filter.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Outside_Squid_Filter.cpp @@ -56,8 +56,9 @@ ACE::HTBP::Outside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) ch->leftovers().length(0); errno = EINVAL; ACE_ERROR_RETURN ((LM_ERROR, - "ACE::HTBP::Outside_Squid_Filter::recv_data_header " - "bad request header\n"),0); + ACE_TEXT("ACE::HTBP::Outside_Squid_Filter::") + ACE_TEXT("recv_data_header ") + ACE_TEXT("bad request header\n")),0); } } start += token.length(); @@ -73,8 +74,9 @@ ACE::HTBP::Outside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) ch->leftovers().length(0); errno = EINVAL; ACE_ERROR_RETURN ((LM_ERROR, - "ACE::HTBP::Outside_Squid_Filter::recv_data_header " - "missing sender key\n"),0); + ACE_TEXT("ACE::HTBP::Outside_Squid_Filter::") + ACE_TEXT("recv_data_header ") + ACE_TEXT("missing sender key\n")),0); } *slash = 0; session_id.local_.string_to_addr (start); @@ -86,8 +88,9 @@ ACE::HTBP::Outside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) ch->leftovers().length(0); errno = EINVAL; ACE_ERROR_RETURN ((LM_ERROR, - "ACE::HTBP::Outside_Squid_Filter::recv_data_header " - "missing sender key\n"),0); + ACE_TEXT("ACE::HTBP::Outside_Squid_Filter::") + ACE_TEXT("recv_data_header ") + ACE_TEXT("missing sender key\n")),0); } *slash = 0; session_id.peer_.string_to_addr (start); @@ -99,8 +102,9 @@ ACE::HTBP::Outside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) ch->leftovers().length (0); errno = EINVAL; ACE_ERROR_RETURN ((LM_ERROR, - "ACE::HTBP::Outside_Squid_Filter::recv_data_header " - "missing sender key"),0); + ACE_TEXT("ACE::HTBP::Outside_Squid_Filter::") + ACE_TEXT("recv_data_header ") + ACE_TEXT("missing sender key")),0); } *slash = 0; session_id.id_ = ACE_OS::strtol(start,0,10); @@ -127,9 +131,9 @@ ACE::HTBP::Outside_Squid_Filter::recv_data_header (ACE::HTBP::Channel *ch) ACE_NEW_RETURN (session, ACE::HTBP::Session (session_id), 0); if (ACE::HTBP::Session::add_session (session) == -1) ACE_ERROR_RETURN ((LM_ERROR, - "ACE::HTBP::Outside_Squid_Filter::" - "recv_data_header %p", - "add_session"),0); + ACE_TEXT("ACE::HTBP::Outside_Squid_Filter::") + ACE_TEXT("recv_data_header %p"), + ACE_TEXT("add_session")),0); } ch->session(session); diff --git a/ACE/protocols/ace/HTBP/HTBP_Session.cpp b/ACE/protocols/ace/HTBP/HTBP_Session.cpp index f2bae3fde73..69e085636d2 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Session.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Session.cpp @@ -200,7 +200,9 @@ ACE::HTBP::Session::detach (ACE::HTBP::Channel *ch) else if (this->outbound_ == ch) this->outbound_ = 0; else - ACE_ERROR ((LM_ERROR, "ACE::HTBP::Session::detach called with unknown channel\n")); + ACE_ERROR ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Session::detach ") + ACE_TEXT("called with unknown channel\n"))); } void diff --git a/ACE/protocols/ace/HTBP/HTBP_Stream.cpp b/ACE/protocols/ace/HTBP/HTBP_Stream.cpp index c0913569af0..63e8c0df671 100644 --- a/ACE/protocols/ace/HTBP/HTBP_Stream.cpp +++ b/ACE/protocols/ace/HTBP/HTBP_Stream.cpp @@ -48,15 +48,18 @@ ACE::HTBP::Stream::dump (void) const /// Recv an byte buffer from the connected socket. ssize_t ACE::HTBP::Stream::recv (void *buf, - size_t n, - int flags, - const ACE_Time_Value *timeout) const + size_t n, + int flags, + const ACE_Time_Value *timeout) const { if (this->session_->inbound() == 0) { errno = EWOULDBLOCK; - ACE_ERROR_RETURN ((LM_ERROR,"recv(buf,n,flags) called, but no " - "inbound channel connected to stream\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream::") + ACE_TEXT("recv(buf,n,flags) called, but no ") + ACE_TEXT("inbound channel connected to stream\n")), + -1); } return this->session_->inbound()->recv(buf,n,flags,timeout); } @@ -64,14 +67,17 @@ ACE::HTBP::Stream::recv (void *buf, /// Recv an byte buffer from the connected socket. ssize_t ACE::HTBP::Stream::recv (void *buf, - size_t n, - const ACE_Time_Value *timeout) const + size_t n, + const ACE_Time_Value *timeout) const { if (this->session_->inbound() == 0) { errno = EWOULDBLOCK; - ACE_ERROR_RETURN ((LM_ERROR,"recv(buf,n) called, but no " - "inbound channel connected to stream\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream::") + ACE_TEXT("recv(buf,n) called, but no ") + ACE_TEXT("inbound channel connected to stream\n")), + -1); } return this->session_->inbound()->recv(buf,n,timeout); } @@ -85,8 +91,11 @@ ACE::HTBP::Stream::recvv (iovec iov[], if (this->session_->inbound() == 0) { errno = EWOULDBLOCK; - ACE_ERROR_RETURN ((LM_ERROR,"recv(iov,iovcnt) called, but no " - "inbound channel connected to stream\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream::") + ACE_TEXT("recv(iov,iovcnt) called, but no ") + ACE_TEXT("inbound channel connected to stream\n")), + -1); } return this->session_->inbound()->recvv(iov,iovcnt,timeout); } @@ -98,8 +107,11 @@ ACE::HTBP::Stream::recvv (iovec *io_vec, if (this->session_->inbound() == 0) { errno = EWOULDBLOCK; - ACE_ERROR_RETURN ((LM_ERROR,"recv(io_vec) called, but no " - "inbound channel connected to stream\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream::") + ACE_TEXT("recv(io_vec) called, but no ") + ACE_TEXT("inbound channel connected to stream\n")), + -1); } return this->session_->inbound()->recvv(io_vec,timeout); } @@ -110,7 +122,9 @@ ACE::HTBP::Stream::recv (void *, ACE_OVERLAPPED *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: Asynch recv not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: Asynch ") + ACE_TEXT("recv not supported\n")),-1); } ssize_t @@ -173,7 +187,10 @@ ACE::HTBP::Stream::send (const void *, ACE_OVERLAPPED *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: Asynch send not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: Asynch ") + ACE_TEXT("send not supported\n")), + -1); } ssize_t @@ -184,7 +201,9 @@ ACE::HTBP::Stream::recv_n (void *, size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: recv_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: recv_n not supported\n")), + -1); } /// Try to recv exactly bytes into from the connected socket. @@ -195,7 +214,9 @@ ACE::HTBP::Stream::recv_n (void *, size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: recv_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: recv_n not supported\n")), + -1); } /// Receive an of size from the connected socket. @@ -206,7 +227,9 @@ ACE::HTBP::Stream::recvv_n (iovec [], size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: recvv_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: recvv_n not supported\n")), + -1); } /// Try to send exactly bytes from to the connection socket. @@ -218,7 +241,9 @@ ACE::HTBP::Stream::send_n (const void *, size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: send_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")), + -1); } /// Try to send exactly bytes from to the connected socket. @@ -229,7 +254,9 @@ ACE::HTBP::Stream::send_n (const void *, size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: send_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")), + -1); } /// Send all the s chained through their and @@ -241,7 +268,9 @@ ACE::HTBP::Stream::send_n (const ACE_Message_Block *, size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: send_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: send_n not supported\n")), + -1); } /// Send an of size to the connected socket. @@ -252,7 +281,9 @@ ACE::HTBP::Stream::sendv_n (const iovec [], size_t *) const { errno = ENOTSUP; - ACE_ERROR_RETURN ((LM_ERROR, "ACE::HTBP::Stream: sendv_n not supported\n"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("ACE::HTBP::Stream: sendv_n not supported\n")), + -1); } int diff --git a/ACE/protocols/tests/HTBP/Reactor_Tests/client.cpp b/ACE/protocols/tests/HTBP/Reactor_Tests/client.cpp index 2813d9116f3..1f5cd6feda6 100644 --- a/ACE/protocols/tests/HTBP/Reactor_Tests/client.cpp +++ b/ACE/protocols/tests/HTBP/Reactor_Tests/client.cpp @@ -5,6 +5,7 @@ */ #include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" #include "ace/HTBP/HTBP_Session.h" #include "ace/HTBP/HTBP_Stream.h" @@ -12,27 +13,60 @@ #include "ace/HTBP/HTBP_ID_Requestor.h" #include "ace/HTBP/HTBP_Environment.h" +const ACE_TCHAR * remote_host = 0; +const ACE_TCHAR * config_file = 0; +unsigned remote_port = 8088; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "p:h:c:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + remote_port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + case 'h': + remote_host = get_opts.opt_arg (); + break; + case 'c': + config_file = get_opts.opt_arg (); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("usage: %s ") + ACE_TEXT ("-h remote_host ") + ACE_TEXT ("-p remote_port ") + ACE_TEXT ("-c config_file ") + ACE_TEXT ("\n"), + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { ACE_OS::socket_init (ACE_WSOCK_VERSION); - if (argc < 2) + if (parse_args(argc, argv) != 0) + return 1; + if (remote_host == 0) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT("Usage: client \n")), - 0); + ACE_TEXT ("Client: No remote host specified\n")),1); - ACE::HTBP::Environment env (0,0,ACE_TEXT("inside.env")); -#if 0 // this should be a taken from a command line argument. - env.import_config ("inside.conf"); -#endif /* 0 */ + ACE::HTBP::Environment env; + if (config_file != 0) + env.import_config (config_file); ACE::HTBP::ID_Requestor req (&env); - ACE::HTBP::Addr local = ACE_TEXT_ALWAYS_CHAR(req.get_HTID()); - - unsigned remote_port = 8088; - const ACE_TCHAR * remote_host = argv[1]; + ACE::HTBP::Addr local(ACE_TEXT_ALWAYS_CHAR(req.get_HTID())); unsigned proxy_port = 0; ACE_TString proxy_host; @@ -41,6 +75,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) env.get_proxy_host(proxy_host) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("no proxy address in ") ACE_TEXT("config, using direct connect\n"))); proxy_port = remote_port; @@ -65,7 +100,9 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"), ACE_TEXT("stream send")),-1); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT("send returned %d\n"),n)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT("send returned %d\n"),n)); retrycount = 10; while ((n = ch->recv_ack()) == -1 @@ -74,11 +111,13 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { retrycount--; ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("waiting for ack, %d tries left\n"), retrycount)); ACE_OS::sleep (1); } ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("After wait for ack, n = %d, retry = %d\n"), n,retrycount,errno)); @@ -89,6 +128,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { retrycount--; ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("waiting for inbound data, %d tries left\n"), retrycount)); ACE_OS::sleep(1); @@ -96,6 +136,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) if (retrycount == 0 || n < 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("bailing after wait, %p\n"), ACE_TEXT("recv"))); break; @@ -103,18 +144,26 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) buffer[n] = 0; - ACE_DEBUG ((LM_DEBUG,"Got: \"%s\"\n",buffer)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT("Got: \"%s\"\n"), + buffer)); } ACE::HTBP::Channel *ch = session.outbound(); if (ch == 0) ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("session's outbound channel is null!\n")),1); n = stream.send ("goodbye",7); if (n == -1) - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"), + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT("%p\n"), ACE_TEXT("stream send")),-1); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT("send returned %d\n"),n)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT("send returned %d\n"),n)); retrycount = 10; while (ch && @@ -124,11 +173,13 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { retrycount--; ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("waiting for ack, %d tries left\n"), retrycount)); ACE_OS::sleep (1); } ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("After wait for ack, n = %d, retry = %d\n"), n,retrycount,errno)); diff --git a/ACE/protocols/tests/HTBP/Reactor_Tests/run_test.pl b/ACE/protocols/tests/HTBP/Reactor_Tests/run_test.pl index ae4c56c7fb2..227b8e5503e 100755 --- a/ACE/protocols/tests/HTBP/Reactor_Tests/run_test.pl +++ b/ACE/protocols/tests/HTBP/Reactor_Tests/run_test.pl @@ -11,14 +11,19 @@ use Sys::Hostname; $status = 0; -$SV = new PerlACE::Process ("server"); - $host = hostname(); +if (PerlACE::is_vxworks_test()) { + $host = $ENV{'ACE_RUN_VX_TGTHOST'}; + $SV = new PerlACE::ProcessVX ("server", ""); +} +else { + $SV = new PerlACE::Process ("server", ""); +} # The client code should later be modified to get the hostname # using ACE_OS::hostname so the same script can be run on all # hosts without havng to reset the host where it has to be run. -$CL = new PerlACE::Process ("client", $host); +$CL = new PerlACE::Process ("client", "-h $host"); $SV->Spawn (); diff --git a/ACE/protocols/tests/HTBP/Reactor_Tests/server.cpp b/ACE/protocols/tests/HTBP/Reactor_Tests/server.cpp index 87a914163c2..fad3e03b36d 100644 --- a/ACE/protocols/tests/HTBP/Reactor_Tests/server.cpp +++ b/ACE/protocols/tests/HTBP/Reactor_Tests/server.cpp @@ -14,6 +14,34 @@ #include "ace/SOCK_Stream.h" #include "ace/Event_Handler.h" #include "ace/Reactor.h" +#include "ace/Get_Opt.h" + +unsigned port = 8088; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "p:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-p port " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} class Accept_Handler : public ACE_Event_Handler { @@ -80,7 +108,7 @@ Accept_Handler::handle_input (ACE_HANDLE h) } if (ch == 0) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("Accept_Handler::handle_input, ") + ACE_TEXT ("(%P|%t) Server Accept_Handler::handle_input, ") ACE_TEXT ("unknown handle %d\n") ,h), -1); int result = (*ch)->pre_recv(); @@ -99,18 +127,22 @@ Accept_Handler::handle_input (ACE_HANDLE h) if (handler == 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server Accept_Handler::handle_input ") ACE_TEXT ("Creating new stream handler for %d\n"), stream->get_handle())); Stream_Handler *sh = new Stream_Handler(*stream); session->handler (sh); } else - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("There is already a handler for %d\n"), + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server Accept_Handler::handle_input ") + ACE_TEXT ("There is already a handler for %d\n"), stream->get_handle())); if ((*ch)->state() == ACE::HTBP::Channel::Data_Queued) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server Accept_Handler::handle_input \n"), ACE_TEXT ("Issuing notification on handler\n"))); this->reactor()->notify (session->handler(), ACE_Event_Handler::READ_MASK); @@ -135,12 +167,13 @@ Stream_Handler::handle_input (ACE_HANDLE h) ssize_t n = this->stream_.recv (buffer,1000); if (n == -1) ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("Stream_Handler::handle_input %p\n"), + ACE_TEXT ("(%P|%t) Server Stream_Handler::handle_input %p\n"), ACE_TEXT ("recv")), 0); buffer[n] = 0; ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Stream_Handler::handle_input (%d) read %d:\n%C\n"), + ACE_TEXT ("(%P|%t) Server Stream_Handler::handle_input ") + ACE_TEXT (" (%d) read %d:\n%C\n"), h, n, buffer)); const char *tok_loc = ACE_OS::strstr (buffer, "goodbye"); @@ -151,10 +184,12 @@ Stream_Handler::handle_input (ACE_HANDLE h) ACE::HTBP::Channel *ch = stream_.session()->outbound(); if (ch != 0) ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server Stream_Handler::handle_input ") ACE_TEXT ("Sending reply on %d\n"), ch->ace_stream().get_handle())); else ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server Stream_Handler::handle_input ") ACE_TEXT ("Can't send reply on nul channel\n"))); this->stream_.send ("Back atcha!",11); } @@ -162,18 +197,30 @@ Stream_Handler::handle_input (ACE_HANDLE h) } int -ACE_TMAIN (int, ACE_TCHAR *[]) +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("At start of main\n"))); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") + ACE_TEXT ("At start of main\n"))); ACE_OS::socket_init (ACE_WSOCK_VERSION); - ACE_INET_Addr local(8088); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("got address\n"))); + if (parse_args(argc, argv) != 0) + return 1; + + ACE_INET_Addr local(port); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") + ACE_TEXT ("got address\n"))); + ACE_SOCK_Acceptor acc(local,1); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("opened listener\n"))); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") + ACE_TEXT ("opened listener\n"))); Accept_Handler handler (acc); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("server is ready\n"))); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") + ACE_TEXT ("server is ready\n"))); ACE_Reactor::instance()->run_reactor_event_loop(); return 0; diff --git a/ACE/protocols/tests/HTBP/Send_Large_Msg/client.cpp b/ACE/protocols/tests/HTBP/Send_Large_Msg/client.cpp index 62cd9140da8..cf97a18eb78 100644 --- a/ACE/protocols/tests/HTBP/Send_Large_Msg/client.cpp +++ b/ACE/protocols/tests/HTBP/Send_Large_Msg/client.cpp @@ -1,7 +1,5 @@ // $Id$ -#include "tests/test_config.h" - #include "ace/HTBP/HTBP_Session.h" #include "ace/HTBP/HTBP_Stream.h" #include "ace/HTBP/HTBP_Addr.h" @@ -9,34 +7,65 @@ #include "ace/HTBP/HTBP_Environment.h" #include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" const ssize_t Send_Size = 4*1024; const size_t Loops = 10; const size_t Total_Size = Send_Size * Loops; +const ACE_TCHAR * remote_host = 0; +const ACE_TCHAR * config_file = 0; +unsigned remote_port = 8088; int -ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +parse_args (int argc, char *argv[]) { - ACE_START_TEST (ACE_TEXT ("HTBP_Send_Large_Msg_client")); + ACE_Get_Opt get_opts (argc, argv, "p:h:c:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + remote_port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + case 'h': + remote_host = get_opts.opt_arg (); + break; + case 'c': + config_file = get_opts.opt_arg (); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("usage: %s ") + ACE_TEXT ("-h remote_host ") + ACE_TEXT ("-p remote_port ") + ACE_TEXT ("-c config_file ") + ACE_TEXT ("\n"), + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ ACE_OS::socket_init (ACE_WSOCK_VERSION); - if (argc < 2) + if (parse_args(argc, argv) != 0) + return 1; + if (remote_host == 0) ACE_ERROR_RETURN ((LM_ERROR, - "Usage: client \n"), - 0); - ACE::HTBP::Environment env; -#if 0 // this should be a taken from a command line argument - env.import_config (ACE_TEXT("../HTBP_Config.conf")); -#endif /* 0 */ + ACE_TEXT ("Client: No remote host specified\n")),1); + ACE::HTBP::Environment env; + if (config_file != 0) + env.import_config (config_file); ACE::HTBP::ID_Requestor req (&env); ACE::HTBP::Addr local(ACE_TEXT_ALWAYS_CHAR(req.get_HTID())); - unsigned remote_port = 8088; - const ACE_TCHAR * remote_host = argv[1]; - unsigned proxy_port = 0; ACE_TString proxy_host; @@ -44,6 +73,7 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) env.get_proxy_host(proxy_host) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Client: ") ACE_TEXT("no proxy address in ") ACE_TEXT("config, using direct connect\n"))); proxy_port = remote_port; @@ -59,7 +89,9 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) &proxy); ACE::HTBP::Stream *stream = new ACE::HTBP::Stream(&session); - ACE_DEBUG ((LM_DEBUG,ACE_TEXT("Sending message\n"))); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("Sending message\n"))); char buffer[Send_Size]; ACE_OS::memset (buffer,'a',Send_Size); ssize_t n = 0; @@ -70,14 +102,22 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { n += stream->send (buffer+n,Send_Size); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("Sending %d of %d\n"), n, Send_Size)); + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("Sending %d of %d\n"), + n, Send_Size)); } if (n == -1 && errno != 0) { - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n %d"), - ACE_TEXT("stream send"), errno), -1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("%p\n %d"), + ACE_TEXT("stream send"), errno), + -1); } - ACE_DEBUG ((LM_DEBUG, ACE_TEXT("In round %d, send returned %d\n"), i, n)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("In round %d, send returned %d\n"), + i, n)); } buffer[0] = 0; @@ -87,12 +127,16 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) if (errno == EWOULDBLOCK) n = stream->recv (buffer,1000); else - ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT("%p\n"), - ACE_TEXT("stream.recv")),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("%p\n"), + ACE_TEXT("stream.recv")), + -1); } - ACE_DEBUG ((LM_DEBUG, ACE_TEXT("received %d, %s\n"),n,buffer)); - - ACE_END_TEST; + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("received %d, %s\n"), + n,buffer)); return 0; } diff --git a/ACE/protocols/tests/HTBP/Send_Large_Msg/run_test.pl b/ACE/protocols/tests/HTBP/Send_Large_Msg/run_test.pl index 6b295afbf17..f92fe574ac3 100755 --- a/ACE/protocols/tests/HTBP/Send_Large_Msg/run_test.pl +++ b/ACE/protocols/tests/HTBP/Send_Large_Msg/run_test.pl @@ -9,18 +9,21 @@ use lib "$ENV{ACE_ROOT}/bin"; use PerlACE::Run_Test; use Sys::Hostname; -$iorfile = PerlACE::LocalFile ("server.ior"); - -unlink $iorfile; $status = 0; -$SV = new PerlACE::Process ("server"); $host = hostname(); +if (PerlACE::is_vxworks_test()) { + $host = $ENV{'ACE_RUN_VX_TGTHOST'}; + $SV = new PerlACE::ProcessVX ("server", ""); +} +else { + $SV = new PerlACE::Process ("server", ""); +} # The client code should later be modified to get the hostname # using ACE_OS::hostname so the same script can be run on all # hosts without havng to reset the host where it has to be run. -$CL = new PerlACE::Process ("client", $host); +$CL = new PerlACE::Process ("client", "-h $host"); $SV->Spawn (); diff --git a/ACE/protocols/tests/HTBP/Send_Large_Msg/server.cpp b/ACE/protocols/tests/HTBP/Send_Large_Msg/server.cpp index 7b7f51cf1b9..bd3d844c058 100644 --- a/ACE/protocols/tests/HTBP/Send_Large_Msg/server.cpp +++ b/ACE/protocols/tests/HTBP/Send_Large_Msg/server.cpp @@ -3,6 +3,7 @@ #include "tests/test_config.h" #include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" #include "ace/HTBP/HTBP_Session.h" #include "ace/HTBP/HTBP_Stream.h" @@ -14,38 +15,68 @@ const size_t Send_Size = 4*1024; const size_t Loops = 10; const size_t Total_Size = Send_Size * Loops; +unsigned port = 8088; int -ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +parse_args (int argc, char *argv[]) { + ACE_Get_Opt get_opts (argc, argv, "p:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-p port " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} - ACE_UNUSED_ARG (argc); - ACE_UNUSED_ARG (argv); - - char buffer[1000]; +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + char buffer[5000]; ACE_OS::socket_init (ACE_WSOCK_VERSION); - ACE_INET_Addr local(8088); + if (parse_args(argc, argv) != 0) + return 1; + + ACE_INET_Addr local(port); ACE_SOCK_Stream sock[2]; + ACE::HTBP::Channel *channels[2]; ACE_SOCK_Acceptor acc(local,1); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("server is ready\n"))); acc.accept(sock[0]); - ACE::HTBP::Channel channel1(sock[0]); + channels[0] = new ACE::HTBP::Channel (sock[0]); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("Got sock[0], handle = %d\n"), sock[0].get_handle())); acc.accept(sock[1]); - ACE::HTBP::Channel channel2(sock[1]); + channels[1] = new ACE::HTBP::Channel(sock[1]); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("Got sock[1], handle = %d\n"), sock[1].get_handle())); int res = 0; - while ((res =channel1.pre_recv()) != 0) + while ((res = channels[0]->pre_recv()) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("res = %d. waiting 1 sec. %p\n"), res, ACE_TEXT("stream.pre_recv()"))); @@ -53,20 +84,23 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) } ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("Read from channel2\n"))); - while ((res = channel2.pre_recv()) != 0) + while ((res = channels[1]->pre_recv()) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("res = %d, waiting 1 sec. %p\n"), res, ACE_TEXT("stream2.pre_recv()"))); ACE_OS::sleep (1); } - ACE::HTBP::Session *session = channel1.session(); + ACE::HTBP::Session *session = channels[0]->session(); ACE::HTBP::Stream stream (session); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("using streams %d, %d. Got sesssion = %x\n"), sock[0].get_handle(),sock[1].get_handle(),session)); @@ -78,7 +112,8 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) errno = 0; got = stream.recv (buffer, sizeof (buffer)); ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("got : %s %d "), buffer, got)); + ACE_TEXT("(%P|%t) Server: ") + ACE_TEXT("got = %d\n"), got)); if (got < 0) break; @@ -86,18 +121,25 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) } ACE_DEBUG ((LM_DEBUG, - ACE_TEXT("received %d, %s\n"),total_recv,buffer)); + ACE_TEXT("(%P|%t) Server: ") + ACE_TEXT("received %d \n"),total_recv)); ACE_OS::strcpy (buffer,"I hear you !"); ssize_t n = stream.send (buffer,ACE_OS::strlen(buffer)+1); if (n == -1) ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("%p\n"), ACE_TEXT("stream.send")),-1); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Server: ") ACE_TEXT("send returned %d\n"),n)); - return 0; + ACE_DEBUG ((LM_DEBUG,"deleting channels[1]\n")); + delete channels[1]; + ACE_DEBUG ((LM_DEBUG,"deleting channels[0]\n")); + delete channels[0]; + return 0; } diff --git a/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.cpp b/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.cpp deleted file mode 100644 index d462a11c3d3..00000000000 --- a/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.cpp +++ /dev/null @@ -1,388 +0,0 @@ -// $Id$ - -// =========================================================================== -// -// = LIBRARY -// tests -// -// = FILENAME -// Send_Recv_Test.cpp -// -// = DESCRIPTION This is a test of the 's various send and -// receive methods, over HTBP. The test forks two processes or spawns -// two threads (depending upon the platform) and then executes client -// and server allowing them to connect and exchange data in ways -// designed to exercise the send and recv functions. -// -// Right now, it primarily tests the iov-like send and recv -// functions, but others should be added to completely cover the -// possible scenarios. -// -// = AUTHOR -// Steve Huston -// -// ============================================================================ - -#include "tests/test_config.h" - -#include "ace/HTBP/HTBP_Stream.h" -#include "ace/HTBP/HTBP_Session.h" -#include "ace/HTBP/HTBP_ID_Requestor.h" -#include "ace/HTBP/HTBP_Environment.h" - -#include "ace/OS.h" -#include "ace/Thread.h" -#include "ace/Thread_Manager.h" -#include "ace/SOCK_Connector.h" -#include "ace/SOCK_Acceptor.h" -#include "ace/SOCK_Stream.h" - -ACE_RCSID(tests, - SOCK_Send_Recv_Test, - "$Id$") - -// Change to non-zero if test fails -static int Test_Result = 0; - -#if !defined (ACE_LACKS_FORK) || defined (ACE_HAS_THREADS) - -// In test 3, a large amount of data is sent. The purpose is to overflow the -// TCP send window, causing the sender to block (it's a send_n). This value -// is the amount to send. The assumption is that no implementation has a -// receive window larger than 128K bytes. If one is found, this is the place -// to change it. -// For some odd reason, NT will try to send a single large buffer, but not -// multiple smaller ones that add up to the large size. -const size_t Test3_Send_Size = 4*1024; -const size_t Test3_Loops = 10; -const size_t Test3_Total_Size = Test3_Send_Size * Test3_Loops; - - -static void * -client (void *arg) -{ - ACE_OS::socket_init (ACE_WSOCK_VERSION); - ACE::HTBP::Environment ht_env; - -#if 0 // this needs to take the config file name as an argument. - ht_env.import_config ("../HTBP_Config.conf"); -#endif /* 0 */ - - ACE::HTBP::ID_Requestor req (&ht_env); - ACE::HTBP::Addr local(ACE_TEXT_ALWAYS_CHAR(req.get_HTID())); - - char hostname [128]; - - if (ACE_OS::hostname (hostname,128) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "Could not get the host name\n"),0); - - ACE_INET_Addr *remote_addr = reinterpret_cast (arg); - ACE::HTBP::Addr remote (remote_addr->get_port_number (),hostname); - - unsigned pport; - ACE_TString phost; - ht_env.get_proxy_port(pport); - ht_env.get_proxy_host(phost); - - ACE_INET_Addr proxy(pport,phost.c_str()); - ACE::HTBP::Session session(remote,local,ACE::HTBP::Session::next_session_id(),&proxy); - ACE::HTBP::Stream stream(&session); - - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) Connecting to port %d\n"), - remote.get_port_number())); - - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) connected to %s\n"), - ACE_TEXT_CHAR_TO_TCHAR(remote.get_host_name ()))); - - //******************* TEST 1 ****************************** - // - // Do a iovec sendv - send the 255 byte buffer in 5 chunks. The - // server will verify that the correct data is sent, and that there - // is no more and no less. - - u_char buffer[255]; - size_t i; - ssize_t len; - - // The server will verify that this data pattern gets there intact. - - for (i = 0; i < sizeof buffer; ++i) - buffer[i] = static_cast (i); - - iovec iov[5]; - - iov[0].iov_base = reinterpret_cast (&buffer[0]); - iov[0].iov_len = 50; - - iov[1].iov_base = reinterpret_cast (&buffer[50]); - iov[1].iov_len = 25; - - iov[2].iov_base = reinterpret_cast (&buffer[75]); - iov[2].iov_len = 150; - - iov[3].iov_base = reinterpret_cast (&buffer[225]); - iov[3].iov_len = 29; - - iov[4].iov_base = reinterpret_cast (&buffer[254]); - iov[4].iov_len = 1; - - len = stream.sendv (iov, 5); - if (len == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n"), - ACE_TEXT ("Test 1, sendv failed"))); - Test_Result = 1; - } - else - ACE_ASSERT (len == 255); - - - ACE_DEBUG ((LM_DEBUG, "***** client TEST 2 ***** \n")); - - //******************* TEST 2 ****************************** - // - // The same data is coming back - receive it using recv (size_t n, - // ...) and compare it to the original data. - - u_char buffer2[255]; - // Give it a chance to get here - ACE_OS::sleep (2); - - len = stream.recv_n (buffer2, - 155); - - - len = stream.recv_n (buffer2, - 105); - - for (i = 0; i < 255; i++) - if (buffer2[i] != buffer[i]) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) Test 2, rcvd byte %d is %d, not %d\n"), - i, buffer2[i], buffer[i])); - Test_Result = 1; - } - - - stream.close (); - - return 0; -} - -static void * -server (void *arg) -{ - - ACE_OS::socket_init (ACE_WSOCK_VERSION); - ACE_SOCK_Acceptor *peer_acceptor = (ACE_SOCK_Acceptor *) arg; - ACE_INET_Addr cli_addr; - - ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT); - - ACE_SOCK_Stream sock[2]; - ACE_DEBUG ((LM_DEBUG,"server is ready\n")); - - if (peer_acceptor->accept(sock[0],&cli_addr,&timeout) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n"), - ACE_TEXT ("accept"))); - Test_Result = 1; - return 0; - } - - ACE::HTBP::Channel channel1(sock[0]); - ACE_DEBUG ((LM_DEBUG,"Got sock[0], handle = %d\n",sock[0].get_handle())); - - if (peer_acceptor->accept(sock[0],&cli_addr,&timeout) == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n"), - ACE_TEXT ("accept"))); - Test_Result = 1; - return 0; - } - - ACE::HTBP::Channel channel2(sock[1]); - ACE_DEBUG ((LM_DEBUG,"Got sock[1], handle = %d\n",sock[1].get_handle())); - int res = 0; - while ((res = channel1.pre_recv()) != 0) - { - ACE_DEBUG ((LM_DEBUG,"res = %d. waiting 1 sec. %p\n",res, - "stream.pre_recv()")); - ACE_OS::sleep (1); - } - - ACE_DEBUG ((LM_DEBUG,"Read from channel2\n")); - while ((res = channel2.pre_recv()) != 0) - { - ACE_DEBUG ((LM_DEBUG,"res = %d, waiting 1 sec. %p\n",res, - "stream2.pre_recv()")); - ACE_OS::sleep (1); - } - - ACE::HTBP::Session *session = channel1.session(); - ACE::HTBP::Stream stream (session); - - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) client %s connected from %d\n"), - ACE_TEXT_CHAR_TO_TCHAR(cli_addr.get_host_name ()), - cli_addr.get_port_number ())); - - //******************* TEST 1 ****************************** - // - // Do a iovec recvv - the client should send 255 bytes, which we - // will be detected and read into a ACE-allocated buffer. Use a 5 - // second timeout to give the client a chance to send it all. - - ACE_OS::sleep (5); - - u_char buffer[255]; - - iovec iov[3]; - - ssize_t len; - int i; - - iov[0].iov_base = reinterpret_cast (&buffer[0]); - iov[0].iov_len = 75; - - iov[1].iov_base = reinterpret_cast (&buffer[75]); - iov[1].iov_len = 100; - - iov[2].iov_base = reinterpret_cast (&buffer[175]); - iov[2].iov_len = 80; - - len = stream.recvv (iov, 3); - if (len == -1) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n"), - ACE_TEXT ("Test 1, recvv failed"))); - Test_Result = 1; - } - - for (i = 0; i < 255; i++) - if (buffer[i] != i) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) Test 1, rcvd byte %d is %d, not %d\n"), - i, - buffer[i], - i)); - Test_Result = 1; - } - - ACE_DEBUG ((LM_DEBUG, "***** TEST 2 ***** \n")); - - //******************* TEST 2 ****************************** - // - // Send the buffer back, using send (size_t n, ...) in 3 pieces. - - len = stream.send (buffer, 6); - len += stream.send (buffer,42); - len += stream.send (buffer,189); - len += stream.send_n (buffer,18); - ACE_ASSERT (len == 255); - sock[0].close(); - sock[1].close(); - stream.close (); - return 0; -} - -#endif /* !ACE_LACKS_FORK || ACE_HAS_THREADS */ - -static void -spawn (void) -{ - // Acceptor - ACE_SOCK_Acceptor peer_acceptor; - - // Create a server address. - ACE_INET_Addr server_addr; - - char hostname[BUFSIZ]; - - if (ACE_OS::hostname (hostname, BUFSIZ) != 0) - { - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("Could not get the hostname\n"))); - } - - ACE::HTBP::Addr addr (8088, hostname); - - // Bind listener to any port and then find out what the port was. - if (peer_acceptor.open (addr) == -1 - || peer_acceptor.get_local_addr (server_addr) == -1) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n"), - ACE_TEXT ("open"))); - else - { - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) starting server at port %d\n"), - server_addr.get_port_number ())); - -#if !defined (ACE_LACKS_FORK) - switch (ACE_OS::fork (ACE_TEXT("child"))) - { - case -1: - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n%a"), - ACE_TEXT ("fork failed"), - 1)); - /* NOTREACHED */ - case 0: - client (&server_addr); - ACE_OS::exit (0); - /* NOTREACHED */ - default: - server (reinterpret_cast (&peer_acceptor)); - ACE_OS::wait (); - } -#elif defined (ACE_HAS_THREADS) - if (ACE_Thread_Manager::instance ()->spawn - (ACE_THR_FUNC (server), - reinterpret_cast (&peer_acceptor), - THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n%a"), - ACE_TEXT ("thread create failed"), - 1)); - - if (ACE_Thread_Manager::instance ()->spawn - (ACE_THR_FUNC (client), - reinterpret_cast (&server_addr), - THR_NEW_LWP | THR_DETACHED) == -1) - ACE_ERROR ((LM_ERROR, - ACE_TEXT ("(%P|%t) %p\n%a"), - ACE_TEXT ("thread create failed"), - 1)); - - // Wait for the threads to exit. - ACE_Thread_Manager::instance ()->wait (); -#else - ACE_ERROR ((LM_INFO, - ACE_TEXT ("(%P|%t) ") - ACE_TEXT ("only one thread may be run ") - ACE_TEXT ("in a process on this platform\n"))); -#endif /* ACE_HAS_THREADS */ - - peer_acceptor.close (); - } -} - -int -ACE_TMAIN (int, ACE_TCHAR *[]) -{ - ACE_START_TEST (ACE_TEXT ("SOCK_Send_Recv_Test")); - - spawn (); - - ACE_END_TEST; - return Test_Result; -} diff --git a/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.mpc b/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.mpc index 64a40f688d1..b91c55e9763 100644 --- a/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.mpc +++ b/ACE/protocols/tests/HTBP/Send_Recv_Tests/SendRecv_Test.mpc @@ -3,12 +3,18 @@ // $Id$ // -project: aceexe, htbp { - exename = SendRecv_Test - after += Test_Output - libs += Test_Output +project(*server): aceexe, htbp { + exename = server Source_Files { - SendRecv_Test.cpp + server.cpp + } +} + +project(*client): aceexe, htbp { + exename = client + + Source_Files { + client.cpp } } diff --git a/ACE/protocols/tests/HTBP/Send_Recv_Tests/client.cpp b/ACE/protocols/tests/HTBP/Send_Recv_Tests/client.cpp new file mode 100644 index 00000000000..e8a7756f9be --- /dev/null +++ b/ACE/protocols/tests/HTBP/Send_Recv_Tests/client.cpp @@ -0,0 +1,224 @@ +// $Id$ + +// =========================================================================== +// +// = LIBRARY +// tests +// +// = FILENAME +// Send_Recv_Test.cpp +// +// = DESCRIPTION This is a test of the 's various send and +// receive methods, over HTBP. The test forks two processes or spawns +// two threads (depending upon the platform) and then executes client +// and server allowing them to connect and exchange data in ways +// designed to exercise the send and recv functions. +// +// Right now, it primarily tests the iov-like send and recv +// functions, but others should be added to completely cover the +// possible scenarios. +// +// = AUTHOR +// Steve Huston +// +// ============================================================================ + +#include "ace/HTBP/HTBP_Stream.h" +#include "ace/HTBP/HTBP_Session.h" +#include "ace/HTBP/HTBP_ID_Requestor.h" +#include "ace/HTBP/HTBP_Environment.h" + +#include "ace/OS.h" +#include "ace/Thread.h" +#include "ace/Thread_Manager.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/SOCK_Stream.h" +#include "ace/Get_Opt.h" + +// Change to non-zero if test fails +static int Test_Result = 0; + +const size_t Test3_Send_Size = 4*1024; +const size_t Test3_Loops = 10; +const size_t Test3_Total_Size = Test3_Send_Size * Test3_Loops; + +const ACE_TCHAR * remote_host = 0; +const ACE_TCHAR * config_file = 0; +unsigned remote_port = 8088; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "p:h:c:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + remote_port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + case 'h': + remote_host = get_opts.opt_arg (); + break; + case 'c': + config_file = get_opts.opt_arg (); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("usage: %s ") + ACE_TEXT ("-h remote_host ") + ACE_TEXT ("-p remote_port ") + ACE_TEXT ("-c config_file ") + ACE_TEXT ("\n"), + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + ACE_OS::socket_init (ACE_WSOCK_VERSION); + + if (parse_args(argc, argv) != 0) + return 1; + if (remote_host == 0) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Client: No remote host specified\n")),1); + + ACE::HTBP::Environment env; + if (config_file != 0) + env.import_config (config_file); + + ACE::HTBP::ID_Requestor req (&env); + ACE::HTBP::Addr local(ACE_TEXT_ALWAYS_CHAR(req.get_HTID())); + + unsigned proxy_port = 0; + ACE_TString proxy_host; + + if (env.get_proxy_port(proxy_port) != 0 || + env.get_proxy_host(proxy_host) != 0) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P|%t) Client: ") + ACE_TEXT("no proxy address in ") + ACE_TEXT("config, using direct connect\n"))); + proxy_port = remote_port; + proxy_host = remote_host; + } + + ACE_INET_Addr proxy(proxy_port,proxy_host.c_str()); + ACE::HTBP::Addr remote (remote_port, + ACE_TEXT_ALWAYS_CHAR(remote_host)); + + ACE::HTBP::Session session(remote, + local, + ACE::HTBP::Session::next_session_id(), + &proxy); + + ACE::HTBP::Stream stream(&session); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Connecting to port %d\n"), + remote.get_port_number())); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) connected to %s\n"), + ACE_TEXT_CHAR_TO_TCHAR(remote.get_host_name ()))); + + //******************* TEST 1 ****************************** + // + // Do a iovec sendv - send the 255 byte buffer in 5 chunks. The + // server will verify that the correct data is sent, and that there + // is no more and no less. + + u_char buffer[255]; + size_t i; + ssize_t len; + + // The server will verify that this data pattern gets there intact. + + for (i = 0; i < sizeof buffer; ++i) + buffer[i] = static_cast (i); + + iovec iov[5]; + + iov[0].iov_base = reinterpret_cast (&buffer[0]); + iov[0].iov_len = 50; + + iov[1].iov_base = reinterpret_cast (&buffer[50]); + iov[1].iov_len = 25; + + iov[2].iov_base = reinterpret_cast (&buffer[75]); + iov[2].iov_len = 150; + + iov[3].iov_base = reinterpret_cast (&buffer[225]); + iov[3].iov_len = 29; + + iov[4].iov_base = reinterpret_cast (&buffer[254]); + iov[4].iov_len = 1; + + len = stream.sendv (iov, 5); + ACE_DEBUG ((LM_DEBUG,"(%P) after send, len = %d\n")); + if (len == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("Test 1, sendv failed"))); + Test_Result = 1; + } + else + ACE_ASSERT (len == 255); + + + ACE_DEBUG ((LM_DEBUG, "(%P) ***** client TEST 2 ***** \n")); + + //******************* TEST 2 ****************************** + // + // The same data is coming back - receive it using recv (size_t n, + // ...) and compare it to the original data. + + u_char buffer2[255]; + printf ("client - waiting!\n"); + // Give it a chance to get here + ACE_OS::sleep (60); + + do { + len = stream.recv (buffer2, 155); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P) Test 2: want 155 bytes, got %d\n"), + len)); + if (len == -1 || errno == EWOULDBLOCK) + + ACE_OS::sleep (1); + } while (len == -1 && errno == EWOULDBLOCK); + + if (len != 155) + Test_Result = 1; + + len = stream.recv (buffer2, 105); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P) Test 2: second read want 105 bytes, got %d\n"), + len)); + + if (len != 105) + Test_Result = 1; + + for (i = 0; Test_Result == 0 && i < 255; i++) + if (buffer2[i] != buffer[i]) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) Test 2, rcvd byte %d is %d, not %d\n"), + i, buffer2[i], buffer[i])); + Test_Result = 1; + } + + + stream.close (); + + return 0; +} diff --git a/ACE/protocols/tests/HTBP/Send_Recv_Tests/run_test.pl b/ACE/protocols/tests/HTBP/Send_Recv_Tests/run_test.pl new file mode 100755 index 00000000000..f92fe574ac3 --- /dev/null +++ b/ACE/protocols/tests/HTBP/Send_Recv_Tests/run_test.pl @@ -0,0 +1,46 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; +use Sys::Hostname; + +$status = 0; + +$host = hostname(); +if (PerlACE::is_vxworks_test()) { + $host = $ENV{'ACE_RUN_VX_TGTHOST'}; + $SV = new PerlACE::ProcessVX ("server", ""); +} +else { + $SV = new PerlACE::Process ("server", ""); +} + +# The client code should later be modified to get the hostname +# using ACE_OS::hostname so the same script can be run on all +# hosts without havng to reset the host where it has to be run. +$CL = new PerlACE::Process ("client", "-h $host"); + +$SV->Spawn (); + +$client = $CL->SpawnWaitKill (300); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$server = $SV->WaitKill (10); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +unlink $iorfile; + +exit $status; diff --git a/ACE/protocols/tests/HTBP/Send_Recv_Tests/server.cpp b/ACE/protocols/tests/HTBP/Send_Recv_Tests/server.cpp new file mode 100644 index 00000000000..afe6acaa5bf --- /dev/null +++ b/ACE/protocols/tests/HTBP/Send_Recv_Tests/server.cpp @@ -0,0 +1,237 @@ +// $Id$ + +// =========================================================================== +// +// = LIBRARY +// tests +// +// = FILENAME +// Send_Recv_Test.cpp +// +// = DESCRIPTION This is a test of the 's various send and +// receive methods, over HTBP. The test forks two processes or spawns +// two threads (depending upon the platform) and then executes client +// and server allowing them to connect and exchange data in ways +// designed to exercise the send and recv functions. +// +// Right now, it primarily tests the iov-like send and recv +// functions, but others should be added to completely cover the +// possible scenarios. +// +// = AUTHOR +// Steve Huston +// +// ============================================================================ + +#include "ace/HTBP/HTBP_Stream.h" +#include "ace/HTBP/HTBP_Session.h" +#include "ace/HTBP/HTBP_ID_Requestor.h" +#include "ace/HTBP/HTBP_Environment.h" + +#include "ace/OS.h" +#include "ace/Thread.h" +#include "ace/Thread_Manager.h" +#include "ace/SOCK_Connector.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/SOCK_Stream.h" +#include "ace/Get_Opt.h" + +// Change to non-zero if test fails +static int Test_Result = 0; + +// In test 3, a large amount of data is sent. The purpose is to overflow the +// TCP send window, causing the sender to block (it's a send_n). This value +// is the amount to send. The assumption is that no implementation has a +// receive window larger than 128K bytes. If one is found, this is the place +// to change it. +// For some odd reason, NT will try to send a single large buffer, but not +// multiple smaller ones that add up to the large size. +const size_t Test3_Send_Size = 4*1024; +const size_t Test3_Loops = 10; +const size_t Test3_Total_Size = Test3_Send_Size * Test3_Loops; +unsigned port = 8088; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "p:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-p port " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + ACE_OS::socket_init (ACE_WSOCK_VERSION); + + if (parse_args(argc, argv) != 0) + return 1; + + // Acceptor + ACE_SOCK_Acceptor peer_acceptor; + + // Create a server address. + ACE_INET_Addr server_addr; + + char hostname[BUFSIZ]; + + if (ACE_OS::hostname (hostname, BUFSIZ) != 0) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("Could not get the hostname\n"))); + } + + ACE::HTBP::Addr addr (8088, hostname); + + // Bind listener to any port and then find out what the port was. + if (peer_acceptor.open (addr) == -1 + || peer_acceptor.get_local_addr (server_addr) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("open")), 1); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) starting server at port %d\n"), + server_addr.get_port_number ())); + + ACE_INET_Addr cli_addr; + + ACE_SOCK_Stream sock_stream[2]; + ACE_DEBUG ((LM_DEBUG,"(%P) server is ready\n")); + + if (peer_acceptor.accept(sock_stream[0],&cli_addr,0) == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("accept"))); + Test_Result = 1; + return 0; + } + + ACE::HTBP::Channel channel1(sock_stream[0]); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P) Got sock[0], handle = %d\n"), + sock_stream[0].get_handle())); + + if (peer_acceptor.accept(sock_stream[1],&cli_addr,0) == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("accept"))); + Test_Result = 1; + return 0; + } + + ACE::HTBP::Channel channel2(sock_stream[1]); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P) Got sock_stream[1], handle = %d\n"), + sock_stream[1].get_handle())); + int res = 0; + while ((res = channel1.pre_recv()) != 0) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P)res = %d. waiting 1 sec. %p\n"), + res, + ACE_TEXT("stream.pre_recv()"))); + ACE_OS::sleep (1); + } + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P)Read from channel2\n"))); + while ((res = channel2.pre_recv()) != 0) + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P)res = %d, waiting 1 sec. %p\n"),res, + ACE_TEXT("stream2.pre_recv()"))); + ACE_OS::sleep (1); + } + + ACE::HTBP::Session *session = channel1.session(); + ACE::HTBP::Stream stream (session); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) client %s connected from %d\n"), + ACE_TEXT_CHAR_TO_TCHAR(cli_addr.get_host_name ()), + cli_addr.get_port_number ())); + + //******************* TEST 1 ****************************** + // + // Do a iovec recvv - the client should send 255 bytes, which we + // will be detected and read into a ACE-allocated buffer. Use a 5 + // second timeout to give the client a chance to send it all. + + ACE_OS::sleep (5); + + u_char buffer[255]; + + iovec iov[3]; + + ssize_t len; + int i; + + iov[0].iov_base = reinterpret_cast (&buffer[0]); + iov[0].iov_len = 75; + + iov[1].iov_base = reinterpret_cast (&buffer[75]); + iov[1].iov_len = 100; + + iov[2].iov_base = reinterpret_cast (&buffer[175]); + iov[2].iov_len = 80; + + len = stream.recvv (iov, 3); + if (len == -1) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) %p\n"), + ACE_TEXT ("Test 1, recvv failed"))); + Test_Result = 1; + } + + for (i = 0; i < 255; i++) + if (buffer[i] != i) + { + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("(%P|%t) Test 1, rcvd byte %d is %d, not %d\n"), + i, + buffer[i], + i)); + Test_Result = 1; + } + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT("(%P) server: ***** TEST 2 ***** \n"))); + + //******************* TEST 2 ****************************** + // + // Send the buffer back, using send (size_t n, ...) in 3 pieces. + + len = stream.send (buffer, 6); + len += stream.send (buffer,42); + len += stream.send (buffer,189); + len += stream.send (buffer,18); + ACE_ASSERT (len == 255); + sock_stream[0].close(); + sock_stream[1].close(); + stream.close (); + + peer_acceptor.close (); + + return 0; +} diff --git a/ACE/protocols/tests/HTBP/ping/client.cpp b/ACE/protocols/tests/HTBP/ping/client.cpp index e7753faab6d..7e74c290ba1 100644 --- a/ACE/protocols/tests/HTBP/ping/client.cpp +++ b/ACE/protocols/tests/HTBP/ping/client.cpp @@ -6,6 +6,7 @@ #include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" #include "ace/HTBP/HTBP_Session.h" #include "ace/HTBP/HTBP_Stream.h" @@ -13,28 +14,60 @@ #include "ace/HTBP/HTBP_ID_Requestor.h" #include "ace/HTBP/HTBP_Environment.h" +const ACE_TCHAR * remote_host = 0; +const ACE_TCHAR * config_file = 0; +unsigned remote_port = 8088; + int -ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +parse_args (int argc, char *argv[]) { + ACE_Get_Opt get_opts (argc, argv, "p:h:c:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + remote_port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + case 'h': + remote_host = get_opts.opt_arg (); + break; + case 'c': + config_file = get_opts.opt_arg (); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("usage: %s ") + ACE_TEXT ("-h remote_host ") + ACE_TEXT ("-p remote_port ") + ACE_TEXT ("-c config_file ") + ACE_TEXT ("\n"), + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ ACE_OS::socket_init (ACE_WSOCK_VERSION); - if (argc < 2) + if (parse_args(argc, argv) != 0) + return 1; + if (remote_host == 0) ACE_ERROR_RETURN ((LM_ERROR, - "Usage: client \n"), - 0); - ACE::HTBP::Environment env; -#if 0 // this should be a taken from a command line argument - env.import_config (ACE_TEXT("../HTBP_Config.conf")); -#endif /* 0 */ + ACE_TEXT ("Client: No remote host specified\n")),1); + ACE::HTBP::Environment env; + if (config_file != 0) + env.import_config (config_file); ACE::HTBP::ID_Requestor req (&env); ACE::HTBP::Addr local(ACE_TEXT_ALWAYS_CHAR(req.get_HTID())); - unsigned remote_port = 8088; - const ACE_TCHAR * remote_host = argv[1]; - unsigned proxy_port = 0; ACE_TString proxy_host; @@ -42,6 +75,7 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) env.get_proxy_host(proxy_host) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") ACE_TEXT("no proxy address in ") ACE_TEXT("config, using direct connect\n"))); proxy_port = remote_port; @@ -66,23 +100,34 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) ACE::HTBP::Channel *ob = session.outbound(); n = stream.send (buffer,ACE_OS::strlen(buffer)+1); if (n == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n","stream send"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("%p\n"), + ACE_TEXT("stream send")),-1); - ACE_DEBUG ((LM_DEBUG, "send returned %d\n",n)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("send returned %d\n"),n)); retrycount = 10; - ACE_DEBUG ((LM_DEBUG,"after send, outbound = %x, ob = %x\n", + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("after send, outbound = %x, ob = %x\n"), session.outbound(), ob)); while ((n = ob->recv_ack()) == -1 && (errno == EWOULDBLOCK || errno == ETIME) && retrycount > 0) { retrycount--; - ACE_DEBUG ((LM_DEBUG,"waiting for ack, %d tries left\n", + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("waiting for ack, %d tries left\n"), retrycount)); ACE_OS::sleep (1); } - ACE_DEBUG ((LM_DEBUG,"After wait for ack, n = %d, retry = %d\n", + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("After wait for ack, n = %d, retry = %d\n"), n,retrycount,errno)); retrycount = 10; @@ -91,27 +136,38 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) && retrycount > 0) { retrycount--; - ACE_DEBUG ((LM_DEBUG,"waiting for inbound data, %d tries left\n", + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("waiting for inbound data, %d tries left\n"), retrycount)); ACE_OS::sleep(1); } if (retrycount == 0 || n < 0) { - ACE_DEBUG ((LM_DEBUG,"bailing after wait, %p\n","recv")); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("bailing after wait, %p\n"),"recv")); break; } buffer[n] = 0; - ACE_DEBUG ((LM_DEBUG,"Got: \"%s\"\n",buffer)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("Got: \"%s\"\n"),buffer)); } ACE::HTBP::Channel *ob = session.outbound(); n = stream.send ("goodbye",7); if (n == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n","stream send"),-1); + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("%p\n"), + ACE_TEXT("stream send")),-1); - ACE_DEBUG ((LM_DEBUG, "send returned %d\n",n)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("send returned %d\n"),n)); retrycount = 10; while ((n = ob->recv_ack()) == -1 @@ -119,11 +175,15 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) && retrycount > 0) { retrycount--; - ACE_DEBUG ((LM_DEBUG,"waiting for ack, %d tries left\n", + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("waiting for ack, %d tries left\n"), retrycount)); ACE_OS::sleep (1); } - ACE_DEBUG ((LM_DEBUG,"After wait for ack, n = %d, retry = %d\n", + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Client: ") + ACE_TEXT ("After wait for ack, n = %d, retry = %d\n"), n,retrycount,errno)); return 0; diff --git a/ACE/protocols/tests/HTBP/ping/run_test.pl b/ACE/protocols/tests/HTBP/ping/run_test.pl index ae4c56c7fb2..21bd50c868e 100755 --- a/ACE/protocols/tests/HTBP/ping/run_test.pl +++ b/ACE/protocols/tests/HTBP/ping/run_test.pl @@ -10,15 +10,19 @@ use PerlACE::Run_Test; use Sys::Hostname; $status = 0; - -$SV = new PerlACE::Process ("server"); - $host = hostname(); +if (PerlACE::is_vxworks_test()) { + $host = $ENV{'ACE_RUN_VX_TGTHOST'}; + $SV = new PerlACE::ProcessVX ("server", ""); +} +else { + $SV = new PerlACE::Process ("server", ""); +} # The client code should later be modified to get the hostname # using ACE_OS::hostname so the same script can be run on all # hosts without havng to reset the host where it has to be run. -$CL = new PerlACE::Process ("client", $host); +$CL = new PerlACE::Process ("client", " -h $host"); $SV->Spawn (); diff --git a/ACE/protocols/tests/HTBP/ping/server.cpp b/ACE/protocols/tests/HTBP/ping/server.cpp index d20d46b8b09..81405f8d1f3 100644 --- a/ACE/protocols/tests/HTBP/ping/server.cpp +++ b/ACE/protocols/tests/HTBP/ping/server.cpp @@ -12,34 +12,68 @@ #include "ace/SOCK_Acceptor.h" #include "ace/SOCK_Stream.h" +#include "ace/Get_Opt.h" + +unsigned port = 8088; int -ACE_TMAIN (int, ACE_TCHAR *[]) +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "p:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'p': + port = static_cast(ACE_OS::atoi (get_opts.opt_arg())); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-p port " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +ACE_TMAIN (int argc , ACE_TCHAR *argv[]) { char buffer[1000]; ssize_t n = 0; - ACE_OS::socket_init (ACE_WSOCK_VERSION); - ACE_INET_Addr local(8088); + if (parse_args(argc, argv) != 0) + return 1; + + ACE_INET_Addr local(port); ACE_SOCK_Stream sock[2]; ACE_SOCK_Acceptor acc(local,1); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("server is ready\n"))); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server is ready\n"))); acc.accept (sock[0]); ACE::HTBP::Channel channel1(sock[0]); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("Got sock[0], handle = %d\n"), sock[0].get_handle())); acc.accept (sock[1]); ACE::HTBP::Channel channel2 (sock[1]); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("Got sock[1], handle = %d\n"), sock[1].get_handle())); int res = 0; while ((res = channel1.pre_recv ()) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("res = %d. waiting 1 sec. %p\n"), res, ACE_TEXT ("stream.pre_recv()"))); @@ -50,6 +84,7 @@ ACE_TMAIN (int, ACE_TCHAR *[]) while ((res = channel2.pre_recv()) != 0) { ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("res = %d, waiting 1 sec. %p\n"), res, ACE_TEXT ("stream2.pre_recv()"))); @@ -60,6 +95,7 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE::HTBP::Stream stream (session); ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("using streams %d, %d. Got sesssion = %@\n"), sock[0].get_handle(), sock[1].get_handle(), @@ -74,6 +110,7 @@ ACE_TMAIN (int, ACE_TCHAR *[]) { retrycount--; ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("waiting for inbound data, %d tries left\n"), retrycount)); ACE_OS::sleep(1); @@ -83,7 +120,9 @@ ACE_TMAIN (int, ACE_TCHAR *[]) buffer[n] = 0; - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Got: \"%C\"\n"), buffer)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") + ACE_TEXT ("Got: \"%C\"\n"), buffer)); if (ACE_OS::strstr (buffer,"goodbye") != 0) break; @@ -95,7 +134,8 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE_TEXT ("stream.send")), -1); - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Send returned %d\n"), n)); + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: Send returned %d\n"), n)); int got[2] = {-1,-1}; while (got[0] == -1 || got[1] == -1) @@ -104,6 +144,7 @@ ACE_TMAIN (int, ACE_TCHAR *[]) { if ((got[0] = (res =channel1.pre_recv())) == -1) ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("res = %d, waiting 1 sec. %p\n"), got[0], ACE_TEXT ("channel1.pre_recv()"))); @@ -112,6 +153,7 @@ ACE_TMAIN (int, ACE_TCHAR *[]) { if ((got[1] = (res =channel2.pre_recv())) == -1) ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) Server: ") ACE_TEXT ("res = %d, waiting 1 sec. %p\n"), got[1], ACE_TEXT ("channel2.pre_recv()"))); -- cgit v1.2.1