summaryrefslogtreecommitdiff
path: root/examples/IPC_SAP
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1998-08-29 23:45:59 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1998-08-29 23:45:59 +0000
commitfc35da14c119c84ae289b20cc173ac7e7683e4fc (patch)
tree039ec2bfd2858dd2af3f591effc23595fb271419 /examples/IPC_SAP
parent4b6d52a029acc602c7ec50474a35a3743631caba (diff)
downloadATCD-fc35da14c119c84ae289b20cc173ac7e7683e4fc.tar.gz
*** empty log message ***
Diffstat (limited to 'examples/IPC_SAP')
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp23
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-inserver-fancy.cpp79
-rw-r--r--examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp39
3 files changed, 81 insertions, 60 deletions
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp
index 4bc15986e72..9e2f4f9c3cf 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp
@@ -112,7 +112,7 @@ private:
Options::Options (void)
: host_ (ACE_DEFAULT_SERVER_HOST),
port_ (ACE_DEFAULT_SERVER_PORT),
- sleep_time_ (0, 100000), // Sleep for 100 msecs between calls.
+ sleep_time_ (0, 0), // By default, don't sleep between calls.
threads_ (10),
quit_string_ ("q"),
message_len_ (0),
@@ -181,17 +181,16 @@ Options::read (void *buf, size_t len, size_t &iteration)
ACE_UNUSED_ARG (len);
if (this->io_source_ == ACE_STDIN)
- return ACE_OS::read (ACE_STDIN, buf, sizeof buf);
+ return ACE_OS::read (ACE_STDIN, buf, len);
else if (iteration >= this->iterations_)
return 0;
else
{
- size_t size = this->message_len ();
ACE_OS::memcpy (buf,
this->message_buf (),
- size);
+ len);
iteration++;
- return size;
+ return len;
}
}
@@ -313,8 +312,8 @@ Options::oneway_client_test (void *)
ACE_SOCK_Stream cli_stream;
// Add 1 to the port to trigger the oneway test!
- void *buf = options->shared_client_test (options->port () + 1,
- cli_stream);
+ void *request = options->shared_client_test (options->port () + 1,
+ cli_stream);
// This variable is allocated off the stack to obviate the need for
// locking.
size_t iteration = 0;
@@ -330,14 +329,14 @@ Options::oneway_client_test (void *)
// "incomplete writes").
for (ssize_t r_bytes;
- (r_bytes = options->read (buf, len, iteration)) > 0;
+ (r_bytes = options->read (request, len, iteration)) > 0;
// Transmit at the proper rate.
ACE_OS::sleep (options->sleep_time ()))
- if (ACE_OS::memcmp (buf,
+ if (ACE_OS::memcmp (request,
options->quit_string (),
ACE_OS::strlen (options->quit_string ())) == 0)
break;
- else if (cli_stream.send_n (buf, r_bytes) == -1)
+ else if (cli_stream.send_n (request, r_bytes) == -1)
{
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
@@ -349,7 +348,7 @@ Options::oneway_client_test (void *)
// Close the connection.
cli_stream.close ();
- delete [] buf;
+ delete [] request;
return (void *) result;
}
@@ -427,7 +426,7 @@ Options::twoway_client_test (void *)
timer.elapsed_time_incr (tv);
double real_time = tv.sec () * ACE_ONE_SECOND_IN_USECS + tv.usec ();
- double messages_per_sec = double (iteration * ACE_ONE_SECOND_IN_USECS) / real_time;
+ double messages_per_sec = iteration * double (ACE_ONE_SECOND_IN_USECS) / real_time;
ACE_DEBUG ((LM_DEBUG,
ASYS_TEXT ("(%t) messages = %d\n(%t) usec-per-message = %f\n(%t) messages-per-second = %0.00f\n"),
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inserver-fancy.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inserver-fancy.cpp
index 9c126024c95..e05fd7291f0 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-inserver-fancy.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-inserver-fancy.cpp
@@ -2,12 +2,13 @@
// This example tests the features of the <ACE_SOCK_Acceptor>,
// <ACE_SOCK_Stream>, and <ACE_Svc_Handler> classes. If the platform
-// supports threads it uses a thread-per-connection concurrency model;
-// otherwise it uses a single-threaded iterative server model.
+// supports threads it uses a thread-per-connection concurrency model.
+// Otherwise, it uses a single-threaded iterative server model.
#include "ace/SOCK_Acceptor.h"
#include "ace/Svc_Handler.h"
#include "ace/Profile_Timer.h"
+#include "ace/Get_Opt.h"
ACE_RCSID(SOCK_SAP, CPP_inserver_fancy, "$Id$")
@@ -36,7 +37,7 @@ private:
// Initialize the acceptors.
int create_handler (ACE_SOCK_Acceptor &acceptor,
- Handler *(*handler_factory) (ACE_HANDLE),
+ Handler *(*handler_factory) (ACE_HANDLE, int),
const char *handler_type);
// Factory that creates the right kind of <Handler>.
@@ -70,6 +71,9 @@ public:
virtual int open (void * = 0);
// Generic initialization method.
+ virtual int close (u_long);
+ // Close down and delete this.
+
protected:
Handler (ACE_HANDLE handle, int verbose = 0);
// Constructor.
@@ -87,7 +91,7 @@ protected:
virtual int svc (void);
// Template method entry point into the handler task.
- void print_results (void) = 0;
+ virtual void print_results (void);
// Print the results.
int verbose_;
@@ -127,7 +131,7 @@ private:
virtual int run (void);
// Template Method hook called by <svc>.
- void print_results (void) = 0;
+ virtual void print_results (void);
// Print the results.
};
@@ -135,9 +139,7 @@ Handler::Handler (ACE_HANDLE handle,
int verbose)
: verbose_ (verbose),
total_bytes_ (0),
- message_count_ (0),
- len_ (0),
- buf_ (0)
+ message_count_ (0)
{
this->peer ().set_handle (handle);
}
@@ -163,6 +165,16 @@ Handler::open (void *)
}
int
+Handler::close (u_long)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "(%P|%t) closing down %x\n",
+ this));
+ delete this;
+ return 0;
+}
+
+int
Handler::svc (void)
{
// Timer logic.
@@ -179,18 +191,16 @@ Handler::svc (void)
}
int
-Handler::parse_header_and_allocate_buffer (ACE_INT32 *len,
- char *&buf)
+Handler::parse_header_and_allocate_buffer (char *&request,
+ ACE_INT32 *len)
{
-
ssize_t result = this->peer ().recv_n ((void *) len,
sizeof (ACE_INT32));
-
if (result == 0)
{
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) connected closed\n"));
- return 0;
+ return -1;
}
else if (result == -1 || result != sizeof (ACE_INT32))
ACE_ERROR_RETURN ((LM_ERROR,
@@ -200,16 +210,19 @@ Handler::parse_header_and_allocate_buffer (ACE_INT32 *len,
else
{
*len = ntohl (*len);
- ACE_DEBUG ((LM_DEBUG,
- "(%P|%t) reading messages of size %d\n",
- *len));
- ACE_NEW_RETURN (buf,
+ ACE_NEW_RETURN (request,
char[*len],
-1);
}
+
return 0;
}
+void
+Handler::print_results (void)
+{
+}
+
Twoway_Handler::Twoway_Handler (ACE_HANDLE handle,
int verbose)
: Handler (handle, verbose)
@@ -226,14 +239,15 @@ Twoway_Handler::run (void)
for (;;)
{
ACE_INT32 len = 0;
- char *buf;
+ char *request;
- if (parse_header_and_allocate_buffer (buf,
- &len) <= 0)
+ if (parse_header_and_allocate_buffer (request,
+ &len) == -1)
return -1;
- ssize_t r_bytes = this->peer ().recv (buf,
- len);
+ // Subtract off the sizeof the length prefix.
+ ssize_t r_bytes = this->peer ().recv_n (request,
+ len - sizeof (ACE_UINT32));
if (r_bytes == -1)
{
@@ -250,12 +264,12 @@ Twoway_Handler::run (void)
}
else if (this->verbose_
&& ACE::write_n (ACE_STDOUT,
- this->buf_,
+ request,
r_bytes) != r_bytes)
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE::write_n"));
- else if (this->peer ().send_n (this->buf_,
+ else if (this->peer ().send_n (request,
r_bytes) != r_bytes)
ACE_ERROR ((LM_ERROR,
"%p\n",
@@ -303,12 +317,15 @@ Oneway_Handler::run (void)
for (;;)
{
ACE_INT32 len = 0;
- char *buf;
+ char *request;
- if (parse_header_and_allocate_buffer (buf, &len) <= 0)
+ if (parse_header_and_allocate_buffer (request,
+ &len) == -1)
return -1;
- ssize_t r_bytes = this->peer ().recv (buf, len);
+ // Subtract off the sizeof the length prefix.
+ ssize_t r_bytes = this->peer ().recv_n (request,
+ len - sizeof (ACE_UINT32));
if (r_bytes == -1)
{
@@ -325,7 +342,7 @@ Oneway_Handler::run (void)
}
else if (this->verbose_
&& ACE::write_n (ACE_STDOUT,
- this->buf_,
+ request,
r_bytes) != r_bytes)
ACE_ERROR ((LM_ERROR,
"%p\n",
@@ -384,7 +401,7 @@ Handler_Factory::init_acceptors (void)
int
Handler_Factory::create_handler (ACE_SOCK_Acceptor &acceptor,
- Handler * (*handler_factory) (ACE_HANDLE),
+ Handler * (*handler_factory) (ACE_HANDLE, int),
const char *handler_type)
{
ACE_SOCK_Stream new_stream;
@@ -442,7 +459,7 @@ Handler_Factory::parse_args (int argc, char *argv[])
}
Handler_Factory::Handler_Factory (int argc, char *argv[])
- : port_ (ACE_DEFAULT_PORT),
+ : port_ (ACE_DEFAULT_SERVER_PORT),
verbose_ (0)
{
}
@@ -485,7 +502,7 @@ Handler_Factory::handle_events (void)
ACE_ERROR ((LM_ERROR,
"(%P|%t) %p\n",
"select"));
- else if (result == 0)
+ else if (result == 0 && this->verbose_)
ACE_DEBUG ((LM_DEBUG,
"(%P|%t) select timed out\n"));
else
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp
index 9e9539a496f..9609cf49c81 100644
--- a/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp
+++ b/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp
@@ -1,8 +1,9 @@
// $Id$
-// This example tests the features of the <ACE_SOCK_Acceptor> and
-// <ACE_SOCK_Stream> classes. If the platform supports threads it
-// uses a thread-per-connection concurrency model.
+// This example tests the features of the <ACE_SOCK_Acceptor>,
+// <ACE_SOCK_Stream>, and <ACE_Svc_Handler> classes. If the platform
+// supports threads it uses a thread-per-connection concurrency model.
+// Otherwise, it uses a single-threaded iterative server model.
#include "ace/SOCK_Acceptor.h"
#include "ace/Thread_Manager.h"
@@ -63,7 +64,7 @@ twoway_server (void *arg)
size_t total_bytes = 0;
size_t message_count = 0;
- void *buf;
+ void *request;
// Read data from client (terminate on error).
@@ -96,14 +97,14 @@ twoway_server (void *arg)
else
{
len = ntohl (len);
- ACE_NEW_RETURN (buf,
+ ACE_NEW_RETURN (request,
char [len],
0);
}
// Subtract off the sizeof the length prefix.
- r_bytes = new_stream.recv (buf, len - sizeof (ACE_UINT32));
-
+ r_bytes = new_stream.recv_n (request,
+ len - sizeof (ACE_UINT32));
if (r_bytes == -1)
{
ACE_ERROR ((LM_ERROR,
@@ -118,11 +119,14 @@ twoway_server (void *arg)
break;
}
else if (verbose
- && ACE::write_n (ACE_STDOUT, buf, r_bytes) != r_bytes)
+ && ACE::write_n (ACE_STDOUT,
+ request,
+ r_bytes) != r_bytes)
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE::write_n"));
- else if (new_stream.send_n (buf, r_bytes) != r_bytes)
+ else if (new_stream.send_n (request,
+ r_bytes) != r_bytes)
ACE_ERROR ((LM_ERROR,
"%p\n",
"send_n"));
@@ -130,13 +134,13 @@ twoway_server (void *arg)
total_bytes += size_t (r_bytes);
message_count++;
- delete [] buf;
+ delete [] request;
}
// Close new endpoint (listening endpoint stays open).
new_stream.close ();
- delete [] buf;
+ delete [] request;
return 0;
}
@@ -175,7 +179,7 @@ oneway_server (void *arg)
size_t total_bytes = 0;
size_t message_count = 0;
- void *buf;
+ void *request;
// Read data from client (terminate on error).
@@ -208,13 +212,14 @@ oneway_server (void *arg)
else
{
len = ntohl (len);
- ACE_NEW_RETURN (buf,
+ ACE_NEW_RETURN (request,
char [len],
0);
}
// Subtract off the sizeof the length prefix.
- r_bytes = new_stream.recv (buf, len - sizeof (ACE_UINT32));
+ r_bytes = new_stream.recv_n (request,
+ len - sizeof (ACE_UINT32));
if (r_bytes == -1)
{
@@ -230,7 +235,7 @@ oneway_server (void *arg)
break;
}
else if (verbose
- && ACE::write_n (ACE_STDOUT, buf, r_bytes) != r_bytes)
+ && ACE::write_n (ACE_STDOUT, request, r_bytes) != r_bytes)
ACE_ERROR ((LM_ERROR,
"%p\n",
"ACE::write_n"));
@@ -238,7 +243,7 @@ oneway_server (void *arg)
total_bytes += size_t (r_bytes);
message_count++;
- delete [] buf;
+ delete [] request;
}
timer.stop ();
@@ -265,7 +270,7 @@ oneway_server (void *arg)
// Close new endpoint (listening endpoint stays open).
new_stream.close ();
- delete [] buf;
+ delete [] request;
return 0;
}