diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-12-19 03:27:29 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1997-12-19 03:27:29 +0000 |
commit | d19d760e232bb6c93e386f90997b30730007345b (patch) | |
tree | e2addf02aa217061651069c07dd5c5182a706799 /examples | |
parent | fb719c4a051d25397139cab00f2fca9e44e08097 (diff) | |
download | ATCD-d19d760e232bb6c93e386f90997b30730007345b.tar.gz |
*** empty log message ***
Diffstat (limited to 'examples')
-rw-r--r-- | examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp | 35 | ||||
-rw-r--r-- | examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp | 138 |
2 files changed, 52 insertions, 121 deletions
diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp index d298955aa7a..54ed35d8518 100644 --- a/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp +++ b/examples/IPC_SAP/SOCK_SAP/CPP-inclient.cpp @@ -80,16 +80,13 @@ Options::read (char *buf, size_t len, size_t &iteration) { if (io_source_ == ACE_STDIN) return ACE_OS::read (ACE_STDIN, buf, sizeof buf); + else if (iteration >= this->iterations_) + return 0; else { - if (iteration >= this->iterations_) - return 0; - else - { - ACE_OS::strncpy (buf, "TAO", len); - iteration++; - return ACE_OS::strlen ("TAO") + 1; - } + ACE_OS::strncpy (buf, "TAO", len); + iteration++; + return ACE_OS::strlen ("TAO") + 1; } } @@ -192,12 +189,6 @@ client (void *) "(%P|%t) connected to %s\n", remote_addr.get_host_name ())); - if (cli_stream.disable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) %p\n", - "disable"), - 0); - // This variable is allocated off the stack to obviate the need for // locking. size_t iteration = 0; @@ -211,17 +202,11 @@ client (void *) options->quit_string (), ACE_OS::strlen (options->quit_string ())) == 0) break; - else if (cli_stream.send (buf, r_bytes, 0, options->timeout ()) == -1) - { - if (errno == ETIME) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) %p\n", "send_n")); - else - // Breakout if we didn't fail due to a timeout. - ACE_ERROR_RETURN ((LM_ERROR, - "(%P|%t) %p\n", - "send_n"), - 0); - } + else if (cli_stream.send (buf, r_bytes, 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) %p\n", + "send_n"), + 0); else if (cli_stream.recv (buf, sizeof buf) <= 0) ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", diff --git a/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp b/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp index a2e44d0eca2..2aab0c6cbd8 100644 --- a/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp +++ b/examples/IPC_SAP/SOCK_SAP/CPP-inserver.cpp @@ -1,7 +1,8 @@ // $Id$ -// This example tests the non-blocking features of the -// ACE_SOCK_Acceptor and ACE_SOCK_Stream classes. +// This example tests the features of the ACE_SOCK_Acceptor and +// ACE_SOCK_Stream classes when used with a thread-per-request +// concurrency model. #include "ace/SOCK_Acceptor.h" #include "ace/SOCK_Stream.h" @@ -12,74 +13,41 @@ // Are we running verbosely? static int verbose = 0; -static ACE_Time_Value timeout; - -static int sleep_time; - // ACE SOCK_SAP server. -void * +// Entry point into the server task. + +static void * server (void *arg) { - ACE_Handle_Set handle_set; ACE_SOCK_Stream new_stream; ACE_HANDLE handle = ACE_HANDLE (arg); new_stream.set_handle (handle); - // Enable non-blocking I/O. - if (new_stream.enable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "enable"), 0); - - handle_set.set_bit (new_stream.get_handle ()); - // Read data from client (terminate on error). - for (ssize_t r_bytes;;) + for (;;) { - // Wait to read until there's something from the client. - if (ACE_OS::select (int (new_stream.get_handle ()) + 1, - handle_set, - 0, 0, timeout) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "select"), 0); - - // Keep reading until the client shuts down. - for (;;) + char buf[BUFSIZ]; + + ssize_t r_bytes = new_stream.recv (buf, sizeof buf, 0); + + if (r_bytes == -1) { - // Sleep for some amount of time in order to test client - // flow control. - ACE_OS::sleep (sleep_time); - - char buf[BUFSIZ]; - - r_bytes = new_stream.recv (buf, sizeof buf, 0, &timeout); - - if (r_bytes <= 0) - { - if (errno == ETIME) - ACE_ERROR ((LM_ERROR, "%p\n", "recv")); - break; - } - else if (verbose && ACE::write_n (ACE_STDOUT, buf, r_bytes) != r_bytes) - ACE_ERROR ((LM_ERROR, "%p\n", "ACE::write_n")); - else if (new_stream.send_n (buf, r_bytes) != r_bytes) - ACE_ERROR ((LM_ERROR, "%p\n", "send_n")); + ACE_ERROR ((LM_ERROR, "%p\n", "recv")); + break; } - - if (r_bytes == 0) + else if (r_bytes == 0) { ACE_DEBUG ((LM_DEBUG, "(%P|%t) reached end of input, connection closed by client\n")); break; } - else if (r_bytes == -1) - { - if (errno == EWOULDBLOCK || errno == ETIME) - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) no input available, going back to reading\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "recv"), 0); - } + else if (verbose && ACE::write_n (ACE_STDOUT, buf, r_bytes) != r_bytes) + ACE_ERROR ((LM_ERROR, "%p\n", "ACE::write_n")); + else if (new_stream.send_n (buf, r_bytes) != r_bytes) + ACE_ERROR ((LM_ERROR, "%p\n", "send_n")); } // Close new endpoint (listening endpoint stays open). @@ -95,8 +63,6 @@ main (int argc, char *argv[]) u_short port = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT; - timeout = argc > 2 ? ACE_OS::atoi (argv[2]) : ACE_DEFAULT_TIMEOUT; - sleep_time = argc > 3 ? ACE_OS::atoi (argv[3]) : 0; ACE_SOCK_Acceptor peer_acceptor; @@ -105,65 +71,45 @@ main (int argc, char *argv[]) // Create a server, reuse the address. if (peer_acceptor.open (server_addr, 1) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "open"), 1); - // Set the peer acceptor into non-blocking mode. - else if (peer_acceptor.enable (ACE_NONBLOCK) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "enable"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "open"), + 1); else if (peer_acceptor.get_local_addr (server_addr) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "get_local_addr"), 1); + ACE_ERROR_RETURN ((LM_ERROR, + "%p\n", + "get_local_addr"), + 1); - ACE_DEBUG ((LM_DEBUG, "(%P|%t) starting server at port %d\n", + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) starting server at port %d\n", server_addr.get_port_number ())); // Keep these objects out here to prevent excessive constructor // calls within the loop. ACE_SOCK_Stream new_stream; ACE_INET_Addr cli_addr; - ACE_Handle_Set handle_set; // Performs the iterative server activities. - for (;;) + while (peer_acceptor.accept (new_stream, &cli_addr) != -1) { - handle_set.reset (); - handle_set.set_bit (peer_acceptor.get_handle ()); - - int result = ACE_OS::select (int (peer_acceptor.get_handle ()) + 1, - handle_set, - 0, 0, &timeout); - if (result == -1) - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "select"), -1); - else if (result == 0) - ACE_DEBUG ((LM_DEBUG, "(%P|%t) select timed out\n")); - else - { - // Create a new ACE_SOCK_Stream endpoint (note automatic restart - // if errno == EINTR). - - while ((result = peer_acceptor.accept (new_stream, &cli_addr)) != -1) - { - ACE_DEBUG ((LM_DEBUG, "(%P|%t) client %s connected from %d\n", - cli_addr.get_host_name (), cli_addr.get_port_number ())); + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) client %s connected from %d\n", + cli_addr.get_host_name (), + cli_addr.get_port_number ())); #if defined (ACE_HAS_THREADS) - if (ACE_Thread_Manager::instance ()->spawn ((ACE_THR_FUNC) server, - (void *) new_stream.get_handle ()) == -1) - ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) %p\n", "spawn"), 1); + if (ACE_Thread_Manager::instance ()->spawn ((ACE_THR_FUNC) server, + (void *) new_stream.get_handle ()) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "(%P|%t) %p\n", + "spawn"), + 1); #else - server ((void *) new_stream.get_handle ()); + server ((void *) new_stream.get_handle ()); #endif /* ACE_HAS_THREADS */ - } - - if (result == -1) - { - if (errno == EWOULDBLOCK) - ACE_DEBUG ((LM_DEBUG, - "(%P|%t) no connections available, going back to accepting\n")); - else - ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE::write"), -1); - } - } } - /* NOTREACHED */ + return 0; } |