1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Class Poco::Net::SocketConnector</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<meta name="author" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="publisher" content="Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="copyright" content="Copyright (c) 2009, Applied Informatics Software Engineering GmbH and Contributors"/>
<meta name="language" content="en"/>
<meta name="date" content="2009-11-24"/>
<meta name="generator" content="PocoDoc"/>
<link rel="stylesheet" href="css/styles.css" type="text/css"/>
</head>
<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
<div class="header">
<h1 class="namespace"><a href="Poco.Net.html" class="namespace">Poco::Net</a></h1>
<h1 class="template">template < class ServiceHandler ></h1>
<h1 class="symbol">class SocketConnector</h1>
</div>
<div class="body">
<p>
<b>Library:</b> Net<br />
<b>Package:</b> Reactor<br />
<b>Header:</b> Poco/Net/SocketConnector.h</p>
<h2>Description</h2>
<div class="description">
<p>This class implements the Connector part of the Acceptor-Connector design pattern. </p>
<p>The Acceptor-Connector pattern has been described in the book "Pattern Languages of Program Design 3", edited by Robert Martin, Frank Buschmann and Dirk Riehle (Addison Wesley, 1997). </p>
<p>The Acceptor-Connector design pattern decouples connection establishment and service initialization in a distributed system from the processing performed once a service is initialized. This decoupling is achieved with three components: Acceptors, Connectors and Service Handlers. The Connector actively establishes a connection with a remote server socket (usually managed by an Acceptor) and initializes a Service Handler to manage the connection. </p>
<p>The <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a> sets up a <a href="Poco.Net.StreamSocket.html" title="class Poco::Net::StreamSocket">StreamSocket</a>, initiates a non-blocking connect operation and registers itself for <a href="Poco.Net.ReadableNotification.html" title="class Poco::Net::ReadableNotification">ReadableNotification</a>, <a href="Poco.Net.WritableNotification.html" title="class Poco::Net::WritableNotification">WritableNotification</a> and <a href="Poco.Net.ErrorNotification.html" title="class Poco::Net::ErrorNotification">ErrorNotification</a>. <a href="Poco.Net.ReadableNotification.html" title="class Poco::Net::ReadableNotification">ReadableNotification</a> or <a href="Poco.Net.WritableNotification.html" title="class Poco::Net::WritableNotification">WritableNotification</a> denote the successful establishment of the connection. </p>
<p>When the <a href="Poco.Net.StreamSocket.html" title="class Poco::Net::StreamSocket">StreamSocket</a> becomes readable or writeable, the <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a> creates a ServiceHandler to service the connection and unregisters itself. </p>
<p>In case of an error (<a href="Poco.Net.ErrorNotification.html" title="class Poco::Net::ErrorNotification">ErrorNotification</a>), the <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a> unregisters itself and calls the <a href="Poco.Net.SocketConnector.html#15168" title="Poco::Net::SocketConnector::onError()">onError</a>() method, which can be overridden by subclasses to perform custom error handling. </p>
<p>The ServiceHandler class must provide a constructor that takes a <a href="Poco.Net.StreamSocket.html" title="class Poco::Net::StreamSocket">StreamSocket</a> and a <a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a> as arguments, e.g.: </p>
<pre>MyServiceHandler(const StreamSocket& socket, ServiceReactor& reactor)
</pre>
<p>When the ServiceHandler is done, it must destroy itself. </p>
<p>Subclasses can override the <a href="Poco.Net.SocketConnector.html#15170" title="Poco::Net::SocketConnector::createServiceHandler()">createServiceHandler</a>() factory method if special steps are necessary to create a ServiceHandler object. </p>
</div>
<h2>Member Summary</h2>
<p><b>Member Functions: </b><a href="Poco.Net.SocketConnector.html#15170" title="Poco::Net::SocketConnector::createServiceHandler()">createServiceHandler</a>, <a href="Poco.Net.SocketConnector.html#15167" title="Poco::Net::SocketConnector::onConnect()">onConnect</a>, <a href="Poco.Net.SocketConnector.html#15168" title="Poco::Net::SocketConnector::onError()">onError</a>, <a href="Poco.Net.SocketConnector.html#15163" title="Poco::Net::SocketConnector::onReadable()">onReadable</a>, <a href="Poco.Net.SocketConnector.html#15165" title="Poco::Net::SocketConnector::onWritable()">onWritable</a>, <a href="Poco.Net.SocketConnector.html#15173" title="Poco::Net::SocketConnector::reactor()">reactor</a>, <a href="Poco.Net.SocketConnector.html#15160" title="Poco::Net::SocketConnector::registerConnector()">registerConnector</a>, <a href="Poco.Net.SocketConnector.html#15174" title="Poco::Net::SocketConnector::socket()">socket</a>, <a href="Poco.Net.SocketConnector.html#15162" title="Poco::Net::SocketConnector::unregisterConnector()">unregisterConnector</a></p>
<h2>Constructors</h2>
<h3><a name="15154">SocketConnector</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">explicit <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>(<br /> <a href="Poco.Net.SocketAddress.html" title="class Poco::Net::SocketAddress">SocketAddress</a> & address<br />);</p>
<div class="description">
<p>Creates a <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>, using the given <a href="Poco.Net.Socket.html" title="class Poco::Net::Socket">Socket</a>. </p>
</div>
<h3><a name="15156">SocketConnector</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>(<br /> <a href="Poco.Net.SocketAddress.html" title="class Poco::Net::SocketAddress">SocketAddress</a> & address,<br /> <a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a> & reactor<br />);</p>
<div class="description">
<p>Creates an acceptor, using the given <a href="Poco.Net.ServerSocket.html" title="class Poco::Net::ServerSocket">ServerSocket</a>. The <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a> registers itself with the given <a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a>. </p>
</div>
<h2>Destructor</h2>
<h3><a name="15159">~SocketConnector</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual ~<a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>();</p>
<div class="description">
<p>Destroys the <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>. </p>
</div>
<h2>Member Functions</h2>
<h3><a name="15167">onConnect</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void onConnect();</p>
<div class="description">
<p></p>
</div>
<h3><a name="15168">onError</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void onError(<br /> <a href="Poco.Net.ErrorNotification.html" title="class Poco::Net::ErrorNotification">ErrorNotification</a> * pNotification<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="15163">onReadable</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void onReadable(<br /> <a href="Poco.Net.ReadableNotification.html" title="class Poco::Net::ReadableNotification">ReadableNotification</a> * pNotification<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="15165">onWritable</a> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">void onWritable(<br /> <a href="Poco.Net.WritableNotification.html" title="class Poco::Net::WritableNotification">WritableNotification</a> * pNotification<br />);</p>
<div class="description">
<p></p>
</div>
<h3><a name="15160">registerConnector</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual void registerConnector(<br /> <a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a> & reactor<br />);</p>
<div class="description">
<p>Registers the <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a> with a <a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a>. </p>
<p>A subclass can override this and, for example, also register an event handler for a timeout event. </p>
<p>The overriding method must call the baseclass implementation first. </p>
</div>
<h3><a name="15162">unregisterConnector</a> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual void unregisterConnector();</p>
<div class="description">
<p>Unregisters the <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>. </p>
<p>A subclass can override this and, for example, also unregister its event handler for a timeout event. </p>
<p>The overriding method must call the baseclass implementation first. </p>
</div>
<h3><a name="15170">createServiceHandler</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual ServiceHandler * createServiceHandler();</p>
<div class="description">
<p>Create and initialize a new ServiceHandler instance. </p>
<p>Subclasses can override this method. </p>
</div>
<h3><a name="15171">onError</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/virtual.gif" alt="virtual" title="virtual" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl">virtual void onError(<br /> int errorCode<br />);</p>
<div class="description">
<p>Called when the socket cannot be connected. </p>
<p>Subclasses can override this method. </p>
</div>
<h3><a name="15173">reactor</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a> * reactor();</p>
<div class="description">
<p>Returns a pointer to the <a href="Poco.Net.SocketReactor.html" title="class Poco::Net::SocketReactor">SocketReactor</a> where this <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a> is registered. </p>
<p>The pointer may be null. </p>
</div>
<h3><a name="15174">socket</a> <img src="images/protected.gif" alt="protected" title="protected" style="vertical-align:baseline;" border="0" /> <img src="images/inline.gif" alt="inline" title="inline" style="vertical-align:baseline;" border="0" /> </h3>
<p class="decl"><a href="Poco.Net.Socket.html" title="class Poco::Net::Socket">Socket</a> & socket();</p>
<div class="description">
<p>Returns a reference to the <a href="Poco.Net.SocketConnector.html" title="class Poco::Net::SocketConnector">SocketConnector</a>'s socket. </p>
</div>
<p class="footer">POCO C++ Libraries 1.3.6-all<br />
Copyright © 2009, <a href="http://pocoproject.org/" target="_blank">Applied Informatics Software Engineering GmbH and Contributors</a></p>
</div>
</body>
</html>
|