diff options
author | jcej <jcej@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-10-06 17:50:03 +0000 |
---|---|---|
committer | jcej <jcej@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-10-06 17:50:03 +0000 |
commit | 2440eaf8dc2b9b27e4a2de31a8fb9e1d9aea9b42 (patch) | |
tree | 44c256127e1896251b35daa154c241169f9e811b | |
parent | 29869f8ec1afd3a7d56106c41b5d70481294874a (diff) | |
download | ATCD-2440eaf8dc2b9b27e4a2de31a8fb9e1d9aea9b42.tar.gz |
*** empty log message ***
-rw-r--r-- | ChangeLog-98b | 11 | ||||
-rw-r--r-- | docs/tutorials/006/client_handler.cpp | 12 | ||||
-rw-r--r-- | docs/tutorials/006/page05.html | 95 |
3 files changed, 74 insertions, 44 deletions
diff --git a/ChangeLog-98b b/ChangeLog-98b index 502b504fbbe..e2a222c9352 100644 --- a/ChangeLog-98b +++ b/ChangeLog-98b @@ -1,3 +1,14 @@ +Tue Oct 6 12:49:37 EDT 1998 James CE Johnson <jcej@lads.com> + + * docs/tutorials/006/client_handler.cpp + * docs/tutorials/006/page05.html + Susan Liebeskind discovered that invoking the baseclass + close() after handle_close() in Client_Handler::close() + causes the object to be destructed twice. I've removed + the call to the baseclass close(). She reports success + on Solaris, Dec and AIX. I've verified that Linux also + works fine with this fix. + Tue Oct 06 09:53:22 1998 David L. Levine <levine@cs.wustl.edu> * ace/config-fsu-pthread.h,config-mit-pthread.h,config-mvs.h, diff --git a/docs/tutorials/006/client_handler.cpp b/docs/tutorials/006/client_handler.cpp index d9dd2867c8a..16fd098f12c 100644 --- a/docs/tutorials/006/client_handler.cpp +++ b/docs/tutorials/006/client_handler.cpp @@ -172,13 +172,19 @@ int Client_Handler::open (void *_acceptor) */ int Client_Handler::close(u_long flags) { + /* + Down in the depths of our baseclass, this will eventually cause us + to be destroyed. Since all of the destructors are virtual, everything + gets cleaned up nicely. + */ this->handle_close(ACE_INVALID_HANDLE,0); /* - After we've taken care of ourselves, call the baseclass method - to do any other necessary cleanup. + Don't forward the close() to the baseclass! handle_close() above has + already taken care of delete'ing. Forwarding close() would cause that + to happen again and things would get really ugly at that point! */ - return inherited::close(); + return 0; } /* diff --git a/docs/tutorials/006/page05.html b/docs/tutorials/006/page05.html index 2b79e79c7b9..5f8bedf16d9 100644 --- a/docs/tutorials/006/page05.html +++ b/docs/tutorials/006/page05.html @@ -1,7 +1,7 @@ <HTML> <HEAD> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="GENERATOR" CONTENT="Mozilla/4.04 [en] (X11; I; Linux 2.0.32 i486) [Netscape]"> + <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (WinNT; I) [Netscape]"> <META NAME="Author" CONTENT="James CE Johnson"> <META NAME="Description" CONTENT="A first step towards using ACE productively"> <TITLE>ACE Tutorial 006</TITLE> @@ -16,22 +16,22 @@ <P> <HR WIDTH="100%"> -<P><A HREF="client_handler.cpp">client_handler.cpp</A> -exposes all the things I've been hinting at. Pay special attention -to the decision made in open() as well as the bit of cleverness in svc(). +<P><A HREF="client_handler.cpp">client_handler.cpp</A> exposes all the +things I've been hinting at. Pay special attention to the decision +made in open() as well as the bit of cleverness in svc(). <P> <HR WIDTH="100%"> <P><FONT FACE="Arial,Helvetica">// $Id: client_handler.cpp,v 1.1 1998/08/30 -23:47:13 schmidt Exp $</FONT><FONT FACE="Arial,Helvetica"></FONT> +23:47:13 schmidt Exp $</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> In client_handler.h I alluded to the fact that we'll mess around with a</FONT> <BR><FONT FACE="Arial,Helvetica"> Client_Acceptor pointer. To do so, we need the Client_Acceptor object</FONT> -<BR><FONT FACE="Arial,Helvetica"> declaration.</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> declaration.</FONT> <P><FONT FACE="Arial,Helvetica"> We know that including client_handler.h is redundant because</FONT> @@ -39,13 +39,13 @@ is redundant because</FONT> it. Still, the sentry prevents double-inclusion</FONT> <BR><FONT FACE="Arial,Helvetica"> from causing problems and it's sometimes good to be explicit about what</FONT> -<BR><FONT FACE="Arial,Helvetica"> we're using.</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> we're using.</FONT> <P><FONT FACE="Arial,Helvetica"> On the other hand, we don't directly include any ACE header files here.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica">#include "client_acceptor.h"</FONT> -<BR><FONT FACE="Arial,Helvetica">#include "client_handler.h"</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">#include "client_handler.h"</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> Our constructor doesn't do @@ -60,7 +60,7 @@ would cause new to return 0 if I failed. Oh</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica">Client_Handler::Client_Handler (void)</FONT> <BR><FONT FACE="Arial,Helvetica">{</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> Our destructor doesn't do @@ -72,7 +72,7 @@ left to do when the destructor gets invoked.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica">Client_Handler::~Client_Handler (void)</FONT> <BR><FONT FACE="Arial,Helvetica">{</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> The much talked about destroy() @@ -97,7 +97,7 @@ probably already closed. Still... there are other ways to</FONT> <BR><FONT FACE="Arial,Helvetica"> get here and closing a closed peer doesn't hurt.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> -<BR><FONT FACE="Arial,Helvetica"> this->peer ().close ();</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> this->peer ().close ();</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Tell the reactor @@ -113,7 +113,7 @@ due to handle_close(), that could cause a bit of nasty</FONT> <BR><FONT FACE="Arial,Helvetica"> this->reactor ()->remove_handler (this,</FONT> <BR><FONT FACE="Arial,Helvetica"> -ACE_Event_Handler:: READ_MASK | ACE_Event_Handler::DONT_CALL);</FONT><FONT FACE="Arial,Helvetica"></FONT> +ACE_Event_Handler:: READ_MASK | ACE_Event_Handler::DONT_CALL);</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> This is how we're @@ -124,7 +124,7 @@ own instance, we take care of memory leaks after ensuring</FONT> is shut down correctly.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> delete this;</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> As mentioned before, the @@ -143,7 +143,7 @@ to store the address of the client that we are now connected</FONT> <BR><FONT FACE="Arial,Helvetica"> to. We'll use it later to display a debug message.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> -<BR><FONT FACE="Arial,Helvetica"> ACE_INET_Addr addr;</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> ACE_INET_Addr addr;</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Our ACE_Svc_Handler @@ -172,7 +172,7 @@ string representing the TCP/IP address.</FONT> <BR><FONT FACE="Arial,Helvetica"> {</FONT> <BR><FONT FACE="Arial,Helvetica"> return -1;</FONT> -<BR><FONT FACE="Arial,Helvetica"> }</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> }</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Convert the void* @@ -187,7 +187,7 @@ sure of what you're doing when you do this kind of thing.</FONT> the new-style cast operators can save you.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> Client_Acceptor *acceptor = (Client_Acceptor -*) _acceptor;</FONT><FONT FACE="Arial,Helvetica"></FONT> +*) _acceptor;</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Our Client_Acceptor @@ -197,7 +197,7 @@ to find out what that strategy was. If thread-per-connection</FONT> <BR><FONT FACE="Arial,Helvetica"> was selected then we simply activate a thread for ourselves and exit. Our</FONT> <BR><FONT FACE="Arial,Helvetica"> svc() method -will then begin executing in that thread.</FONT><FONT FACE="Arial,Helvetica"></FONT> +will then begin executing in that thread.</FONT> <P><FONT FACE="Arial,Helvetica"> If we are told to use the single-threaded strategy, there is no difference</FONT> @@ -208,7 +208,7 @@ and the Tutorial 5 implementation.</FONT> )</FONT> <BR><FONT FACE="Arial,Helvetica"> {</FONT> <BR><FONT FACE="Arial,Helvetica"> return this->activate();</FONT> -<BR><FONT FACE="Arial,Helvetica"> }</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> }</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Our reactor reference @@ -217,7 +217,7 @@ will be set when we register ourselves but I decided</FONT> set it here. No good reason really...</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> this->reactor (acceptor->reactor -());</FONT><FONT FACE="Arial,Helvetica"></FONT> +());</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> If we managed @@ -229,7 +229,7 @@ so quickly that it is invalid by the time we get here. In</FONT> <BR><FONT FACE="Arial,Helvetica"> any case, the test above should always be done to ensure that the</FONT> <BR><FONT FACE="Arial,Helvetica"> connection is -worth keeping.</FONT><FONT FACE="Arial,Helvetica"></FONT> +worth keeping.</FONT> <P><FONT FACE="Arial,Helvetica"> Now, regiser ourselves with a reactor and tell that reactor that we want</FONT> @@ -247,7 +247,7 @@ to do.</FONT> <BR><FONT FACE="Arial,Helvetica"> {</FONT> <BR><FONT FACE="Arial,Helvetica"> ACE_ERROR_RETURN ((LM_ERROR, "(%P|%t) can't register with reactor\n"), -1);</FONT> -<BR><FONT FACE="Arial,Helvetica"> }</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> }</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Here, we use @@ -261,14 +261,14 @@ other reason that a TCP/IP addreess cannot be converted</FONT> <BR><FONT FACE="Arial,Helvetica"> into a host name.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> ACE_DEBUG ((LM_DEBUG, "(%P|%t) -connected with %s\n", addr.get_host_name ()));</FONT><FONT FACE="Arial,Helvetica"></FONT> +connected with %s\n", addr.get_host_name ()));</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Always return zero on success.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> return 0;</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> As mentioned in the header, @@ -282,19 +282,33 @@ us, we'll just forward the request on to that</FONT> <BR><FONT FACE="Arial,Helvetica">int Client_Handler::close(u_long flags)</FONT> <BR><FONT FACE="Arial,Helvetica">{</FONT> <BR><FONT FACE="Arial,Helvetica"> +/*</FONT> +<BR><FONT FACE="Arial,Helvetica"> +Down in the depths of our baseclass, this will eventually cause us</FONT> +<BR><FONT FACE="Arial,Helvetica"> +to be destroyed. Since all of the destructors are virtual, everything</FONT> +<BR><FONT FACE="Arial,Helvetica"> +gets cleaned up nicely.</FONT> +<BR><FONT FACE="Arial,Helvetica"> +*/</FONT> +<BR><FONT FACE="Arial,Helvetica"> this->handle_close(ACE_INVALID_HANDLE,0);</FONT><FONT FACE="Arial,Helvetica"></FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> -After we've taken care of ourselves, call the baseclass method</FONT> +Don't forward the close() to the baseclass! handle_close() above +has</FONT> +<BR><FONT FACE="Arial,Helvetica"> +already taken care of delete'ing. Forwarding close() would cause +that</FONT> <BR><FONT FACE="Arial,Helvetica"> -to do any other necessary cleanup.</FONT> +to happen again and things would get really ugly at that point!</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> -return inherited::close();</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +return 0;</FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> In the open() method, we @@ -318,7 +332,7 @@ don't like it when you fail to use a parameter. This macro</FONT> <BR><FONT FACE="Arial,Helvetica"> will keep 'em quiet for you.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> -<BR><FONT FACE="Arial,Helvetica"> ACE_UNUSED_ARG (_handle);</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> ACE_UNUSED_ARG (_handle);</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Now, we create @@ -327,7 +341,7 @@ and initialize a buffer for receiving the data. Since this</FONT> test app, we'll use a small buffer size.</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> char buf[128];</FONT> -<BR><FONT FACE="Arial,Helvetica"> memset (buf, 0, sizeof (buf));</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> memset (buf, 0, sizeof (buf));</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> Invoke the process() @@ -344,7 +358,7 @@ It's best if we push that all into the application-logic</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> <BR><FONT FACE="Arial,Helvetica"> return this->process (buf, sizeof (buf));</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> If we return -1 out of handle_input() @@ -358,11 +372,11 @@ get rid of our instance.</FONT> _handle, ACE_Reactor_Mask _mask)</FONT> <BR><FONT FACE="Arial,Helvetica">{</FONT> <BR><FONT FACE="Arial,Helvetica"> ACE_UNUSED_ARG (_handle);</FONT> -<BR><FONT FACE="Arial,Helvetica"> ACE_UNUSED_ARG (_mask);</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> ACE_UNUSED_ARG (_mask);</FONT> <P><FONT FACE="Arial,Helvetica"> this->destroy ();</FONT> <BR><FONT FACE="Arial,Helvetica"> return 0;</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> The ACE_Svc_Handler<> @@ -386,7 +400,7 @@ here: the buffer is created once when the thread is created</FONT> <BR><FONT FACE="Arial,Helvetica"> instead of for each invocation of process().</FONT> <BR><FONT FACE="Arial,Helvetica"> */</FONT> -<BR><FONT FACE="Arial,Helvetica"> char buf[128];</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> char buf[128];</FONT> <P><FONT FACE="Arial,Helvetica"> // Forever...</FONT> <BR><FONT FACE="Arial,Helvetica"> while( 1 )</FONT> @@ -394,7 +408,7 @@ each invocation of process().</FONT> <BR><FONT FACE="Arial,Helvetica"> // Clean the buffer...</FONT> <BR><FONT FACE="Arial,Helvetica"> memset (buf, -0, sizeof (buf));</FONT><FONT FACE="Arial,Helvetica"></FONT> +0, sizeof (buf));</FONT> <P><FONT FACE="Arial,Helvetica"> /*</FONT> <BR><FONT FACE="Arial,Helvetica"> @@ -408,7 +422,7 @@ concurrency strategy. Since process() has all of our application-level</FO <BR><FONT FACE="Arial,Helvetica"> logic, it's nice that it doesn't have to change when we decide to go</FONT> <BR><FONT FACE="Arial,Helvetica"> -multi-threaded.</FONT><FONT FACE="Arial,Helvetica"></FONT> +multi-threaded.</FONT> <P><FONT FACE="Arial,Helvetica"> Notice that since the recv() method call in process() blocks until</FONT> @@ -422,10 +436,10 @@ there is actually data sent from the client.</FONT> <BR><FONT FACE="Arial,Helvetica"> {</FONT> <BR><FONT FACE="Arial,Helvetica"> return(-1);</FONT> <BR><FONT FACE="Arial,Helvetica"> }</FONT> -<BR><FONT FACE="Arial,Helvetica"> }</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> }</FONT> <P><FONT FACE="Arial,Helvetica"> return(0);</FONT> -<BR><FONT FACE="Arial,Helvetica">}</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica">}</FONT> <P><FONT FACE="Arial,Helvetica">/*</FONT> <BR><FONT FACE="Arial,Helvetica"> And, at last, we get to the @@ -455,7 +469,7 @@ has happened. The reactor wouldn't have called us if</FONT> <BR><FONT FACE="Arial,Helvetica"> there wasn't some kind of read activity but there wouldn't be activity if</FONT> <BR><FONT FACE="Arial,Helvetica"> there were no -bytes to read...</FONT><FONT FACE="Arial,Helvetica"></FONT> +bytes to read...</FONT> <P><FONT FACE="Arial,Helvetica"> On the other hand, if we got some data then we can display it in a debug</FONT> @@ -475,7 +489,7 @@ _rdbuf_len))</FONT> <BR><FONT FACE="Arial,Helvetica"> default:</FONT> <BR><FONT FACE="Arial,Helvetica"> ACE_DEBUG ((LM_DEBUG, "(%P|%t) from client: %s", _rdbuf));</FONT> -<BR><FONT FACE="Arial,Helvetica"> }</FONT><FONT FACE="Arial,Helvetica"></FONT> +<BR><FONT FACE="Arial,Helvetica"> }</FONT> <P><FONT FACE="Arial,Helvetica"> return 0;</FONT> <BR><FONT FACE="Arial,Helvetica">}</FONT> @@ -495,8 +509,7 @@ do. <P> <HR WIDTH="100%"> -<CENTER>[<A HREF="..">Tutorial -Index</A>] [<A HREF="page06.html">Continue +<CENTER>[<A HREF="..">Tutorial Index</A>] [<A HREF="page06.html">Continue This Tutorial</A>]</CENTER> </BODY> |