diff options
Diffstat (limited to 'docs/tutorials/Chap_6/ex05.html')
-rw-r--r-- | docs/tutorials/Chap_6/ex05.html | 130 |
1 files changed, 0 insertions, 130 deletions
diff --git a/docs/tutorials/Chap_6/ex05.html b/docs/tutorials/Chap_6/ex05.html deleted file mode 100644 index 9763486a71f..00000000000 --- a/docs/tutorials/Chap_6/ex05.html +++ /dev/null @@ -1,130 +0,0 @@ -<HTML> -<!-- $Id$ --> -<HEAD> - <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> - <META NAME="Author" CONTENT="Ambreen Ilyas"> - <META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (X11; I; SunOS 5.5.1 sun4u) [Netscape]"> - <TITLE>Example 5</TITLE> -</HEAD> -<BODY> -<FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> -<BR><FONT COLOR="#CC0000">//// This example is from the ACE Programmers -Guide.</FONT> -<BR><FONT COLOR="#CC0000">//// Chapter: "The Acceptor/Connector" -(Connection Initialization)</FONT> -<BR><FONT COLOR="#CC0000">//// For details please see the guide at</FONT> -<BR><FONT COLOR="#CC0000">//// http://www.cs.wustl.edu/~schmidt/ACE.html</FONT> -<BR><FONT COLOR="#CC0000">//// AUTHOR: Umar Syyid (usyyid@hns.com)</FONT> -<BR><FONT COLOR="#CC0000">//// and Ambreen Ilyas (ambreen@bitsmart.com)</FONT> -<BR><FONT COLOR="#CC0000">/////////////////////////////////////////////////////////////////////////////////////////////////////////////</FONT> - -<P><FONT COLOR="#CC0000">//Example 5</FONT> -<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Reactor.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Svc_Handler.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> "<FONT COLOR="#006600">ace/Acceptor.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Synch.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/SOCK_Acceptor.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Thread.h"</FONT> - -<P><FONT COLOR="#FF0000">//Add our own Reactor singleton</FONT> -<BR>typedef ACE_Singleton<ACE_Reactor,ACE_Null_Mutex> Reactor; -<BR><FONT COLOR="#FF0000">//Create an Acceptor</FONT> -<BR>typedef ACE_Acceptor<MyServiceHandler,ACE_SOCK_ACCEPTOR> Acceptor; -<BR><FONT COLOR="#FF0000">//Create a Connector</FONT> -<BR>typedef ACE_Connector<MyServiceHandler,ACE_SOCK_CONNECTOR> Connector; - -<P>class MyServiceHandler: -<BR>public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ -<BR>public: -<BR><FONT COLOR="#FF0000"> //Used by the two threads "globally" to -determine their peer stream</FONT> -<BR> static ACE_SOCK_Stream* Peer; - -<P><FONT COLOR="#FF0000">//Thread ID used to identify the threads</FONT> -<BR> ACE_thread_t t_id; - -<P>int open(void*){ -<BR> ACE_DEBUG((LM_DEBUG,"Acceptor: received new connection\n")); - -<P><FONT COLOR="#FF0000">//Register with the reactor to remember this handlle</FONT> -<BR> Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); - -<P><FONT COLOR="#FF0000">//Determine the peer stream and record it globally</FONT> -<BR> MyServiceHandler::Peer=&peer(); -<BR> -<BR> <FONT COLOR="#FF0000">//Spawn new thread to send string every -second</FONT> -<BR> ACE_Thread::spawn((ACE_THR_FUNC)send_data,0,THR_NEW_LWP,&t_id); -<BR> -<BR> <FONT COLOR="#FF0000"> //keep the service handler registered -by returning 0 to the reactor</FONT> -<BR> return 0; -<BR> } -<BR> - -<P>static void* send_data(void*){ -<BR> while(1){ -<BR> ACE_DEBUG((LM_DEBUG,"Hello World\n")); -<BR> Peer->send_n("Hello World",sizeof("Hello World")); -<BR> -<BR> <FONT COLOR="#FF0000">//Go to sleep for a second before -sending again</FONT> -<BR> ACE_OS::sleep(1); -<BR> } -<BR> return 0; -<BR> } -<BR> - -<P>int handle_input(ACE_HANDLE){ -<BR> char* data= new char[12]; -<BR> -<BR> <FONT COLOR="#FF0000"> //Check if peer aborted the connection</FONT> -<BR> if(Peer.recv_n(data,12)==0){ -<BR> ACE_DEBUG((LM_DEBUG,"Peer probably aborted connection\n")); -<BR> ACE_Thread::cancel(t_id); <FONT COLOR="#CC0000">//kill -sending thread ..</FONT> -<BR> return -1; <FONT COLOR="#FF0000">//de-register from the -Reactor.</FONT> -<BR> } - -<P> <FONT COLOR="#FF0000"> //Show what you got..</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"<< %s\n",data)); -<BR> -<BR> <FONT COLOR="#FF0000">//keep yourself registered</FONT> -<BR> return 0; -<BR> } -<BR>}; - -<P><FONT COLOR="#FF0000">//Global stream identifier used by both threads</FONT> -<BR>ACE_SOCK_Stream * MyServiceHandler::Peer=0; -<BR> - -<P>void main_accept(){ -<BR> ACE_INET_Addr addr(PORT_NO); -<BR> Acceptor myacceptor(addr,Reactor::instance()); -<BR> while(1) -<BR> Reactor::instance()->handle_events(); - -<P> return 0; -<BR> } - -<P>void main_connect(){ -<BR> ACE_INET_Addr addr(PORT_NO,HOSTNAME); -<BR> Connector myconnector; -<BR> myconnector.connect(my_svc_handler,addr); -<BR> while(1) -<BR> Reactor::instance()->handle_events(); - -<P> } -<BR> - -<P>int main(int argc, char* argv[]){ -<BR><FONT COLOR="#FF0000"> // Use ACE_Get_Opt to parse and obtain -arguments and then call the</FONT> -<BR> <FONT COLOR="#FF0000">// approriate function for accept or connect.</FONT> -<BR><FONT COLOR="#CC0000">//...</FONT> -<BR>} -<BR> -<BR> <A HREF="ex06.html">Next Example</A> -</BODY> -</HTML> |