diff options
Diffstat (limited to 'ACE/examples/Reactor/TP_Reactor')
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/AcceptHandler.cpp | 108 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/AcceptHandler.h | 75 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/Makefile.am | 55 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/README | 86 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/ReadHandler.cpp | 152 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/ReadHandler.h | 92 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/TP_Reactor.mpc | 18 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/client.cpp | 141 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/common.h | 29 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/run_test.pl | 41 | ||||
-rw-r--r-- | ACE/examples/Reactor/TP_Reactor/server.cpp | 66 |
11 files changed, 0 insertions, 863 deletions
diff --git a/ACE/examples/Reactor/TP_Reactor/AcceptHandler.cpp b/ACE/examples/Reactor/TP_Reactor/AcceptHandler.cpp deleted file mode 100644 index 4ca0e6ac71b..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/AcceptHandler.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * $Id$ - * - * ACE reactor demonstration - * - * Date: 26-Jan-2006 - */ - -#include "common.h" -#include "AcceptHandler.h" -#include "ReadHandler.h" - -#include <ace/Auto_Ptr.h> -#include <ace/INET_Addr.h> -#include <ace/Log_Msg.h> - - -AcceptHandler:: AcceptHandler(ACE_Reactor *reactor) : - ACE_Event_Handler(), - mReactor(reactor == 0 ? ACE_Reactor::instance() : reactor), - mAcceptor() { - ACE_TRACE("AcceptHandler:: AcceptHandler(ACE_Reactor *)"); -} - -AcceptHandler::~AcceptHandler() { - ACE_TRACE("AcceptHandler::~AcceptHandler()"); -} - -int AcceptHandler::open(void) { - ACE_TRACE("AcceptHandler::open(void)"); - - // create the local address used for the service (PORT is from common.h) - ACE_INET_Addr addr(PORT); - - // open a port using the acceptor; reuse the address later - if (mAcceptor.open(addr, 1) == -1) - ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to open ") - ACE_TEXT ("listening socket. (errno = %i: %m)\n"), errno), -1); - - // register the handler with the reactor - if (mReactor->register_handler(this, - ACE_Event_Handler::ACCEPT_MASK) == -1) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to register accept ") - ACE_TEXT ("handler. (errno = %i: %m)\n"), errno)); - - // don't leave the acceptor open - if (mAcceptor.close() == -1) - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to close the socket ") - ACE_TEXT ("after previous error. (errno = %i: %m)\n"), - errno)); - return -1; - } - - return 0; -} - -ACE_HANDLE AcceptHandler::get_handle(void) const { - ACE_TRACE("AcceptHandler::get_handle(void)"); - return mAcceptor.get_handle(); -} - -int AcceptHandler::handle_input(ACE_HANDLE) { - ACE_TRACE("AcceptHandler::handle_input(ACE_HANDLE)"); - - ACE_INET_Addr clientAddr; - - // create a new ReadHandler - ReadHandler *reader = 0; - ACE_NEW_NORETURN (reader, ReadHandler()); - if (reader == 0) - ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to allocate ") - ACE_TEXT ("reader. (errno = %i: %m)\n"), errno), -1); - - // put reader in an auto pointer so we can use ACE_ERROR_RETURN safely - auto_ptr<ReadHandler> pReader(reader); - - // accept the connection using the reader's stream - if (mAcceptor.accept(reader->getStream(), &clientAddr) == -1) - ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to accept ") - ACE_TEXT ("client connection. (errno = %i: %m)\n"), errno), -1); - - // register the reader with the reactor - if (mReactor->register_handler(reader, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to register ") - ACE_TEXT ("read handler. (errno = %i: %m)\n"), errno), -1); - - // from now on the read handler takes care of itself - pReader.release(); - - return 0; // keep going -} - -int AcceptHandler::handle_close(ACE_HANDLE, ACE_Reactor_Mask) { - ACE_TRACE("AcceptHandler::handle_close(ACE_HANDLE, ACE_Reactor_Mask)"); - - // close the listening socket - if (mAcceptor.close() == -1) - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to close the ") - ACE_TEXT ("socket. (errno = %i: %m)\n"), errno)); - - // no need to distinguish between error during close and normal close - // since ACE does not evaluate the return value of handle_close() - - delete this; - return 0; -} - diff --git a/ACE/examples/Reactor/TP_Reactor/AcceptHandler.h b/ACE/examples/Reactor/TP_Reactor/AcceptHandler.h deleted file mode 100644 index 036f7a36f5a..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/AcceptHandler.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * ACE reactor demonstration - * - * $Id$ - * Date: 26-Jan-2006 - */ - -#ifndef __ACCEPTHANDLER_H__ -#define __ACCEPTHANDLER_H__ - -#include <ace/Event_Handler.h> -#include <ace/Reactor.h> -#include <ace/SOCK_Acceptor.h> - -/** - * This accept handler is based on the provided solution from the ACE course. - */ -class AcceptHandler : public ACE_Event_Handler { - - private: - - /** - * The reactor to which the accept handler belongs. - */ - ACE_Reactor *mReactor; - - /** - * The socket used for incoming conections. - */ - ACE_SOCK_Acceptor mAcceptor; - - public: - - /** - * @param reactor The reactor which will use this accept handler. - */ - AcceptHandler(ACE_Reactor *reactor = 0); - - /** - * The destructor exists for tracing purposes. - */ - virtual ~AcceptHandler(); - - /** - * Open the listening socket and register the handler with the reactor. - * - * @return 0 on success, -1 on failure - */ - int open(void); - - /** - * @name Overridden methods from the ACE_Event_Handler - */ - // @{ - - /** - * Provides the handle of mAcceptor. - */ - virtual ACE_HANDLE get_handle(void) const; - - /** - * Create a read handler for the new connection and register that - * handler with the reactor. - */ - virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE); - - /** - * Close the listening socket. - */ - virtual int handle_close(ACE_HANDLE, ACE_Reactor_Mask); - // @} -}; - -#endif /* __ACCEPTHANDLER_H__ */ - diff --git a/ACE/examples/Reactor/TP_Reactor/Makefile.am b/ACE/examples/Reactor/TP_Reactor/Makefile.am deleted file mode 100644 index 17eda0d0046..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/Makefile.am +++ /dev/null @@ -1,55 +0,0 @@ -## Process this file with automake to create Makefile.in -## -## $Id$ -## -## This file was generated by MPC. Any changes made directly to -## this file will be lost the next time it is generated. -## -## MPC Command: -## ./bin/mwc.pl -type automake -noreldefs ACE.mwc - -ACE_BUILDDIR = $(top_builddir) -ACE_ROOT = $(top_srcdir) - -## Makefile.TP_Reactor_Client.am - -noinst_PROGRAMS = client - -client_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -client_SOURCES = \ - client.cpp \ - AcceptHandler.h \ - ReadHandler.h \ - common.h - -client_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -## Makefile.TP_Reactor_Server.am - -noinst_PROGRAMS += server - -server_CPPFLAGS = \ - -I$(ACE_ROOT) \ - -I$(ACE_BUILDDIR) - -server_SOURCES = \ - AcceptHandler.cpp \ - ReadHandler.cpp \ - server.cpp \ - AcceptHandler.h \ - ReadHandler.h - -server_LDADD = \ - $(ACE_BUILDDIR)/ace/libACE.la - -## Clean up template repositories, etc. -clean-local: - -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* - -rm -f gcctemp.c gcctemp so_locations *.ics - -rm -rf cxx_repository ptrepository ti_files - -rm -rf templateregistry ir.out - -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/ACE/examples/Reactor/TP_Reactor/README b/ACE/examples/Reactor/TP_Reactor/README deleted file mode 100644 index 32fbc15aca9..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/README +++ /dev/null @@ -1,86 +0,0 @@ -ACE reactor demonstration -========================= - -Martin Kolleck -Tino Riethmuller - - - -1. Introduction - -This program demonstrates what we think is a bug in the ACE library. The -affected component is the ACE_TP_Reactor. According to the documentation, the -reactor ensures that only one of the handle_*() methods of an event handler is -called at a time. Tino found this to be not true and I wrote this example -program showing the behavior. I do not exclude the possibility that we are -using the ACE library in an unintended/wrong way. So comments on the code as -well as any other remarks are welcome. - - - -2. The program - -The program consists of a client and a server. The general implementation is -taken from the example solution to exercise 4c of the ACE course. The client -will send a request to the server. This request is interpreted to be the size -of the following data. The server allocates the memory required to hold the -client's data and then sends a confirmation to the client, that it may -proceed. The the client sends the large data chunk and the server again -confirms it. - -The client runs in a loop which can be configured to run indefinitely or a -previously set amount of times. The configuration i done from the command -line. To invoke the client type: - - $ ./client size [count] - -<size> sets the size (in MiB) of the buffer sent to the server. Depending on -the systems, values between 60 and 100 have been used for testing. <count> -determines how often the buffer is sent. If left out, the clients send the -buffer until interrupted. - -The server is started without arguments. Both programs will print a dot for -each successful connection. I found this an easy and unintrusive way of showing -progress whithout flooding the console too fast. This also makes it easier to -see when an error has occurred. - - - -3. Building the program - -This example was created on a Linux box. You will need the environment -variable ACE_ROOT set up to the location where ACE is installed. It might be -possible, that the path where the ACE libraries are found, needs to be adjusted -in the Makefile. - -To compile simply type 'make' on the command prompt. - - $ make - -This will create two executable files. One for the server and one for the -client. (named respectively) - - - -4. Running the program - -The error seems to be of statistical nature. Occurring only under certain -conditions (which I am not sure of, what they are). I successfully produced -the error on the four machines given below (architecture, ACE and compiler -version). I tested the program with localhost connections, as well as over -a real network connection and could always reproduce the error. - -To detect the error I introduced a member variable to the read event handler. -This counter is initialized to zero in the constructor. When handle_input() of -the event handler is called, the counter is increased and decreased, when -handle_input() returns. Before increasing the counter, It is compared to zero -(which it should alway be, if only one invocation to handle_input() is made -at a time) and an error message is printed if it is not zero. - -To test for the error, I ran one instance of the server program and TWO -instances of the client program. The sizes of the buffers were between 60 and -100 MiB and no count was given (running until stopped) The three Linux boxes -showed the error within one minute of starting both clients. For the Windows -box I decreased the buffer size to 15 and 20 MiB (Windows does not seem to have -very performant localhost connectivity) and it took about half an -hour until the error occurred the first time. diff --git a/ACE/examples/Reactor/TP_Reactor/ReadHandler.cpp b/ACE/examples/Reactor/TP_Reactor/ReadHandler.cpp deleted file mode 100644 index 25b66e05ade..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/ReadHandler.cpp +++ /dev/null @@ -1,152 +0,0 @@ -/* - * ACE reactor demonstration - * - * $Id$ - * Date: 26-Jan-2006 - */ - -#include "common.h" -#include "ReadHandler.h" - -#include <ace/streams.h> -#include <ace/Time_Value.h> -#include <ace/Log_Msg.h> - -/** - * This macro is used to increase the invocation counter by one when entering - * handle_input(). It also checks wether the counter is greater than zero - * indicating, that handle_input() has been called before. - */ -#define INVOCATION_ENTER() do { if (mInvocationCounter > 0) \ - ACE_ERROR((LM_ERROR, ACE_TEXT("Multiple invocations detected.\n"))); \ - mInvocationCounter++; } while (0) - -/** - * THis macro is the counter part to INVOCATION_ENTER(). It decreases the - * invocation counter and then returns the given value. This macro is - * here for convenience to decrease the invocation counter also when returning - * due to errors. - */ -#define INVOCATION_RETURN(retval) do { mInvocationCounter--; \ - return retval; } while(0) - -ReadHandler::ReadHandler() : ACE_Event_Handler(), mStream(), mDataSize(0), - mData(0), mCallCounter(0), mInvocationCounter(0) { - ACE_TRACE(ACE_TEXT("ReadHandler::ReadHandler()")); -} - -ReadHandler::~ReadHandler() { - ACE_TRACE(ACE_TEXT("ReadHandler::~ReadHandler()")); - - if (mStream.close() == -1) - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to close socket. ") - ACE_TEXT ("(errno = %i: %m)\n"), errno)); - - delete[] mData; -} - -ACE_SOCK_Stream &ReadHandler::getStream(void) { - ACE_TRACE(ACE_TEXT("ReadHandler::getStream(void)")); - return mStream; -} - -ACE_HANDLE ReadHandler::get_handle(void) const { - ACE_TRACE(ACE_TEXT("ReadHandler::get_handle(void)")); - return mStream.get_handle(); -} - -int ReadHandler::handle_input(ACE_HANDLE) { - ACE_TRACE(ACE_TEXT("ReadHandler::handle_input(ACE_HANDLE)")); - - INVOCATION_ENTER(); - - // the response sent to the client - char response = 0; - - if (mCallCounter == 0) { - - /* - * This is the first request from the client. - */ - - // increase the call counter so the next client request goes to else-if - mCallCounter++; - - // get the desired size from the client - // Note: only use the sizeof and pointer to int on compatible - // platforms (i.e. little-endian/big-endian, data type size) - if (mStream.recv_n(&mDataSize, sizeof(mDataSize), - &connTimeout) != sizeof(mDataSize)) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to receive ") - ACE_TEXT ("request. (errno = %i: %m)\n"), errno)); - INVOCATION_RETURN(-1); - } - - // The verbose debug output is replaced with some unintrusive dots. - // This increases visibility of the desired effect. - // ACE_DEBUG((LM_DEBUG, ACE_TEXT("%@: Data size: %i\n"), this, mDataSize)); - ACE_DEBUG((LM_DEBUG, ACE_TEXT("."))); - - // check mDataSize for plausability then allocate memory - if (mDataSize > 0) { - mData = new (std::nothrow) char[mDataSize]; - if (mData == 0) - ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l: Failed to allocate ") - ACE_TEXT ("data buffer.\n"))); - else - response = 'K'; - } - - // send the response to the client (which is still 0, if the - // allocation did not succeed) - if (mStream.send_n(&response, sizeof(response), &connTimeout) != 1) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to send ") - ACE_TEXT ("response. (errno = %i: %m)\n"), errno)); - INVOCATION_RETURN(-1); - } - - if (response == 'K') - INVOCATION_RETURN(0); // get another request from the same client - else - INVOCATION_RETURN(-1); // the client will not send data if response != 'K' - - } else if (mCallCounter == 1) { - - /* - * This is the second request from the client. - */ - - // increase the call counter, this read handler should not be called - // again - mCallCounter++; - - // receive the data from the client - if (mStream.recv_n(mData, mDataSize, &connTimeout) != mDataSize) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to receive data.") - ACE_TEXT ("(errno = %i: %m)\n"), errno)); - INVOCATION_RETURN(-1); - } - - response = 'K'; - - if (mStream.send_n(&response, 1, &connTimeout) != 1) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to send ") - ACE_TEXT ("confirmation. (errno = %i: %m)\n"), errno)); - INVOCATION_RETURN(-1); - } - - INVOCATION_RETURN(-1); // ask for removal, since client does not send any more data - } - - // this is to find strange actions with the call counter - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: We should not get here."))); - INVOCATION_RETURN(-1); -} - -int ReadHandler::handle_close(ACE_HANDLE, ACE_Reactor_Mask) { - ACE_TRACE("ReadHandler::handle_close(ACE_HANDLE, ACE_Reactor_Mask)"); - - delete this; - return 0; -} - diff --git a/ACE/examples/Reactor/TP_Reactor/ReadHandler.h b/ACE/examples/Reactor/TP_Reactor/ReadHandler.h deleted file mode 100644 index 41d58b6008a..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/ReadHandler.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * ACE reactor demonstration - * - * $Id$ - * Date: 26-Jan-2006 - */ - -#ifndef __READHANDLER_H__ -#define __READHANDLER_H__ - -#include <ace/Event_Handler.h> -#include <ace/SOCK_Stream.h> - -/** - * This read handler is created by the accept handler and handles all the data - * exchange between client and server. The client makes two requests to the - * server. The first asks the server to create a buffer which will hold the - * data sent in the second call. - */ -class ReadHandler : public ACE_Event_Handler { - - private: - - /** - * The stream socket used for data exchange. - */ - ACE_SOCK_Stream mStream; - - /** - * The size of the data array. - */ - int mDataSize; - - /** - * The array containing the client's data. - */ - char *mData; - - /** - * The call counter to distinguish between first and second call. - */ - int mCallCounter; - - /** - * Count the numer of invocations of handle_*(). According to the - * docs, there should be only one invocation at any given time. - */ - int mInvocationCounter; - - public: - - /** - * Initialization. - */ - ReadHandler(void); - - /** - * Clean up data. - */ - virtual ~ReadHandler(); - - /** - * Provide access to the internal stream socket. - */ - ACE_SOCK_Stream &getStream(void); - - /** - * @name Overridden methods from the ACE_Event_Handler - */ - // @{ - - /** - * Provides the handle of mStream; - */ - virtual ACE_HANDLE get_handle(void) const; - - /** - * Handles the data excahnge between client and server. On the first - * invocation, mData is allocated to the requested size and on the - * second invocation, that buffer is filled with the client's data. - */ - virtual int handle_input(ACE_HANDLE = ACE_INVALID_HANDLE); - - /** - * Deletes this instance of the read handler. - */ - virtual int handle_close(ACE_HANDLE, ACE_Reactor_Mask); - // @} -}; - -#endif /* __READHANDLER_H__ */ - diff --git a/ACE/examples/Reactor/TP_Reactor/TP_Reactor.mpc b/ACE/examples/Reactor/TP_Reactor/TP_Reactor.mpc deleted file mode 100644 index 03d8de2e7aa..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/TP_Reactor.mpc +++ /dev/null @@ -1,18 +0,0 @@ -// -*- MPC -*- -// $Id$ - -project (*client) : aceexe { - exename = client - Source_Files { - client.cpp - } -} - -project (*server) : aceexe { - exename = server - Source_Files { - server.cpp - AcceptHandler.cpp - ReadHandler.cpp - } -} diff --git a/ACE/examples/Reactor/TP_Reactor/client.cpp b/ACE/examples/Reactor/TP_Reactor/client.cpp deleted file mode 100644 index c7ef4f2e431..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/client.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * ACE reactor demonstration - * - * $Id$ - * Date: 26-Jan-2006 - */ - -#include <ace/Auto_Ptr.h> -#include <ace/INET_Addr.h> -#include <ace/Log_Msg.h> -#include <ace/OS.h> -#include <ace/SOCK_Acceptor.h> -#include <ace/SOCK_Connector.h> -#include <ace/SOCK_Stream.h> -#include <ace/streams.h> - -#include "common.h" - -/** - * Print usage information for the client. - * - * @param arg The progams name (argv[0]). - */ -int printUsage(ACE_TCHAR *arg) { - cerr << "Usage: " << arg << " size [count]" << endl; - cerr << "\tSends <size> MiB to the server and optionally repeats that " - << "<count> times." << endl; - cerr << "\tAll arguments must be positive numbers. If no <count> is " - << "given, the\n\tclient runs until interrupted." << endl; - return -1; -} - -int ACE_TMAIN(int argc, ACE_TCHAR **argv) { - - // size and count for transmissions - int size = 0, count = -1; - - // the server's answer is a single byte - char answer; - - // parse the <size> argument - if ((argc < 2) || (((size = ACE_OS::strtol(argv[1], 0, 10)) < 1) || - (errno == EINVAL))) - return printUsage(argv[0]); - - // take size as the number of MiB and create appropriate buffer - size *= BASE; - char *someData = new (std::nothrow) char[size]; - - if (someData == 0) - ACE_ERROR_RETURN ((LM_ERROR, - ACE_TEXT ("%N:%l: Failed to allocate ") - ACE_TEXT ("data buffer.\n")), -1); - - // put someData in an auto_ptr so it gets deleted automatically - auto_ptr<char> pSomeData(someData); - - // parse the <count> argument if available - if ((argc == 3) && (((count = ACE_OS::strtol(argv[2], 0, 10)) < 1) || - (errno == EINVAL))) - return printUsage(argv[0]); - - // the server listens on localhost on default port (from common.h) - ACE_INET_Addr serverAddr(PORT, "localhost"); - - ACE_SOCK_Stream stream; - ACE_SOCK_Connector connector; - - // -1 is running indefinitely - while ((count == -1) || (count-- != 0)) { - - // some output, that we know something is happening - //ACE_DEBUG((LM_DEBUG, ACE_TEXT("%N:%l: Passes left: %i\n"), count)); - ACE_DEBUG((LM_DEBUG, ACE_TEXT("."))); - - // connect to the server and get the stream - if (connector.connect(stream, serverAddr) == -1) { - ACE_ERROR((LM_ERROR, - ACE_TEXT("%N:%l: Failed to connect to ") - ACE_TEXT ("server. (errno = %i: %m)\n"), errno)); - break; - } - - try { - - // send the request to the server (number of MiB in the next call) - // Note: only use the sizeof and pointer to int on compatible - // platforms (i.e. little-endian/big-endian, data type size) - if (stream.send_n(&size, sizeof(size), &connTimeout) != sizeof(size)) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to send ") - ACE_TEXT ("request. (errno = %i: %m)\n"), errno)); - throw 1; - } - - // receive the answer - if (stream.recv_n(&answer, sizeof(answer), &connTimeout) != 1) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N: %l: Failed to receive ") - ACE_TEXT ("1st response. (errno = %i: %m)\n"), errno)); - throw 1; - } - - // server answer, 'K" indicates a positive answer - if (answer == 'K') { - - // send a huge message to the server - if (stream.send_n(someData, size, &connTimeout) != size) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to send ") - ACE_TEXT ("someData. (errno = %i: %m)\n"), errno)); - throw 1; - } - - // get an answer - if (stream.recv_n(&answer, sizeof(answer), &connTimeout) != 1) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N: %l: Failed to receive ") - ACE_TEXT ("2nd response. (errno = %i: %m)\n"), errno)); - throw 1; - } - - // check the answer - if (answer != 'K') { - cout << "The server was unable to process the data." - << endl; - } - } - } catch (...) { - // ok we know an error occurred, we need to close the socket. - // The we'll try again. - } - - // close the current stream - if (stream.close() == -1) { - ACE_ERROR((LM_ERROR, ACE_TEXT("%N:%l: Failed to close ") - ACE_TEXT ("socket. (errno = %i: %m)\n"), errno)); - break; - } - } // while - - cout << "Bye. Bye" << endl; - return 0; -} - diff --git a/ACE/examples/Reactor/TP_Reactor/common.h b/ACE/examples/Reactor/TP_Reactor/common.h deleted file mode 100644 index c9661027923..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/common.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * ACE reactor demonstration - * - * $Id$ - * Date: 26-Jan-2006 - */ - -#ifndef __COMMON_H__ -#define __COMMON_H__ - -#include <ace/Time_Value.h> - -/** - * The port number used by client and server. - */ -static const int PORT = 4711; - -/** - * The base size. 0x100000 = 1 MiB - */ -static const int BASE = 0x100000; - -/** - * The timeout value for connections. (30 seconds) - */ -static const ACE_Time_Value connTimeout(30); - -#endif /* __COMMON_H__ */ - diff --git a/ACE/examples/Reactor/TP_Reactor/run_test.pl b/ACE/examples/Reactor/TP_Reactor/run_test.pl deleted file mode 100644 index ac07295a735..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/run_test.pl +++ /dev/null @@ -1,41 +0,0 @@ -eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' - & eval 'exec perl -S $0 $argv:q' - if 0; - -# $Id$ -# -*- perl -*- - -use lib '../../../bin'; -use PerlACE::Run_Test; - -$status = 0; - -$SV = new PerlACE::Process ("server", ""); -$CL1 = new PerlACE::Process ("client", "80 100"); -$CL2 = new PerlACE::Process ("client", "80 100"); -$SV->Spawn (); - -sleep (1); - -$client1 = $CL1->Spawn (); - -if ($client1 != 0) { - print STDERR "ERROR: client 1 returned $client1\n"; - $status = 1; -} - -$client2 = $CL2->Spawn (); - -if ($client2 != 0) { - print STDERR "ERROR: client 2 returned $client2\n"; - $status = 1; -} - -$server = $SV->WaitKill (1000); - -if ($server != 0) { - print STDERR "ERROR: server returned $server\n"; - $status = 1; -} - -exit $status; diff --git a/ACE/examples/Reactor/TP_Reactor/server.cpp b/ACE/examples/Reactor/TP_Reactor/server.cpp deleted file mode 100644 index 0c147818424..00000000000 --- a/ACE/examples/Reactor/TP_Reactor/server.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * ACE reactor demonstration - * - * $Id$ - * Date: 26-Jan-2006 - */ - -#include <ace/Event_Handler.h> -#include <ace/Log_Msg.h> -#include <ace/OS.h> -#include <ace/Reactor.h> -#include <ace/Signal.h> -#include <ace/streams.h> -#include <ace/Thread_Manager.h> -#include <ace/TP_Reactor.h> - -#include "AcceptHandler.h" - -/** - * This is the function run by all threads in the thread pool. - * - * @param arg is expected to be of type (ACE_Reactor *) - */ -ACE_THR_FUNC_RETURN threadFunc(void *arg) { - ACE_TRACE("threadFunc(void *)"); - - ACE_Reactor *reactor = (ACE_Reactor *) arg; - reactor->run_reactor_event_loop(); - - return 0; -} - -/** - * The main function sets up the TP reactor. The code is basically taken from - * the solution to exercise 4c of the ACE course. - */ -int ACE_TMAIN(int, ACE_TCHAR **) { - - // create a reactor from a TP reactor - ACE_TP_Reactor tpReactor; - ACE_Reactor reactor(&tpReactor); - - // create a new accept handler using that reactor - AcceptHandler *acceptHandler = 0; - ACE_NEW_NORETURN (acceptHandler, AcceptHandler(&reactor)); - if (acceptHandler == 0) - ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to allocate ") - ACE_TEXT ("accept handler. (errno = %i: %m)\n"), errno), -1); - - // open the accept handler - if (acceptHandler->open() == -1) { - delete acceptHandler; - ACE_ERROR_RETURN((LM_ERROR, ACE_TEXT("%N:%l: Failed to open accept ") - ACE_TEXT ("handler. Exiting.\n")), -1); - } - - // spawn some threads which run the reactor event loop(s) - ACE_Thread_Manager::instance()->spawn_n(9, threadFunc, &reactor); - - // let the thread manager wait for all threads - ACE_Thread_Manager::instance()->wait(); - - ACE_DEBUG((LM_DEBUG, ACE_TEXT("Bye. Bye.\n"))); - return 0; -} - |