diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-11-10 21:33:25 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-11-10 21:33:25 +0000 |
commit | 8957225d74555060d1a83a4c240f1e602cc82d4a (patch) | |
tree | fc8c311055b97bfa1b5d2efbbd68d8705481660d /docs/tutorials/Chap_6/ex01.html | |
parent | 922a655a3a371b2d749f59761843297c408a9d1a (diff) | |
download | ATCD-8957225d74555060d1a83a4c240f1e602cc82d4a.tar.gz |
.
Diffstat (limited to 'docs/tutorials/Chap_6/ex01.html')
-rw-r--r-- | docs/tutorials/Chap_6/ex01.html | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/docs/tutorials/Chap_6/ex01.html b/docs/tutorials/Chap_6/ex01.html new file mode 100644 index 00000000000..ff60ea6dcb7 --- /dev/null +++ b/docs/tutorials/Chap_6/ex01.html @@ -0,0 +1,81 @@ +<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> |