diff options
Diffstat (limited to 'docs/tutorials/Chap_6')
-rw-r--r-- | docs/tutorials/Chap_6/Chap_6.zip | bin | 14305 -> 0 bytes | |||
-rw-r--r-- | docs/tutorials/Chap_6/ex01.html | 81 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex02.html | 94 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex03.html | 50 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex04.html | 44 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex05.html | 129 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex06.html | 134 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex07.html | 173 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex08.html | 96 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex09.html | 211 | ||||
-rw-r--r-- | docs/tutorials/Chap_6/ex10.html | 110 |
11 files changed, 0 insertions, 1122 deletions
diff --git a/docs/tutorials/Chap_6/Chap_6.zip b/docs/tutorials/Chap_6/Chap_6.zip Binary files differdeleted file mode 100644 index fcfd5455cba..00000000000 --- a/docs/tutorials/Chap_6/Chap_6.zip +++ /dev/null diff --git a/docs/tutorials/Chap_6/ex01.html b/docs/tutorials/Chap_6/ex01.html deleted file mode 100644 index ff60ea6dcb7..00000000000 --- a/docs/tutorials/Chap_6/ex01.html +++ /dev/null @@ -1,81 +0,0 @@ -<HTML> -<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 1</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="#FF0000">//Example 1</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><FONT COLOR="#FF0000">//Create a Service Handler whose open() method -will be called back automatically.</FONT> -<BR><FONT COLOR="#FF0000">//This class MUST derive from ACE_Svc_Handler -which is an interface and</FONT> -<BR><FONT COLOR="#FF0000">//as can be seen is a template container class -itself. The first parameter to //ACE_Svc_Handler is the underlying stream -that it may use for communication.</FONT> -<BR><FONT COLOR="#FF0000">//Since we are using TCP sockets the stream is -ACE_SOCK_STREAM.</FONT> -<BR><FONT COLOR="#FF0000">//The second is the internal synchronization -mechanism it could use.</FONT> -<BR><FONT COLOR="#FF0000">//Since we have a single threaded application -we pass it a "null" lock</FONT> -<BR><FONT COLOR="#FF0000">//which will do nothing.</FONT> - -<P>class My_Svc_Handler: -<BR> public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ -<BR><FONT COLOR="#FF0000">//the open method which will be called back automatically -after the</FONT> -<BR><FONT COLOR="#FF0000">//connection has been established</FONT>. - -<P>public: -<BR>int open(void*){ -<BR> cout<<?Connection established?<<endl; -<BR> } -<BR>}; -<BR><FONT COLOR="#FF0000">// Create the acceptor as described above.</FONT> -<BR>typedef ACE_Acceptor<My_Svc_Handler,ACE_SOCK_ACCEPTOR> MyAcceptor; - -<P>int main(int argc, char* argv[]){ -<BR><FONT COLOR="#FF0000">//create the address on which we wish to -connect. The constructor takes</FONT> -<BR><FONT COLOR="#FF0000">//the port number on which to listen and will -automatically take the hosts</FONT> -<BR><FONT COLOR="#FF0000">//IP address as the IP Address for the addr object</FONT> - -<P>ACE_INET_Addr addr(PORT_NUM); - -<P><FONT COLOR="#FF0000">//instantiate the appropriate acceptor object -with the address on which we wish to</FONT> -<BR><FONT COLOR="#FF0000">//accept and the Reactor instance we want to -use. In this case we just use the global</FONT> -<BR><FONT COLOR="#FF0000">//ACE_Reactor singleton. (Read more about the -reactor in the previous chapter)</FONT> -<BR>MyAcceptor acceptor(address, ACE_Reactor::instance()); - -<P>while(1) -<BR><FONT COLOR="#FF0000"> // Start the reactors event loop</FONT> -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} - -<P> <A HREF="ex02.html">Next Example</A> -<BR> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex02.html b/docs/tutorials/Chap_6/ex02.html deleted file mode 100644 index a5ab4cca339..00000000000 --- a/docs/tutorials/Chap_6/ex02.html +++ /dev/null @@ -1,94 +0,0 @@ -<HTML> -<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 2</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 2</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">#define</FONT> <FONT COLOR="#663366">PORT_NUM -10101</FONT> -<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> DATA_SIZE -12</FONT> - -<P><FONT COLOR="#FF0000">//forward declaration</FONT> -<BR>class My_Svc_Handler; - -<P><FONT COLOR="#FF0000">//Create the Acceptor class</FONT> -<BR>typedef ACE_Acceptor<My_Svc_Handler,ACE_SOCK_ACCEPTOR> MyAcceptor; - -<P><FONT COLOR="#FF0000">//Create a service handler similar to as seen -in example 1.</FONT> -<BR><FONT COLOR="#FF0000">//Except this time include the handle_input() -method which will be</FONT> -<BR><FONT COLOR="#FF0000">//called back automatically by the reactor when -new data arrives</FONT> -<BR><FONT COLOR="#FF0000">//on the newly established connection</FONT> -<BR>class My_Svc_Handler: -<BR> public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ -<BR>public: -<BR>My_Svc_Handler(){ -<BR> data= new char[DATA_SIZE]; -<BR> } -<BR>int open(void*){ -<BR> ACE_DEBUG((LM_DEBUG,"Connection established")); - -<P><FONT COLOR="#FF0000"> //Register the service handler with the -reactor</FONT> -<BR> ACE_Reactor::instance()->register_handler(this, -<BR> ACE_Event_Handler::READ_MASK); -<BR> return 0; -<BR> } - -<P>int handle_input(ACE_HANDLE){ -<BR> <FONT COLOR="#FF0000">//After using the peer() method of ACE_Svc_Handler -to obtain a</FONT> -<BR><FONT COLOR="#FF0000">//reference to the underlying stream of the service -handler class</FONT> -<BR><FONT COLOR="#FF0000">//we call recv_n() on it to read the data which -has been received.</FONT> -<BR><FONT COLOR="#FF0000">//This data is stored in the data array and then -printed out</FONT> -<BR> peer().recv_n(data,DATA_SIZE); -<BR> ACE_OS::printf("<< %s\n",data); - -<P> <FONT COLOR="#FF0000">//keep yourself registered with the reactor</FONT> -<BR> return 0; -<BR> } -<BR>private: -<BR> char* data; -<BR>}; - -<P>int main(int argc, char* argv[]){ -<BR> ACE_INET_Addr addr(PORT_NUM); -<BR><FONT COLOR="#FF0000"> //create the acceptor</FONT> -<BR> MyAcceptor acceptor(addr, <FONT COLOR="#FF0000">//address to -accept on</FONT> -<BR> ACE_Reactor::instance()); <FONT COLOR="#FF0000">//the reactor -to use</FONT> - -<P>while(1) -<BR><FONT COLOR="#FF0000"> //Start the reactor?s event loop</FONT> -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} - -<P> <A HREF="ex03.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex03.html b/docs/tutorials/Chap_6/ex03.html deleted file mode 100644 index a68bd303b61..00000000000 --- a/docs/tutorials/Chap_6/ex03.html +++ /dev/null @@ -1,50 +0,0 @@ -<HTML> -<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 3</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">//Example3</FONT> - -<P>class My_Svc_Handler: -<BR>public ACE_Svc_Handler <ACE_LSOCK_STREAM,ACE_NULL_SYNCH>{ -<BR>public: -<BR>int open(void*){ -<BR> ACE_DEBUG((LM_DEBUG,"Connection established")); -<BR> ACE_Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); -<BR> } - -<P> int handle_input(ACE_HANDLE){ -<BR> char* data= new char[DATA_SIZE]; -<BR> peer().recv_n(data,DATA_SIZE); -<BR> ACE_OS::printf("<< %s\n",data); -<BR> return 0; -<BR> } -<BR>}; - -<P>typedef ACE_Acceptor<My_Svc_Handler,ACE_LSOCK_ACCEPTOR> MyAcceptor; - -<P>int main(int argc, char* argv[]){ -<BR> ACE_UNIX_Addr addr("/tmp/addr.ace"); -<BR> MyAcceptor acceptor(address, ACE_Reactor::instance()); - -<P>while(1) <FONT COLOR="#FF0000">/* Start the reactors event loop */</FONT> -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} - -<P> <A HREF="ex04.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex04.html b/docs/tutorials/Chap_6/ex04.html deleted file mode 100644 index f5910341621..00000000000 --- a/docs/tutorials/Chap_6/ex04.html +++ /dev/null @@ -1,44 +0,0 @@ -<HTML> -<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 4</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 4 (Use in conjunction with other examples -to create running example)</FONT><FONT COLOR="#CC0000"></FONT> - -<P>typedef ACE_Connector<My_Svc_Handler,ACE_SOCK_CONNECTOR> MyConnector; - -<P>int main(int argc, char * argv[]){ -<BR> ACE_INET_Addr addr(PORT_NO,HOSTNAME); -<BR> My_Svc_Handler * handler= new My_Svc_Handler; - -<P><FONT COLOR="#FF0000">//Create the connector</FONT> -<BR> MyConnector connector; - -<P><FONT COLOR="#FF0000">//Connects to remote machine</FONT> -<BR> if(connector.connect(handler,addr)==-1) -<BR> ACE_ERROR(LM_ERROR,?%P|%t, %p?,?Connection failed?); -<BR> - -<P><FONT COLOR="#FF0000">//Registers with the Reactor</FONT> -<BR> while(1) -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} - -<P> <A HREF="ex05.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex05.html b/docs/tutorials/Chap_6/ex05.html deleted file mode 100644 index c983e5751f9..00000000000 --- a/docs/tutorials/Chap_6/ex05.html +++ /dev/null @@ -1,129 +0,0 @@ -<HTML> -<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> diff --git a/docs/tutorials/Chap_6/ex06.html b/docs/tutorials/Chap_6/ex06.html deleted file mode 100644 index 7bfc3b91beb..00000000000 --- a/docs/tutorials/Chap_6/ex06.html +++ /dev/null @@ -1,134 +0,0 @@ -<HTML> -<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> diff --git a/docs/tutorials/Chap_6/ex07.html b/docs/tutorials/Chap_6/ex07.html deleted file mode 100644 index 7ecf0e57bb3..00000000000 --- a/docs/tutorials/Chap_6/ex07.html +++ /dev/null @@ -1,173 +0,0 @@ -<HTML> -<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 7</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 7</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> -<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">NETWORK_SPEED -3</FONT> -<BR>class MyServiceHandler;<FONT COLOR="#FF0000"> //forward declaration</FONT> -<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 message sender and creator threads are -handled 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")); - -<P><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</FONT> -<BR><FONT COLOR="#CC0000"> //remote machine.</FONT> -<BR> activate(THR_NEW_LWP, -<BR> 2, <FONT COLOR="#FF0000">//2 new threads</FONT> -<BR> 0, -<BR> ACE_DEFAULT_THREAD_PRIORITY, -<BR> -1, -<BR> this, -<BR> 0, -<BR> 0, -<BR> 0, -<BR> thread_names); <FONT COLOR="#FF0000">// identifiers in -thread_handles</FONT> -<BR> -<BR> <FONT COLOR="#FF0000">//keep the service handler registered with -the acceptor.</FONT> -<BR> return 0; -<BR> } - -<P>void send_message(void){ -<BR><FONT COLOR="#FF0000"> //Dequeue the message and send it off</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"(%t)Sending message >>")); - -<P><FONT COLOR="#FF0000"> //dequeue the message from the message queue</FONT> -<BR> ACE_Message_Block *mb; -<BR> ACE_ASSERT(this->getq(mb)!=-1); -<BR> int length=mb->length(); -<BR> char *data =mb->rd_ptr(); - -<P> -<BR><FONT COLOR="#FF0000"> //Send the data to the remote peer</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"%s \n",data,length)); -<BR> peer().send_n(data,length); - -<P> <FONT COLOR="#FF0000">//Simulate very SLOW network.</FONT> -<BR> ACE_OS::sleep(NETWORK_SPEED); - -<P><FONT COLOR="#FF0000"> //release the message block</FONT> -<BR> mb->release(); -<BR> } <FONT COLOR="#FF0000">//end send_message</FONT> - -<P>int construct_message(void){ -<BR><FONT COLOR="#FF0000"> // A very fast message creation algorithm</FONT> -<BR><FONT COLOR="#FF0000"> // would lead to the need for queuing messages..</FONT> -<BR><FONT COLOR="#FF0000"> // here. These messages are created and -then sent</FONT> -<BR><FONT COLOR="#FF0000"> // using the SLOW send_message() routine -which is</FONT> -<BR><FONT COLOR="#FF0000"> // running in a different thread so that -the message</FONT> -<BR><FONT COLOR="#FF0000"> //construction thread isn?t blocked.</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"(%t)Constructing message >> ")); - -<P> <FONT COLOR="#FF0000">// Create a new message to send</FONT> -<BR> ACE_Message_Block *mb; -<BR> char *data="Hello Connector"; -<BR> ACE_NEW_RETURN (mb,ACE_Message_Block (16,<FONT COLOR="#FF0000">//Message -16 bytes long</FONT> -<BR> ACE_Message_Block::MB_DATA,<FONT COLOR="#FF0000">//Set -header to data</FONT> -<BR> 0,<FONT COLOR="#FF0000">//No continuations</FONT>. -<BR> data<FONT COLOR="#FF0000">//The data we want to send</FONT> -<BR> ), 0); -<BR> mb->wr_ptr(16); <FONT COLOR="#FF0000">//Set the write pointer.</FONT> -<BR> -<BR> <FONT COLOR="#FF0000">// Enqueue the message into the message -queue</FONT> -<BR><FONT COLOR="#FF0000"> // we COULD have done a timed wait for -enqueuing in case</FONT> -<BR><FONT COLOR="#FF0000"> // someone else holds the lock to the queue -so it doesn?t block</FONT> -<BR><FONT COLOR="#FF0000"> //forever..</FONT> -<BR> ACE_ASSERT(this->putq(mb)!=-1); -<BR> ACE_DEBUG((LM_DEBUG,"Enqueued msg successfully\n")); -<BR>} -<BR> -<BR>int svc(void){ -<BR> ACE_DEBUG( (LM_DEBUG,?(%t) Svc thread \n?)); -<BR> -<BR><FONT COLOR="#FF0000"> //call the message creator thread</FONT> -<BR> if(ACE_Thread::self()== thread_names[0]) -<BR> while(1) construct_message(); <FONT COLOR="#FF0000">//create -messages forever</FONT> -<BR> else -<BR> while(1) send_message(); <FONT COLOR="#FF0000">//send messages -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"); -<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="ex08.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex08.html b/docs/tutorials/Chap_6/ex08.html deleted file mode 100644 index d90c00fbd67..00000000000 --- a/docs/tutorials/Chap_6/ex08.html +++ /dev/null @@ -1,96 +0,0 @@ -<HTML> -<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 8</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 8</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">#define</FONT><FONT COLOR="#663366"> PORT_NUM -10101</FONT> -<BR><FONT COLOR="#000099">#define</FONT><FONT COLOR="#663366"> DATA_SIZE -12</FONT><FONT COLOR="#FF0000"></FONT> - -<P><FONT COLOR="#FF0000">//forward declaration</FONT> -<BR>class My_Svc_Handler;<FONT COLOR="#FF0000"></FONT> - -<P><FONT COLOR="#FF0000">//instantiate a strategy acceptor</FONT> -<BR>typedef ACE_Strategy_Acceptor<My_Svc_Handler,ACE_SOCK_ACCEPTOR> -MyAcceptor;<FONT COLOR="#FF0000"></FONT> - -<P><FONT COLOR="#FF0000">//instantiate a concurrency strategy</FONT> -<BR>typedef ACE_Process_Strategy<My_Svc_Handler> Concurrency_Strategy; - -<P><FONT COLOR="#FF0000">// Define the Service Handler</FONT> -<BR>class My_Svc_Handler: -<BR> public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_NULL_SYNCH>{ -<BR>private: -<BR> char* data; -<BR>public: -<BR> My_Svc_Handler(){ -<BR> data= new char[DATA_SIZE]; -<BR> } -<BR> My_Svc_Handler(ACE_Thread_Manager* tm){ -<BR> data= new char[DATA_SIZE]; -<BR> } -<BR> int open(void*){ -<BR> ACE_DEBUG((LM_DEBUG,"Connection -established\n")); -<BR><FONT COLOR="#FF0000"> -//Register with the reactor</FONT> -<BR> ACE_Reactor::instance()->register_handler(this, -<BR> ACE_Event_Handler::READ_MASK); -<BR> return 0; -<BR> } - -<P> int handle_input(ACE_HANDLE){ -<BR> peer().recv_n(data,DATA_SIZE); -<BR> ACE_OS::printf(?<< %s\n?,data); -<BR> -<BR><FONT COLOR="#FF0000"> // keep yourself registered -with the reactor</FONT> -<BR> return 0; -<BR> } -<BR>}; - -<P>int main(int argc, char* argv[]){ -<BR> ACE_INET_Addr addr(PORT_NUM); - -<P> <FONT COLOR="#FF0000">//Concurrency Strategy</FONT> -<BR> Concurrency_Strategy my_con_strat; - -<P><FONT COLOR="#FF0000">//Instantiate the acceptor</FONT> -<BR> MyAcceptor acceptor(addr, <FONT COLOR="#FF0000">//address to -accept on</FONT> -<BR> ACE_Reactor::instance(), <FONT COLOR="#FF0000">//the reactor -to use</FONT> -<BR> 0, <FONT COLOR="#FF0000">// dont care about creation strategy</FONT> -<BR> 0, <FONT COLOR="#FF0000">// dont care about connection estb. -strategy</FONT> -<BR> &my_con_strat);<FONT COLOR="#FF0000"> // use our new process -concurrency strategy</FONT> - -<P>while(1)<FONT COLOR="#FF0000"> // Start the reactors event loop</FONT> -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} - -<P> <A HREF="ex09.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex09.html b/docs/tutorials/Chap_6/ex09.html deleted file mode 100644 index e641da20bc5..00000000000 --- a/docs/tutorials/Chap_6/ex09.html +++ /dev/null @@ -1,211 +0,0 @@ -<HTML> -<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 9</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 9</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/Reactor.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#663366"> </FONT><FONT COLOR="#006600">"ace/Svc_Handler.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT><FONT COLOR="#006600"> "ace/Connector.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_Connector.h"</FONT> -<BR><FONT COLOR="#000099">#include</FONT> <FONT COLOR="#006600">"ace/INET_Addr.h"</FONT> - -<P><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">PORT_NUM -10101</FONT> -<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DATA_SIZE -16</FONT> - -<P><FONT COLOR="#FF0000">//forward declaration</FONT> -<BR>class My_Svc_Handler; -<BR><FONT COLOR="#FF0000">//Function prototype</FONT> -<BR>static void make_connections(void *arg); - -<P><FONT COLOR="#FF0000">// Template specializations for the hashing function -for the</FONT> -<BR><FONT COLOR="#FF0000">// hash_map which is used by the cache. The cache -is used internally by the</FONT> -<BR><FONT COLOR="#FF0000">// Cached Connection Strategy . Here we use ACE_Hash_Addr</FONT> -<BR><FONT COLOR="#FF0000">// as our external identifier. This utility class -has already</FONT> -<BR><FONT COLOR="#FF0000">// overloaded the == operator and the hash() -method. (The</FONT> -<BR><FONT COLOR="#FF0000">// hashing function). The hash() method delgates -the work to</FONT> -<BR><FONT COLOR="#FF0000">// hash_i() and we use the IP address and port -to get a</FONT> -<BR><FONT COLOR="#FF0000">// a unique integer hash value.</FONT> -<BR>size_t -<BR>ACE_Hash_Addr<ACE_INET_Addr>::hash_i (const ACE_INET_Addr &addr) -const -<BR>{ -<BR> return addr.get_ip_address () + addr.get_port_number (); -<BR>} - -<P><FONT COLOR="#FF0000">//instantiate a strategy acceptor</FONT> -<BR>typedef ACE_Strategy_Connector<My_Svc_Handler,ACE_SOCK_CONNECTOR> -<BR>STRATEGY_CONNECTOR; - -<P><FONT COLOR="#FF0000">//Instantiate the Creation Strategy</FONT> -<BR>typedef ACE_NOOP_Creation_Strategy<My_Svc_Handler> -<BR> NULL_CREATION_STRATEGY; -<BR><FONT COLOR="#FF0000">//Instantiate the Concurrency Strategy</FONT> -<BR>typedef ACE_NOOP_Concurrency_Strategy<My_Svc_Handler> -<BR> NULL_CONCURRENCY_STRATEGY; -<BR><FONT COLOR="#FF0000">//Instantiate the Connection Strategy</FONT> -<BR>typedef ACE_Cached_Connect_Strategy<My_Svc_Handler, -<BR> -ACE_SOCK_CONNECTOR, -<BR> -ACE_SYNCH_RW_MUTEX> -<BR> CACHED_CONNECT_STRATEGY; -<BR> -<BR>class My_Svc_Handler: -<BR>public ACE_Svc_Handler <ACE_SOCK_STREAM,ACE_MT_SYNCH>{ -<BR>private: -<BR>char* data; - -<P>public: -<BR>My_Svc_Handler(){ -<BR>data= new char[DATA_SIZE]; -<BR> } -<BR>My_Svc_Handler(ACE_Thread_Manager* tm){ -<BR>data= new char[DATA_SIZE]; -<BR> } -<BR><FONT COLOR="#FF0000">//Called before the service handler is recycled..</FONT> -<BR>int -<BR>recycle (void *a=0){ -<BR> ACE_DEBUG ((LM_DEBUG, -<BR> "(%P|%t) recycling Svc_Handler %d with handle %d\n", -<BR> -this, this->peer ().get_handle ())); -<BR> return 0; -<BR> } - -<P>int open(void*){ -<BR> ACE_DEBUG((LM_DEBUG,"(%t)Connection established \n")); -<BR> -<BR> -<BR> - -<P><FONT COLOR="#FF0000"> //Register the service handler with the -reactor</FONT> -<BR> ACE_Reactor::instance() ->register_handler(this,ACE_Event_Handler::READ_MASK); -<BR> activate(THR_NEW_LWP|THR_DETACHED); -<BR> return 0; -<BR> } - -<P>int handle_input(ACE_HANDLE){ -<BR> ACE_DEBUG((LM_DEBUG,"Got input in thread: (%t) \n")); -<BR> peer().recv_n(data,DATA_SIZE); -<BR> ACE_DEBUG((LM_DEBUG,"<< %s\n",data)); - -<P> <FONT COLOR="#FF0000">//keep yourself registered with the reactor</FONT> -<BR> return 0; -<BR>} - -<P>int svc(void){ -<BR><FONT COLOR="#FF0000"> //send a few messages and then mark connection -as idle so that it can be recycled later.</FONT> -<BR> ACE_DEBUG((LM_DEBUG,"Started the service routine \n")); - -<P> for(int i=0;i<3;i++){ -<BR> ACE_DEBUG((LM_DEBUG,"(%t)>>Hello World\n")); -<BR> ACE_OS::fflush(stdout); -<BR> peer().send_n("Hello World",sizeof("Hello World")); -<BR> } - -<P> <FONT COLOR="#FF0000">//Mark the service handler as being idle -now and let the other threads reuse this connection</FONT> -<BR> this->idle(1); - -<P> <FONT COLOR="#FF0000">//Wait for the thread to die</FONT> -<BR> this->thr_mgr()->wait(); -<BR> return 0; -<BR> } -<BR>}; -<BR>ACE_INET_Addr *addr; - -<P>int main(int argc, char* argv[]){ -<BR> addr= new ACE_INET_Addr(PORT_NUM,argv[1]); -<BR><FONT COLOR="#FF0000"> //Creation Strategy</FONT> -<BR> NULL_CREATION_STRATEGY creation_strategy; - -<P><FONT COLOR="#FF0000"> //Concurrency Strategy</FONT> -<BR> NULL_CONCURRENCY_STRATEGY concurrency_strategy; - -<P><FONT COLOR="#FF0000"> //Connection Strategy</FONT> -<BR> CACHED_CONNECT_STRATEGY caching_connect_strategy; -<BR> - -<P><FONT COLOR="#FF0000"> //instantiate the connector</FONT> -<BR> STRATEGY_CONNECTOR connector( -<BR> ACE_Reactor::instance(),<FONT COLOR="#FF0000"> //the reactor -to use</FONT> -<BR> &creation_strategy, -<BR> &caching_connect_strategy, -<BR> &concurrency_strategy); -<BR><FONT COLOR="#FF0000"> //Use the thread manager to spawn -a single thread to</FONT> -<BR><FONT COLOR="#FF0000"> //connect multiple times passing it the -address</FONT> -<BR><FONT COLOR="#FF0000"> //of the strategy connector</FONT> -<BR> if(ACE_Thread_Manager::instance()->spawn( -<BR> (ACE_THR_FUNC) make_connections, -<BR> (void *) &connector, -<BR> THR_NEW_LWP) == -1) -<BR> ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n%a", "client thread spawn -failed")); - -<P>while(1) /* Start the reactor?s event loop */ -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} - -<P><FONT COLOR="#FF0000">//Connection establishment function, tries to -establish connections</FONT> -<BR><FONT COLOR="#FF0000">//to the same server again and re-uses the connections -from the</FONT> -<BR><FONT COLOR="#FF0000">//cache</FONT> -<BR>void make_connections(void *arg){ -<BR> ACE_DEBUG((LM_DEBUG,"(%t)Prepared to connect \n")); -<BR> STRATEGY_CONNECTOR *connector= (STRATEGY_CONNECTOR*) arg; -<BR> for (int i = 0; i < 10; i++){ -<BR> My_Svc_Handler *svc_handler = 0; -<BR> - -<P> <FONT COLOR="#FF0000">// Perform a blocking connect to the server -using the Strategy</FONT> -<BR><FONT COLOR="#FF0000"> // Connector with a connection caching -strategy. Since we are</FONT> -<BR><FONT COLOR="#FF0000"> // connecting to the same <server_addr> -these calls will return the</FONT> -<BR><FONT COLOR="#FF0000"> // same dynamically allocated <Svc_Handler> -for each <connect> call.</FONT> -<BR> if (connector->connect (svc_handler, *addr) == -1){ -<BR> ACE_ERROR ((LM_ERROR, "(%P|%t) %p\n", "connection failed\n")); -<BR> return; -<BR> } - -<P><FONT COLOR="#FF0000"> // Rest for a few seconds so that the connection -has been freed up</FONT> -<BR> ACE_OS::sleep (5); -<BR> } -<BR>} -<BR> -<BR> <A HREF="ex10.html">Next Example</A> -</BODY> -</HTML> diff --git a/docs/tutorials/Chap_6/ex10.html b/docs/tutorials/Chap_6/ex10.html deleted file mode 100644 index 872c1c44a82..00000000000 --- a/docs/tutorials/Chap_6/ex10.html +++ /dev/null @@ -1,110 +0,0 @@ -<HTML> -<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 10</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 10</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">#define</FONT> <FONT COLOR="#663366">PORT_NUM -10101</FONT> -<BR><FONT COLOR="#000099">#define</FONT> <FONT COLOR="#663366">DATA_SIZE -12</FONT> - -<P><FONT COLOR="#FF0000">//forward declaration</FONT> -<BR>class My_Svc_Handler; - -<P><FONT COLOR="#FF0000">//Create the Acceptor class</FONT> -<BR>typedef ACE_Acceptor<My_Event_Handler,ACE_SOCK_ACCEPTOR> -<BR>MyAcceptor; - -<P><FONT COLOR="#FF0000">//Create an event handler similar to as seen in -example 2.</FONT> -<BR><FONT COLOR="#FF0000">//We have to overload the get_handle() method -and write the peer()</FONT> -<BR><FONT COLOR="#FF0000">//method. We also provide the data member peer_ -as the underlying</FONT> -<BR><FONT COLOR="#FF0000">//stream which is used.</FONT> -<BR>class My_Event_Handler: -<BR> public ACE_Event_Handler{ -<BR>private: -<BR>char* data; -<BR><FONT COLOR="#FF0000">//Add a new attribute for the underlying stream -which will be used by the Event Handler</FONT> -<BR>ACE_SOCK_Stream peer_; -<BR>public: -<BR>My_Event_Handler(){ -<BR> data= new char[DATA_SIZE]; -<BR> } - -<P>int -<BR>open(void*){ -<BR> ACE_DEBUG((LM_DEBUG,"Connection established\n")); -<BR><FONT COLOR="#FF0000"> //Register the event handler with the reactor</FONT> -<BR> ACE_Reactor::instance()->register_handler(this, ACE_Event_Handler::READ_MASK); -<BR> return 0; -<BR> } - -<P>int -<BR>handle_input(ACE_HANDLE){ -<BR> <FONT COLOR="#FF0000">// After using the peer() method of our -ACE_Event_Handler to obtain a</FONT> -<BR><FONT COLOR="#FF0000"> //reference to the underlying stream of -the service handler class we</FONT> -<BR><FONT COLOR="#FF0000"> //call recv_n() on it to read the data -which has been received. This</FONT> -<BR><FONT COLOR="#FF0000"> //data is stored in the data array and -then printed out</FONT> -<BR> peer().recv_n(data,DATA_SIZE); -<BR> ACE_OS::printf("<< %s\n",data); - -<P> <FONT COLOR="#FF0000">// keep yourself registered with the reactor</FONT> -<BR> return 0; -<BR> } - -<P><FONT COLOR="#FF0000">// new method which returns the handle to the -reactor when it asks for it.</FONT> -<BR>ACE_HANDLE -<BR>get_handle(void) const{ -<BR> return this->peer_.get_handle(); -<BR> } - -<P><FONT COLOR="#FF0000">//new method which returns a reference to the -peer stream</FONT> -<BR>ACE_SOCK_Stream & -<BR>peer(void) const{ -<BR> return (ACE_SOCK_Stream &) this->peer_; -<BR> } -<BR>}; - -<P>int main(int argc, char* argv[]){ -<BR> ACE_INET_Addr addr(PORT_NUM); -<BR> <FONT COLOR="#FF0000">//create the acceptor</FONT> -<BR> MyAcceptor acceptor(addr,<FONT COLOR="#FF0000"> //address to -accept on</FONT> -<BR> ACE_Reactor::instance()); <FONT COLOR="#FF0000">//the reactor -to use</FONT> -<BR>while(1)<FONT COLOR="#FF0000"> // Start the reactors event loop</FONT> -<BR> ACE_Reactor::instance()->handle_events(); -<BR>} -<BR> -<BR> <A HREF="../Chap_7/ex01.html">Next Example</A> -</BODY> -</HTML> |