diff options
Diffstat (limited to 'docs/tutorials/Chap_6/ex06.html')
-rw-r--r-- | docs/tutorials/Chap_6/ex06.html | 135 |
1 files changed, 0 insertions, 135 deletions
diff --git a/docs/tutorials/Chap_6/ex06.html b/docs/tutorials/Chap_6/ex06.html deleted file mode 100644 index 9c6fd395d52..00000000000 --- a/docs/tutorials/Chap_6/ex06.html +++ /dev/null @@ -1,135 +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 6</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 6</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> - -<P>class MyServiceHandler; //forward declaration -<BR>typedef ACE_Singleton<ACE_Reactor,ACE_Null_Mutex> Reactor; -<BR>typedef ACE_Acceptor<MyServiceHandler,ACE_SOCK_ACCEPTOR> Acceptor; - -<P>class MyServiceHandler: -<BR>public ACE_Svc_Handler<ACE_SOCK_STREAM,ACE_MT_SYNCH>{ -<BR><FONT COLOR="#FF0000">// The two thread names are kept here</FONT> -<BR>ACE_thread_t thread_names[2]; - -<P>public: -<BR>int open(void*){ -<BR> ACE_DEBUG((LM_DEBUG, "Acceptor: received new connection \n")); -<BR> -<BR> <FONT COLOR="#FF0000">//Register with the reactor to remember -this handler..</FONT> -<BR> Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); -<BR> ACE_DEBUG((LM_DEBUG,"Acceptor: ThreadID:(%t) open\n")); - -<P><FONT COLOR="#CC0000"> //Create two new threads to create and send -messages to the remote machine.</FONT> -<BR> activate(THR_NEW_LWP, -<BR> 2, <FONT COLOR="#FF0000">//2 new threads</FONT> -<BR> 0, <FONT COLOR="#FF0000">//force active false, if already -created dont try again.</FONT> -<BR> ACE_DEFAULT_THREAD_PRIORITY,<FONT COLOR="#FF0000">//Use -default thread priority</FONT> -<BR> -1, -<BR> this,<FONT COLOR="#FF0000">//Which ACE_Task object to -create? In this case this one.</FONT> -<BR> 0,<FONT COLOR="#FF0000">// dont care about thread handles -used</FONT> -<BR> 0,<FONT COLOR="#FF0000">// dont care about where stacks -are created</FONT> -<BR> 0,<FONT COLOR="#FF0000">//dont care about stack sizes</FONT> -<BR> thread_names); <FONT COLOR="#FF0000">// keep identifiers -in thread_names</FONT> -<BR> -<BR><FONT COLOR="#FF0000"> //keep the service handler registered with -the acceptor.</FONT> -<BR> return 0; -<BR> } - -<P>void send_message1(void){ -<BR> <FONT COLOR="#FF0000">//Send message type 1</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"(%t)Sending message >>")); - -<P> <FONT COLOR="#FF0000">//Send the data to the remote peer</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"Sent message1")); -<BR> peer().send_n("Message1",LENGTH_MSG_1); -<BR> } <FONT COLOR="#FF0000">//end send_message1</FONT> - -<P>int send_message2(void){ -<BR> <FONT COLOR="#FF0000">//Send message type 1</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"(%t)Sending message >>")); - -<P> <FONT COLOR="#FF0000">//Send the data to the remote peer</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"Sent Message2")); -<BR> peer().send_n("Message2",LENGTH_MSG_2); -<BR> }<FONT COLOR="#FF0000">//end send_message_2</FONT> -<BR> -<BR>int svc(void){ -<BR> ACE_DEBUG( (LM_DEBUG,?(%t) Svc thread \n?)); -<BR> -<BR> if(ACE_Thread::self()== thread_names[0]) -<BR> while(1) send_message1(); <FONT COLOR="#FF0000">//send message -1s forever</FONT> -<BR> else -<BR> while(1) send_message2(); <FONT COLOR="#FF0000">//send message -2s forever</FONT> -<BR> return 0; <FONT COLOR="#FF0000">// keep the compiler happy.</FONT> -<BR>} -<BR> -<BR>int handle_input(ACE_HANDLE){ -<BR> ACE_DEBUG((LM_DEBUG,?(%t) handle_input ::?)); -<BR> char* data= new char[13]; -<BR> -<BR> <FONT COLOR="#FF0000">//Check if peer aborted the connection</FONT> -<BR> if(peer().recv_n(data,12)==0){ -<BR> ACE_OS::printf("Peer probably aborted connection\n"); -<BR> return -1; <FONT COLOR="#FF0000">//de-register from the Reactor.</FONT> -<BR> } -<BR> -<BR> <FONT COLOR="#FF0000">//Show what you got..</FONT> -<BR> ACE_OS::printf("<< %s\n",data); -<BR> -<BR> <FONT COLOR="#FF0000">//keep yourself registered</FONT> -<BR> return 0; -<BR> -<BR> } -<BR>}; - -<P>int main(int argc, char* argv[]){ -<BR> ACE_INET_Addr addr(10101); -<BR> ACE_DEBUG((LM_DEBUG,"Thread: (%t) main\n")); - -<P> <FONT COLOR="#FF0000">//Prepare to accept connections</FONT> -<BR> Acceptor myacceptor(addr,Reactor::instance()); - -<P><FONT COLOR="#FF0000"> // wait for something to happen.</FONT> -<BR> while(1) -<BR> Reactor::instance()->handle_events(); -<BR> -<BR> return 0; -<BR>} - -<P> <A HREF="ex07.html">Next Example</A> -</BODY> -</HTML> |