]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - docs/module-doc/classInspSocket.html
Added extra documentation for InspSocket (at last)
[user/henk/code/inspircd.git] / docs / module-doc / classInspSocket.html
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>InspIRCd: InspSocket Class Reference</title>
4 <link href="inspircd.doxygen.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.4.4-20050815 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class&nbsp;Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical&nbsp;List</a> | <a class="qindex" href="annotated.html">Class&nbsp;List</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="namespacemembers.html">Namespace&nbsp;Members</a> | <a class="qindex" href="functions.html">Class&nbsp;Members</a> | <a class="qindex" href="globals.html">File&nbsp;Members</a></div>
8 <h1>InspSocket Class Reference</h1><!-- doxytag: class="InspSocket" -->InspSocket is an extendable socket class which modules can use for TCP socket support.  
9 <a href="#_details">More...</a>
10 <p>
11 <code>#include &lt;<a class="el" href="socket_8h-source.html">socket.h</a>&gt;</code>
12 <p>
13 Collaboration diagram for InspSocket:<p><center><img src="classInspSocket__coll__graph.gif" border="0" usemap="#InspSocket__coll__map" alt="Collaboration graph"></center>
14 <center><font size="2">[<a target="top" href="graph_legend.html">legend</a>]</font></center><a href="classInspSocket-members.html">List of all members.</a><table border="0" cellpadding="0" cellspacing="0">
15 <tr><td></td></tr>
16 <tr><td colspan="2"><br><h2>Public Member Functions</h2></td></tr>
17 <tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#InspSocket_28_29">InspSocket</a> ()</td></tr>
18
19 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The default constructor does nothing and should not be used.  <a href="#InspSocket_28_29"></a><br></td></tr>
20 <tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#InspSocket_28int_20newfd_2C_20char_20_2Aip_29">InspSocket</a> (int newfd, char *ip)</td></tr>
21
22 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This constructor is used to associate an existing connecting with an InspSocket class.  <a href="#InspSocket_28int_20newfd_2C_20char_20_2Aip_29"></a><br></td></tr>
23 <tr><td class="memItemLeft" nowrap align="right" valign="top">&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#InspSocket_28std_3A_3Astring_20host_2C_20int_20port_2C_20bool_20listening_2C_20unsigned_20long_20maxtime_29">InspSocket</a> (<a class="el" href="namespaceirc.html#string">std::string</a> <a class="el" href="classInspSocket.html#host">host</a>, int <a class="el" href="classInspSocket.html#port">port</a>, bool listening, unsigned long maxtime)</td></tr>
24
25 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This constructor is used to create a new socket, either listening for connections, or an outbound connection to another host.  <a href="#InspSocket_28std_3A_3Astring_20host_2C_20int_20port_2C_20bool_20listening_2C_20unsigned_20long_20maxtime_29"></a><br></td></tr>
26 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnConnected_28_29">OnConnected</a> ()</td></tr>
27
28 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is called when an outbound connection on your socket is completed.  <a href="#OnConnected_28_29"></a><br></td></tr>
29 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError</a> (<a class="el" href="socket_8h.html#InspSocketError">InspSocketError</a> e)</td></tr>
30
31 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method is called when an error occurs.  <a href="#OnError_28InspSocketError_20e_29"></a><br></td></tr>
32 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnDisconnect_28_29">OnDisconnect</a> ()</td></tr>
33
34 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">When an established connection is terminated, the OnDisconnect method is triggered.  <a href="#OnDisconnect_28_29"></a><br></td></tr>
35 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnDataReady_28_29">OnDataReady</a> ()</td></tr>
36
37 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">When there is data waiting to be read on a socket, the <a class="el" href="classInspSocket.html#OnDataReady_28_29">OnDataReady()</a> method is called.  <a href="#OnDataReady_28_29"></a><br></td></tr>
38 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnTimeout_28_29">OnTimeout</a> ()</td></tr>
39
40 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">When an outbound connection fails, and the attempt times out, you will receive this event.  <a href="#OnTimeout_28_29"></a><br></td></tr>
41 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnClose_28_29">OnClose</a> ()</td></tr>
42
43 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Whenever close() is called, <a class="el" href="classInspSocket.html#OnClose_28_29">OnClose()</a> will be called first.  <a href="#OnClose_28_29"></a><br></td></tr>
44 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual char *&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#Read_28_29">Read</a> ()</td></tr>
45
46 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Reads all pending bytes from the socket into a char* array which can be up to 16 kilobytes in length.  <a href="#Read_28_29"></a><br></td></tr>
47 <tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="namespaceirc.html#string">std::string</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#GetIP_28_29">GetIP</a> ()</td></tr>
48
49 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the IP address associated with this connection, or an empty string if no IP address exists.  <a href="#GetIP_28_29"></a><br></td></tr>
50 <tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#Timeout_28time_5Ft_20current_29">Timeout</a> (time_t current)</td></tr>
51
52 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This function checks if the socket has timed out yet, given the current time in the parameter.  <a href="#Timeout_28time_5Ft_20current_29"></a><br></td></tr>
53 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#Write_28std_3A_3Astring_20data_29">Write</a> (<a class="el" href="namespaceirc.html#string">std::string</a> data)</td></tr>
54
55 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Writes a <a class="el" href="namespaceirc.html#string">std::string</a> to the socket.  <a href="#Write_28std_3A_3Astring_20data_29"></a><br></td></tr>
56 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#OnIncomingConnection_28int_20newfd_2C_20char_20_2Aip_29">OnIncomingConnection</a> (int newfd, char *ip)</td></tr>
57
58 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">If your socket is a listening socket, when a new connection comes in on the socket this method will be called.  <a href="#OnIncomingConnection_28int_20newfd_2C_20char_20_2Aip_29"></a><br></td></tr>
59 <tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#SetState_28InspSocketState_20s_29">SetState</a> (<a class="el" href="socket_8h.html#InspSocketState">InspSocketState</a> s)</td></tr>
60
61 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Changes the socket's state.  <a href="#SetState_28InspSocketState_20s_29"></a><br></td></tr>
62 <tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="socket_8h.html#InspSocketState">InspSocketState</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#GetState_28_29">GetState</a> ()</td></tr>
63
64 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Returns the current socket state.  <a href="#GetState_28_29"></a><br></td></tr>
65 <tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#Poll_28_29">Poll</a> ()</td></tr>
66
67 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Only the core should call this function.  <a href="#Poll_28_29"></a><br></td></tr>
68 <tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#GetFd_28_29">GetFd</a> ()</td></tr>
69
70 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method returns the socket's file descriptor as assigned by the operating system, or -1 if no descriptor has been assigned.  <a href="#GetFd_28_29"></a><br></td></tr>
71 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#Close_28_29">Close</a> ()</td></tr>
72
73 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This method causes the socket to close, and may also be triggered by other methods such as OnTimeout and OnError.  <a href="#Close_28_29"></a><br></td></tr>
74 <tr><td class="memItemLeft" nowrap align="right" valign="top">virtual&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#_7EInspSocket_28_29">~InspSocket</a> ()</td></tr>
75
76 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The destructor may implicitly call <a class="el" href="classInspSocket.html#OnClose_28_29">OnClose()</a>, and will close() and shutdown() the file descriptor used for this socket.  <a href="#_7EInspSocket_28_29"></a><br></td></tr>
77 <tr><td colspan="2"><br><h2>Private Attributes</h2></td></tr>
78 <tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#fd">fd</a></td></tr>
79
80 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The file descriptor of this socket.  <a href="#fd"></a><br></td></tr>
81 <tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="namespaceirc.html#string">std::string</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#host">host</a></td></tr>
82
83 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The hostname connected to.  <a href="#host"></a><br></td></tr>
84 <tr><td class="memItemLeft" nowrap align="right" valign="top">int&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#port">port</a></td></tr>
85
86 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The port connected to, or the port this socket is listening on.  <a href="#port"></a><br></td></tr>
87 <tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="socket_8h.html#InspSocketState">InspSocketState</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#state">state</a></td></tr>
88
89 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The state for this socket, either listening, connecting, connected or error.  <a href="#state"></a><br></td></tr>
90 <tr><td class="memItemLeft" nowrap align="right" valign="top">sockaddr_in&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#addr">addr</a></td></tr>
91
92 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The host being connected to, in sockaddr form.  <a href="#addr"></a><br></td></tr>
93 <tr><td class="memItemLeft" nowrap align="right" valign="top">in_addr&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#addy">addy</a></td></tr>
94
95 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The host being connected to, in in_addr form.  <a href="#addy"></a><br></td></tr>
96 <tr><td class="memItemLeft" nowrap align="right" valign="top">time_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#timeout_5Fend">timeout_end</a></td></tr>
97
98 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">When this time is reached, the socket times out if it is in the CONNECTING state.  <a href="#timeout_5Fend"></a><br></td></tr>
99 <tr><td class="memItemLeft" nowrap align="right" valign="top">bool&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#timeout">timeout</a></td></tr>
100
101 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">This value is true if the socket has timed out.  <a href="#timeout"></a><br></td></tr>
102 <tr><td class="memItemLeft" nowrap align="right" valign="top">char&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#ibuf_5B_31_36_33_38_34_5D">ibuf</a> [16384]</td></tr>
103
104 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Socket input buffer, used by read().  <a href="#ibuf_5B_31_36_33_38_34_5D"></a><br></td></tr>
105 <tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="namespaceirc.html#string">std::string</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#IP">IP</a></td></tr>
106
107 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">The IP address being connected to stored in string form for easy retrieval by accessors.  <a href="#IP"></a><br></td></tr>
108 <tr><td class="memItemLeft" nowrap align="right" valign="top">sockaddr_in&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#client">client</a></td></tr>
109
110 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Client sockaddr structure used by accept().  <a href="#client"></a><br></td></tr>
111 <tr><td class="memItemLeft" nowrap align="right" valign="top">sockaddr_in&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#server">server</a></td></tr>
112
113 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight"><a class="el" href="classServer.html">Server</a> sockaddr structure used by accept().  <a href="#server"></a><br></td></tr>
114 <tr><td class="memItemLeft" nowrap align="right" valign="top">socklen_t&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="classInspSocket.html#length">length</a></td></tr>
115
116 <tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Used by accept() to indicate the sizes of the sockaddr_in structures.  <a href="#length"></a><br></td></tr>
117 </table>
118 <hr><a name="_details"></a><h2>Detailed Description</h2>
119 InspSocket is an extendable socket class which modules can use for TCP socket support. 
120 <p>
121 It is fully integrated into InspIRCds socket loop and attaches its sockets to the core's instance of the <a class="el" href="classSocketEngine.html">SocketEngine</a> class, meaning that any sockets you create have the same power and abilities as a socket created by the core itself. To use InspSocket, you must inherit a class from it, and use the InspSocket constructors to establish connections and bindings.
122 <p>
123
124 <p>
125 Definition at line <a class="el" href="socket_8h-source.html#l00047">47</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.<hr><h2>Constructor &amp; Destructor Documentation</h2>
126 <a class="anchor" name="InspSocket_28_29"></a><!-- doxytag: member="InspSocket::InspSocket" ref="InspSocket_28_29" args="()" --><p>
127 <table class="mdTable" cellpadding="2" cellspacing="0">
128   <tr>
129     <td class="mdRow">
130       <table cellpadding="0" cellspacing="0" border="0">
131         <tr>
132           <td class="md" nowrap valign="top">InspSocket::InspSocket           </td>
133           <td class="md" valign="top">(&nbsp;</td>
134           <td class="mdname1" valign="top" nowrap>          </td>
135           <td class="md" valign="top">&nbsp;)&nbsp;</td>
136           <td class="md" nowrap></td>
137         </tr>
138       </table>
139     </td>
140   </tr>
141 </table>
142 <table cellspacing="5" cellpadding="0" border="0">
143   <tr>
144     <td>
145       &nbsp;
146     </td>
147     <td>
148
149 <p>
150 The default constructor does nothing and should not be used. 
151 <p>
152
153 <p>
154 Definition at line <a class="el" href="socket_8cpp-source.html#l00049">49</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
155 <p>
156 References <a class="el" href="socket_8h.html#InspSocketStateI_5FDISCONNECTED">I_DISCONNECTED</a>, and <a class="el" href="socket_8h-source.html#l00072">state</a>.<div class="fragment"><pre class="fragment"><a name="l00050"></a>00050 {
157 <a name="l00051"></a>00051         this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FDISCONNECTED">I_DISCONNECTED</a>;
158 <a name="l00052"></a>00052 }
159 </pre></div>
160 <p>
161     </td>
162   </tr>
163 </table>
164 <a class="anchor" name="InspSocket_28int_20newfd_2C_20char_20_2Aip_29"></a><!-- doxytag: member="InspSocket::InspSocket" ref="InspSocket_28int_20newfd_2C_20char_20_2Aip_29" args="(int newfd, char *ip)" --><p>
165 <table class="mdTable" cellpadding="2" cellspacing="0">
166   <tr>
167     <td class="mdRow">
168       <table cellpadding="0" cellspacing="0" border="0">
169         <tr>
170           <td class="md" nowrap valign="top">InspSocket::InspSocket           </td>
171           <td class="md" valign="top">(&nbsp;</td>
172           <td class="md" nowrap valign="top">int&nbsp;</td>
173           <td class="mdname" nowrap> <em>newfd</em>, </td>
174         </tr>
175         <tr>
176           <td class="md" nowrap align="right"></td>
177           <td class="md"></td>
178           <td class="md" nowrap>char *&nbsp;</td>
179           <td class="mdname" nowrap> <em>ip</em></td>
180         </tr>
181         <tr>
182           <td class="md"></td>
183           <td class="md">)&nbsp;</td>
184           <td class="md" colspan="2"></td>
185         </tr>
186       </table>
187     </td>
188   </tr>
189 </table>
190 <table cellspacing="5" cellpadding="0" border="0">
191   <tr>
192     <td>
193       &nbsp;
194     </td>
195     <td>
196
197 <p>
198 This constructor is used to associate an existing connecting with an InspSocket class. 
199 <p>
200 The given file descriptor must be valid, and when initialized, the InspSocket will be set with the given IP address and placed in CONNECTED state.
201 <p>
202 Definition at line <a class="el" href="socket_8cpp-source.html#l00054">54</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
203 <p>
204 References <a class="el" href="socketengine_8cpp-source.html#l00065">SocketEngine::AddFd()</a>, <a class="el" href="socket_8h-source.html#l00054">fd</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FCONNECTED">I_CONNECTED</a>, <a class="el" href="socket_8h-source.html#l00113">IP</a>, <a class="el" href="socket_8h-source.html#l00072">state</a>, and <a class="el" href="socketengine_8h-source.html#l00044">X_ESTAB_MODULE</a>.<div class="fragment"><pre class="fragment"><a name="l00055"></a>00055 {
205 <a name="l00056"></a>00056         this-&gt;<a class="code" href="classInspSocket.html#fd">fd</a> = newfd;
206 <a name="l00057"></a>00057         this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FCONNECTED">I_CONNECTED</a>;
207 <a name="l00058"></a>00058         this-&gt;<a class="code" href="classInspSocket.html#IP">IP</a> = ip;
208 <a name="l00059"></a>00059         <a class="code" href="modules_8cpp.html#SE">SE</a>-&gt;<a class="code" href="classSocketEngine.html#AddFd_28int_20fd_2C_20bool_20readable_2C_20char_20type_29">AddFd</a>(this-&gt;fd,<span class="keyword">true</span>,<a class="code" href="socketengine_8h.html#X_5FESTAB_5FMODULE">X_ESTAB_MODULE</a>);
209 <a name="l00060"></a>00060 }
210 </pre></div>
211 <p>
212     </td>
213   </tr>
214 </table>
215 <a class="anchor" name="InspSocket_28std_3A_3Astring_20host_2C_20int_20port_2C_20bool_20listening_2C_20unsigned_20long_20maxtime_29"></a><!-- doxytag: member="InspSocket::InspSocket" ref="InspSocket_28std_3A_3Astring_20host_2C_20int_20port_2C_20bool_20listening_2C_20unsigned_20long_20maxtime_29" args="(std::string host, int port, bool listening, unsigned long maxtime)" --><p>
216 <table class="mdTable" cellpadding="2" cellspacing="0">
217   <tr>
218     <td class="mdRow">
219       <table cellpadding="0" cellspacing="0" border="0">
220         <tr>
221           <td class="md" nowrap valign="top">InspSocket::InspSocket           </td>
222           <td class="md" valign="top">(&nbsp;</td>
223           <td class="md" nowrap valign="top"><a class="el" href="namespaceirc.html#string">std::string</a>&nbsp;</td>
224           <td class="mdname" nowrap> <em>host</em>, </td>
225         </tr>
226         <tr>
227           <td class="md" nowrap align="right"></td>
228           <td class="md"></td>
229           <td class="md" nowrap>int&nbsp;</td>
230           <td class="mdname" nowrap> <em>port</em>, </td>
231         </tr>
232         <tr>
233           <td class="md" nowrap align="right"></td>
234           <td class="md"></td>
235           <td class="md" nowrap>bool&nbsp;</td>
236           <td class="mdname" nowrap> <em>listening</em>, </td>
237         </tr>
238         <tr>
239           <td class="md" nowrap align="right"></td>
240           <td class="md"></td>
241           <td class="md" nowrap>unsigned long&nbsp;</td>
242           <td class="mdname" nowrap> <em>maxtime</em></td>
243         </tr>
244         <tr>
245           <td class="md"></td>
246           <td class="md">)&nbsp;</td>
247           <td class="md" colspan="2"></td>
248         </tr>
249       </table>
250     </td>
251   </tr>
252 </table>
253 <table cellspacing="5" cellpadding="0" border="0">
254   <tr>
255     <td>
256       &nbsp;
257     </td>
258     <td>
259
260 <p>
261 This constructor is used to create a new socket, either listening for connections, or an outbound connection to another host. 
262 <p>
263 <dl compact><dt><b>Parameters:</b></dt><dd>
264   <table border="0" cellspacing="2" cellpadding="0">
265     <tr><td valign="top"></td><td valign="top"><em>host</em>&nbsp;</td><td>The hostname to connect to, or bind to </td></tr>
266     <tr><td valign="top"></td><td valign="top"><em>port</em>&nbsp;</td><td>The port number to connect to, or bind to </td></tr>
267     <tr><td valign="top"></td><td valign="top"><em>listening</em>&nbsp;</td><td>true to listen on the given host:port pair, or false to connect to them </td></tr>
268     <tr><td valign="top"></td><td valign="top"><em>maxtime</em>&nbsp;</td><td>Number of seconds to wait, if connecting, before the connection times out and an <a class="el" href="classInspSocket.html#OnTimeout_28_29">OnTimeout()</a> event is generated</td></tr>
269   </table>
270 </dl>
271
272 <p>
273 Definition at line <a class="el" href="socket_8cpp-source.html#l00062">62</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
274 <p>
275 References <a class="el" href="socketengine_8cpp-source.html#l00065">SocketEngine::AddFd()</a>, <a class="el" href="socket_8h-source.html#l00078">addr</a>, <a class="el" href="socket_8h-source.html#l00084">addy</a>, <a class="el" href="socket_8cpp-source.html#l00139">Close()</a>, <a class="el" href="modules_8h-source.html#l00023">DEBUG</a>, <a class="el" href="socket_8h-source.html#l00054">fd</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FCONNECTING">I_CONNECTING</a>, <a class="el" href="socket_8h.html#InspSocketErrorI_5FERR_5FBIND">I_ERR_BIND</a>, <a class="el" href="socket_8h.html#InspSocketErrorI_5FERR_5FCONNECT">I_ERR_CONNECT</a>, <a class="el" href="socket_8h.html#InspSocketErrorI_5FERR_5FSOCKET">I_ERR_SOCKET</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FLISTENING">I_LISTENING</a>, <a class="el" href="socket_8h-source.html#l00113">IP</a>, <a class="el" href="socket_8cpp-source.html#l00262">OnError()</a>, <a class="el" href="socket_8h-source.html#l00072">state</a>, <a class="el" href="socket_8h-source.html#l00097">timeout</a>, <a class="el" href="socket_8h-source.html#l00091">timeout_end</a>, and <a class="el" href="socketengine_8h-source.html#l00044">X_ESTAB_MODULE</a>.<div class="fragment"><pre class="fragment"><a name="l00063"></a>00063 {
276 <a name="l00064"></a>00064         <span class="keywordflow">if</span> (listening) {
277 <a name="l00065"></a>00065                 <span class="keywordflow">if</span> ((this-&gt;fd = OpenTCPSocket()) == ERROR)
278 <a name="l00066"></a>00066                 {
279 <a name="l00067"></a>00067                         this-&gt;<a class="code" href="classInspSocket.html#fd">fd</a> = -1;
280 <a name="l00068"></a>00068                         this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>;
281 <a name="l00069"></a>00069                         this-&gt;<a class="code" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError</a>(<a class="code" href="socket_8h.html#InspSocketErrorI_5FERR_5FSOCKET">I_ERR_SOCKET</a>);
282 <a name="l00070"></a>00070                         log(<a class="code" href="modules_8h.html#DEBUG">DEBUG</a>,<span class="stringliteral">"OpenTCPSocket() error"</span>);
283 <a name="l00071"></a>00071                         <span class="keywordflow">return</span>;
284 <a name="l00072"></a>00072                 }
285 <a name="l00073"></a>00073                 <span class="keywordflow">else</span>
286 <a name="l00074"></a>00074                 {
287 <a name="l00075"></a>00075                         <span class="keywordflow">if</span> (BindSocket(this-&gt;fd,this-&gt;client,this-&gt;server,<a class="code" href="classInspSocket.html#port">port</a>,(<span class="keywordtype">char</span>*)<a class="code" href="classInspSocket.html#host">host</a>.c_str()) == ERROR)
288 <a name="l00076"></a>00076                         {
289 <a name="l00077"></a>00077                                 this-&gt;<a class="code" href="classInspSocket.html#Close_28_29">Close</a>();
290 <a name="l00078"></a>00078                                 this-&gt;<a class="code" href="classInspSocket.html#fd">fd</a> = -1;
291 <a name="l00079"></a>00079                                 this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>;
292 <a name="l00080"></a>00080                                 this-&gt;<a class="code" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError</a>(<a class="code" href="socket_8h.html#InspSocketErrorI_5FERR_5FBIND">I_ERR_BIND</a>);
293 <a name="l00081"></a>00081                                 log(<a class="code" href="modules_8h.html#DEBUG">DEBUG</a>,<span class="stringliteral">"BindSocket() error %s"</span>,strerror(errno));
294 <a name="l00082"></a>00082                                 <span class="keywordflow">return</span>;
295 <a name="l00083"></a>00083                         }
296 <a name="l00084"></a>00084                         <span class="keywordflow">else</span>
297 <a name="l00085"></a>00085                         {
298 <a name="l00086"></a>00086                                 this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FLISTENING">I_LISTENING</a>;
299 <a name="l00087"></a>00087                                 <a class="code" href="modules_8cpp.html#SE">SE</a>-&gt;<a class="code" href="classSocketEngine.html#AddFd_28int_20fd_2C_20bool_20readable_2C_20char_20type_29">AddFd</a>(this-&gt;fd,<span class="keyword">true</span>,<a class="code" href="socketengine_8h.html#X_5FESTAB_5FMODULE">X_ESTAB_MODULE</a>);
300 <a name="l00088"></a>00088                                 log(<a class="code" href="modules_8h.html#DEBUG">DEBUG</a>,<span class="stringliteral">"New socket now in I_LISTENING state"</span>);
301 <a name="l00089"></a>00089                                 <span class="keywordflow">return</span>;
302 <a name="l00090"></a>00090                         }
303 <a name="l00091"></a>00091                 }                       
304 <a name="l00092"></a>00092         } <span class="keywordflow">else</span> {
305 <a name="l00093"></a>00093                 <span class="keywordtype">char</span>* ip;
306 <a name="l00094"></a>00094                 this-&gt;<a class="code" href="classInspSocket.html#host">host</a> = <a class="code" href="classInspSocket.html#host">host</a>;
307 <a name="l00095"></a>00095                 hostent* hoste = gethostbyname(<a class="code" href="classInspSocket.html#host">host</a>.c_str());
308 <a name="l00096"></a>00096                 <span class="keywordflow">if</span> (!hoste) {
309 <a name="l00097"></a>00097                         ip = (<span class="keywordtype">char</span>*)<a class="code" href="classInspSocket.html#host">host</a>.c_str();
310 <a name="l00098"></a>00098                 } <span class="keywordflow">else</span> {
311 <a name="l00099"></a>00099                         <span class="keyword">struct </span>in_addr* ia = (in_addr*)hoste-&gt;h_addr;
312 <a name="l00100"></a>00100                         ip = inet_ntoa(*ia);
313 <a name="l00101"></a>00101                 }
314 <a name="l00102"></a>00102 
315 <a name="l00103"></a>00103                 this-&gt;<a class="code" href="classInspSocket.html#IP">IP</a> = ip;
316 <a name="l00104"></a>00104 
317 <a name="l00105"></a>00105                 <a class="code" href="classInspSocket.html#timeout_5Fend">timeout_end</a> = time(NULL)+maxtime;
318 <a name="l00106"></a>00106                 <a class="code" href="classInspSocket.html#timeout">timeout</a> = <span class="keyword">false</span>;
319 <a name="l00107"></a>00107                 <span class="keywordflow">if</span> ((this-&gt;fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
320 <a name="l00108"></a>00108                 {
321 <a name="l00109"></a>00109                         this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>;
322 <a name="l00110"></a>00110                         this-&gt;<a class="code" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError</a>(<a class="code" href="socket_8h.html#InspSocketErrorI_5FERR_5FSOCKET">I_ERR_SOCKET</a>);
323 <a name="l00111"></a>00111                         <span class="keywordflow">return</span>;
324 <a name="l00112"></a>00112                 }
325 <a name="l00113"></a>00113                 this-&gt;<a class="code" href="classInspSocket.html#port">port</a> = <a class="code" href="classInspSocket.html#port">port</a>;
326 <a name="l00114"></a>00114                 inet_aton(ip,&amp;<a class="code" href="classInspSocket.html#addy">addy</a>);
327 <a name="l00115"></a>00115                 <a class="code" href="classInspSocket.html#addr">addr</a>.sin_family = AF_INET;
328 <a name="l00116"></a>00116                 <a class="code" href="classInspSocket.html#addr">addr</a>.sin_addr = <a class="code" href="classInspSocket.html#addy">addy</a>;
329 <a name="l00117"></a>00117                 <a class="code" href="classInspSocket.html#addr">addr</a>.sin_port = htons(this-&gt;port);
330 <a name="l00118"></a>00118 
331 <a name="l00119"></a>00119                 <span class="keywordtype">int</span> flags;
332 <a name="l00120"></a>00120                 flags = fcntl(this-&gt;fd, F_GETFL, 0);
333 <a name="l00121"></a>00121                 fcntl(this-&gt;fd, F_SETFL, flags | O_NONBLOCK);
334 <a name="l00122"></a>00122 
335 <a name="l00123"></a>00123                 <span class="keywordflow">if</span>(connect(this-&gt;fd, (sockaddr*)&amp;this-&gt;addr,<span class="keyword">sizeof</span>(this-&gt;addr)) == -1)
336 <a name="l00124"></a>00124                 {
337 <a name="l00125"></a>00125                         <span class="keywordflow">if</span> (errno != EINPROGRESS)
338 <a name="l00126"></a>00126                         {
339 <a name="l00127"></a>00127                                 this-&gt;<a class="code" href="classInspSocket.html#Close_28_29">Close</a>();
340 <a name="l00128"></a>00128                                 this-&gt;<a class="code" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError</a>(<a class="code" href="socket_8h.html#InspSocketErrorI_5FERR_5FCONNECT">I_ERR_CONNECT</a>);
341 <a name="l00129"></a>00129                                 this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>;
342 <a name="l00130"></a>00130                                 <span class="keywordflow">return</span>;
343 <a name="l00131"></a>00131                         }
344 <a name="l00132"></a>00132                 }
345 <a name="l00133"></a>00133                 this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FCONNECTING">I_CONNECTING</a>;
346 <a name="l00134"></a>00134                 <a class="code" href="modules_8cpp.html#SE">SE</a>-&gt;<a class="code" href="classSocketEngine.html#AddFd_28int_20fd_2C_20bool_20readable_2C_20char_20type_29">AddFd</a>(this-&gt;fd,<span class="keyword">false</span>,<a class="code" href="socketengine_8h.html#X_5FESTAB_5FMODULE">X_ESTAB_MODULE</a>);
347 <a name="l00135"></a>00135                 <span class="keywordflow">return</span>;
348 <a name="l00136"></a>00136         }
349 <a name="l00137"></a>00137 }
350 </pre></div>
351 <p>
352     </td>
353   </tr>
354 </table>
355 <a class="anchor" name="_7EInspSocket_28_29"></a><!-- doxytag: member="InspSocket::~InspSocket" ref="_7EInspSocket_28_29" args="()" --><p>
356 <table class="mdTable" cellpadding="2" cellspacing="0">
357   <tr>
358     <td class="mdRow">
359       <table cellpadding="0" cellspacing="0" border="0">
360         <tr>
361           <td class="md" nowrap valign="top">InspSocket::~InspSocket           </td>
362           <td class="md" valign="top">(&nbsp;</td>
363           <td class="mdname1" valign="top" nowrap>          </td>
364           <td class="md" valign="top">&nbsp;)&nbsp;</td>
365           <td class="md" nowrap><code> [virtual]</code></td>
366         </tr>
367       </table>
368     </td>
369   </tr>
370 </table>
371 <table cellspacing="5" cellpadding="0" border="0">
372   <tr>
373     <td>
374       &nbsp;
375     </td>
376     <td>
377
378 <p>
379 The destructor may implicitly call <a class="el" href="classInspSocket.html#OnClose_28_29">OnClose()</a>, and will close() and shutdown() the file descriptor used for this socket. 
380 <p>
381
382 <p>
383 Definition at line <a class="el" href="socket_8cpp-source.html#l00269">269</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
384 <p>
385 References <a class="el" href="socket_8cpp-source.html#l00139">Close()</a>.<div class="fragment"><pre class="fragment"><a name="l00270"></a>00270 {
386 <a name="l00271"></a>00271         this-&gt;<a class="code" href="classInspSocket.html#Close_28_29">Close</a>();
387 <a name="l00272"></a>00272 }
388 </pre></div>
389 <p>
390     </td>
391   </tr>
392 </table>
393 <hr><h2>Member Function Documentation</h2>
394 <a class="anchor" name="Close_28_29"></a><!-- doxytag: member="InspSocket::Close" ref="Close_28_29" args="()" --><p>
395 <table class="mdTable" cellpadding="2" cellspacing="0">
396   <tr>
397     <td class="mdRow">
398       <table cellpadding="0" cellspacing="0" border="0">
399         <tr>
400           <td class="md" nowrap valign="top">void InspSocket::Close           </td>
401           <td class="md" valign="top">(&nbsp;</td>
402           <td class="mdname1" valign="top" nowrap>          </td>
403           <td class="md" valign="top">&nbsp;)&nbsp;</td>
404           <td class="md" nowrap><code> [virtual]</code></td>
405         </tr>
406       </table>
407     </td>
408   </tr>
409 </table>
410 <table cellspacing="5" cellpadding="0" border="0">
411   <tr>
412     <td>
413       &nbsp;
414     </td>
415     <td>
416
417 <p>
418 This method causes the socket to close, and may also be triggered by other methods such as OnTimeout and OnError. 
419 <p>
420
421 <p>
422 Definition at line <a class="el" href="socket_8cpp-source.html#l00139">139</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
423 <p>
424 References <a class="el" href="socket_8h-source.html#l00054">fd</a>, and <a class="el" href="socket_8cpp-source.html#l00267">OnClose()</a>.
425 <p>
426 Referenced by <a class="el" href="socket_8cpp-source.html#l00062">InspSocket()</a>, and <a class="el" href="socket_8cpp-source.html#l00269">~InspSocket()</a>.<div class="fragment"><pre class="fragment"><a name="l00140"></a>00140 {
427 <a name="l00141"></a>00141         <span class="keywordflow">if</span> (this-&gt;fd != -1)
428 <a name="l00142"></a>00142         {
429 <a name="l00143"></a>00143                 this-&gt;<a class="code" href="classInspSocket.html#OnClose_28_29">OnClose</a>();
430 <a name="l00144"></a>00144                 shutdown(this-&gt;fd,2);
431 <a name="l00145"></a>00145                 close(this-&gt;fd);
432 <a name="l00146"></a>00146                 this-&gt;<a class="code" href="classInspSocket.html#fd">fd</a> = -1;
433 <a name="l00147"></a>00147         }
434 <a name="l00148"></a>00148 }
435 </pre></div>
436 <p>
437     </td>
438   </tr>
439 </table>
440 <a class="anchor" name="GetFd_28_29"></a><!-- doxytag: member="InspSocket::GetFd" ref="GetFd_28_29" args="()" --><p>
441 <table class="mdTable" cellpadding="2" cellspacing="0">
442   <tr>
443     <td class="mdRow">
444       <table cellpadding="0" cellspacing="0" border="0">
445         <tr>
446           <td class="md" nowrap valign="top">int InspSocket::GetFd           </td>
447           <td class="md" valign="top">(&nbsp;</td>
448           <td class="mdname1" valign="top" nowrap>          </td>
449           <td class="md" valign="top">&nbsp;)&nbsp;</td>
450           <td class="md" nowrap></td>
451         </tr>
452       </table>
453     </td>
454   </tr>
455 </table>
456 <table cellspacing="5" cellpadding="0" border="0">
457   <tr>
458     <td>
459       &nbsp;
460     </td>
461     <td>
462
463 <p>
464 This method returns the socket's file descriptor as assigned by the operating system, or -1 if no descriptor has been assigned. 
465 <p>
466
467 <p>
468 Definition at line <a class="el" href="socket_8cpp-source.html#l00256">256</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
469 <p>
470 References <a class="el" href="socket_8h-source.html#l00054">fd</a>.<div class="fragment"><pre class="fragment"><a name="l00257"></a>00257 {
471 <a name="l00258"></a>00258         <span class="keywordflow">return</span> this-&gt;<a class="code" href="classInspSocket.html#fd">fd</a>;
472 <a name="l00259"></a>00259 }
473 </pre></div>
474 <p>
475     </td>
476   </tr>
477 </table>
478 <a class="anchor" name="GetIP_28_29"></a><!-- doxytag: member="InspSocket::GetIP" ref="GetIP_28_29" args="()" --><p>
479 <table class="mdTable" cellpadding="2" cellspacing="0">
480   <tr>
481     <td class="mdRow">
482       <table cellpadding="0" cellspacing="0" border="0">
483         <tr>
484           <td class="md" nowrap valign="top"><a class="el" href="namespaceirc.html#string">std::string</a> InspSocket::GetIP           </td>
485           <td class="md" valign="top">(&nbsp;</td>
486           <td class="mdname1" valign="top" nowrap>          </td>
487           <td class="md" valign="top">&nbsp;)&nbsp;</td>
488           <td class="md" nowrap></td>
489         </tr>
490       </table>
491     </td>
492   </tr>
493 </table>
494 <table cellspacing="5" cellpadding="0" border="0">
495   <tr>
496     <td>
497       &nbsp;
498     </td>
499     <td>
500
501 <p>
502 Returns the IP address associated with this connection, or an empty string if no IP address exists. 
503 <p>
504
505 <p>
506 Definition at line <a class="el" href="socket_8cpp-source.html#l00150">150</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
507 <p>
508 References <a class="el" href="socket_8h-source.html#l00113">IP</a>.<div class="fragment"><pre class="fragment"><a name="l00151"></a>00151 {
509 <a name="l00152"></a>00152         <span class="keywordflow">return</span> this-&gt;<a class="code" href="classInspSocket.html#IP">IP</a>;
510 <a name="l00153"></a>00153 }
511 </pre></div>
512 <p>
513     </td>
514   </tr>
515 </table>
516 <a class="anchor" name="GetState_28_29"></a><!-- doxytag: member="InspSocket::GetState" ref="GetState_28_29" args="()" --><p>
517 <table class="mdTable" cellpadding="2" cellspacing="0">
518   <tr>
519     <td class="mdRow">
520       <table cellpadding="0" cellspacing="0" border="0">
521         <tr>
522           <td class="md" nowrap valign="top"><a class="el" href="socket_8h.html#InspSocketState">InspSocketState</a> InspSocket::GetState           </td>
523           <td class="md" valign="top">(&nbsp;</td>
524           <td class="mdname1" valign="top" nowrap>          </td>
525           <td class="md" valign="top">&nbsp;)&nbsp;</td>
526           <td class="md" nowrap></td>
527         </tr>
528       </table>
529     </td>
530   </tr>
531 </table>
532 <table cellspacing="5" cellpadding="0" border="0">
533   <tr>
534     <td>
535       &nbsp;
536     </td>
537     <td>
538
539 <p>
540 Returns the current socket state. 
541 <p>
542
543 <p>
544 Definition at line <a class="el" href="socket_8cpp-source.html#l00251">251</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
545 <p>
546 References <a class="el" href="socket_8h-source.html#l00072">state</a>.<div class="fragment"><pre class="fragment"><a name="l00252"></a>00252 {
547 <a name="l00253"></a>00253         <span class="keywordflow">return</span> this-&gt;<a class="code" href="classInspSocket.html#state">state</a>;
548 <a name="l00254"></a>00254 }
549 </pre></div>
550 <p>
551     </td>
552   </tr>
553 </table>
554 <a class="anchor" name="OnClose_28_29"></a><!-- doxytag: member="InspSocket::OnClose" ref="OnClose_28_29" args="()" --><p>
555 <table class="mdTable" cellpadding="2" cellspacing="0">
556   <tr>
557     <td class="mdRow">
558       <table cellpadding="0" cellspacing="0" border="0">
559         <tr>
560           <td class="md" nowrap valign="top">void InspSocket::OnClose           </td>
561           <td class="md" valign="top">(&nbsp;</td>
562           <td class="mdname1" valign="top" nowrap>          </td>
563           <td class="md" valign="top">&nbsp;)&nbsp;</td>
564           <td class="md" nowrap><code> [virtual]</code></td>
565         </tr>
566       </table>
567     </td>
568   </tr>
569 </table>
570 <table cellspacing="5" cellpadding="0" border="0">
571   <tr>
572     <td>
573       &nbsp;
574     </td>
575     <td>
576
577 <p>
578 Whenever close() is called, <a class="el" href="classInspSocket.html#OnClose_28_29">OnClose()</a> will be called first. 
579 <p>
580 Please note that this means OnClose will be called alongside <a class="el" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError()</a>, <a class="el" href="classInspSocket.html#OnTimeout_28_29">OnTimeout()</a>, and <a class="el" href="classInspSocket.html#Close_28_29">Close()</a>, and also when cancelling a listening socket by calling the destructor indirectly.
581 <p>
582 Definition at line <a class="el" href="socket_8cpp-source.html#l00267">267</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
583 <p>
584 Referenced by <a class="el" href="socket_8cpp-source.html#l00139">Close()</a>.<div class="fragment"><pre class="fragment"><a name="l00267"></a>00267 { <span class="keywordflow">return</span>; }
585 </pre></div>
586 <p>
587     </td>
588   </tr>
589 </table>
590 <a class="anchor" name="OnConnected_28_29"></a><!-- doxytag: member="InspSocket::OnConnected" ref="OnConnected_28_29" args="()" --><p>
591 <table class="mdTable" cellpadding="2" cellspacing="0">
592   <tr>
593     <td class="mdRow">
594       <table cellpadding="0" cellspacing="0" border="0">
595         <tr>
596           <td class="md" nowrap valign="top">bool InspSocket::OnConnected           </td>
597           <td class="md" valign="top">(&nbsp;</td>
598           <td class="mdname1" valign="top" nowrap>          </td>
599           <td class="md" valign="top">&nbsp;)&nbsp;</td>
600           <td class="md" nowrap><code> [virtual]</code></td>
601         </tr>
602       </table>
603     </td>
604   </tr>
605 </table>
606 <table cellspacing="5" cellpadding="0" border="0">
607   <tr>
608     <td>
609       &nbsp;
610     </td>
611     <td>
612
613 <p>
614 This method is called when an outbound connection on your socket is completed. 
615 <p>
616 <dl compact><dt><b>Returns:</b></dt><dd>false to abort the connection, true to continue</dd></dl>
617
618 <p>
619 Definition at line <a class="el" href="socket_8cpp-source.html#l00261">261</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
620 <p>
621 Referenced by <a class="el" href="socket_8cpp-source.html#l00214">Poll()</a>.<div class="fragment"><pre class="fragment"><a name="l00261"></a>00261 { <span class="keywordflow">return</span> <span class="keyword">true</span>; }
622 </pre></div>
623 <p>
624     </td>
625   </tr>
626 </table>
627 <a class="anchor" name="OnDataReady_28_29"></a><!-- doxytag: member="InspSocket::OnDataReady" ref="OnDataReady_28_29" args="()" --><p>
628 <table class="mdTable" cellpadding="2" cellspacing="0">
629   <tr>
630     <td class="mdRow">
631       <table cellpadding="0" cellspacing="0" border="0">
632         <tr>
633           <td class="md" nowrap valign="top">bool InspSocket::OnDataReady           </td>
634           <td class="md" valign="top">(&nbsp;</td>
635           <td class="mdname1" valign="top" nowrap>          </td>
636           <td class="md" valign="top">&nbsp;)&nbsp;</td>
637           <td class="md" nowrap><code> [virtual]</code></td>
638         </tr>
639       </table>
640     </td>
641   </tr>
642 </table>
643 <table cellspacing="5" cellpadding="0" border="0">
644   <tr>
645     <td>
646       &nbsp;
647     </td>
648     <td>
649
650 <p>
651 When there is data waiting to be read on a socket, the <a class="el" href="classInspSocket.html#OnDataReady_28_29">OnDataReady()</a> method is called. 
652 <p>
653 Within this method, you *MUST* call the <a class="el" href="classInspSocket.html#Read_28_29">Read()</a> method to read any pending data. At its lowest level, this event is signalled by the core via the socket engine. If you return false from this function, the core removes your socket from its list and erases it from the socket engine, then calls <a class="el" href="classInspSocket.html#Close_28_29">InspSocket::Close()</a> and deletes it. <dl compact><dt><b>Returns:</b></dt><dd>false to close the socket</dd></dl>
654
655 <p>
656 Definition at line <a class="el" href="socket_8cpp-source.html#l00265">265</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
657 <p>
658 Referenced by <a class="el" href="socket_8cpp-source.html#l00214">Poll()</a>.<div class="fragment"><pre class="fragment"><a name="l00265"></a>00265 { <span class="keywordflow">return</span> <span class="keyword">true</span>; }
659 </pre></div>
660 <p>
661     </td>
662   </tr>
663 </table>
664 <a class="anchor" name="OnDisconnect_28_29"></a><!-- doxytag: member="InspSocket::OnDisconnect" ref="OnDisconnect_28_29" args="()" --><p>
665 <table class="mdTable" cellpadding="2" cellspacing="0">
666   <tr>
667     <td class="mdRow">
668       <table cellpadding="0" cellspacing="0" border="0">
669         <tr>
670           <td class="md" nowrap valign="top">int InspSocket::OnDisconnect           </td>
671           <td class="md" valign="top">(&nbsp;</td>
672           <td class="mdname1" valign="top" nowrap>          </td>
673           <td class="md" valign="top">&nbsp;)&nbsp;</td>
674           <td class="md" nowrap><code> [virtual]</code></td>
675         </tr>
676       </table>
677     </td>
678   </tr>
679 </table>
680 <table cellspacing="5" cellpadding="0" border="0">
681   <tr>
682     <td>
683       &nbsp;
684     </td>
685     <td>
686
687 <p>
688 When an established connection is terminated, the OnDisconnect method is triggered. 
689 <p>
690
691 <p>
692 Definition at line <a class="el" href="socket_8cpp-source.html#l00263">263</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.<div class="fragment"><pre class="fragment"><a name="l00263"></a>00263 { <span class="keywordflow">return</span> 0; }
693 </pre></div>
694 <p>
695     </td>
696   </tr>
697 </table>
698 <a class="anchor" name="OnError_28InspSocketError_20e_29"></a><!-- doxytag: member="InspSocket::OnError" ref="OnError_28InspSocketError_20e_29" args="(InspSocketError e)" --><p>
699 <table class="mdTable" cellpadding="2" cellspacing="0">
700   <tr>
701     <td class="mdRow">
702       <table cellpadding="0" cellspacing="0" border="0">
703         <tr>
704           <td class="md" nowrap valign="top">void InspSocket::OnError           </td>
705           <td class="md" valign="top">(&nbsp;</td>
706           <td class="md" nowrap valign="top"><a class="el" href="socket_8h.html#InspSocketError">InspSocketError</a>&nbsp;</td>
707           <td class="mdname1" valign="top" nowrap> <em>e</em>          </td>
708           <td class="md" valign="top">&nbsp;)&nbsp;</td>
709           <td class="md" nowrap><code> [virtual]</code></td>
710         </tr>
711       </table>
712     </td>
713   </tr>
714 </table>
715 <table cellspacing="5" cellpadding="0" border="0">
716   <tr>
717     <td>
718       &nbsp;
719     </td>
720     <td>
721
722 <p>
723 This method is called when an error occurs. 
724 <p>
725 A closed socket in itself is not an error, however errors also generate close events. <dl compact><dt><b>Parameters:</b></dt><dd>
726   <table border="0" cellspacing="2" cellpadding="0">
727     <tr><td valign="top"></td><td valign="top"><em>e</em>&nbsp;</td><td>The error type which occured</td></tr>
728   </table>
729 </dl>
730
731 <p>
732 Definition at line <a class="el" href="socket_8cpp-source.html#l00262">262</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
733 <p>
734 Referenced by <a class="el" href="socket_8cpp-source.html#l00062">InspSocket()</a>, and <a class="el" href="socket_8cpp-source.html#l00197">Timeout()</a>.<div class="fragment"><pre class="fragment"><a name="l00262"></a>00262 { <span class="keywordflow">return</span>; }
735 </pre></div>
736 <p>
737     </td>
738   </tr>
739 </table>
740 <a class="anchor" name="OnIncomingConnection_28int_20newfd_2C_20char_20_2Aip_29"></a><!-- doxytag: member="InspSocket::OnIncomingConnection" ref="OnIncomingConnection_28int_20newfd_2C_20char_20_2Aip_29" args="(int newfd, char *ip)" --><p>
741 <table class="mdTable" cellpadding="2" cellspacing="0">
742   <tr>
743     <td class="mdRow">
744       <table cellpadding="0" cellspacing="0" border="0">
745         <tr>
746           <td class="md" nowrap valign="top">int InspSocket::OnIncomingConnection           </td>
747           <td class="md" valign="top">(&nbsp;</td>
748           <td class="md" nowrap valign="top">int&nbsp;</td>
749           <td class="mdname" nowrap> <em>newfd</em>, </td>
750         </tr>
751         <tr>
752           <td class="md" nowrap align="right"></td>
753           <td class="md"></td>
754           <td class="md" nowrap>char *&nbsp;</td>
755           <td class="mdname" nowrap> <em>ip</em></td>
756         </tr>
757         <tr>
758           <td class="md"></td>
759           <td class="md">)&nbsp;</td>
760           <td class="md" colspan="2"><code> [virtual]</code></td>
761         </tr>
762       </table>
763     </td>
764   </tr>
765 </table>
766 <table cellspacing="5" cellpadding="0" border="0">
767   <tr>
768     <td>
769       &nbsp;
770     </td>
771     <td>
772
773 <p>
774 If your socket is a listening socket, when a new connection comes in on the socket this method will be called. 
775 <p>
776 Given the new file descriptor in the parameters, and the IP, it is recommended you copy them to a new instance of your socket class, e.g.:<p>
777 MySocket* newsocket = new MySocket(newfd,ip);<p>
778 Once you have done this, you can then associate the new socket with the core using <a class="el" href="classServer.html#AddSocket_28InspSocket_20_2Asock_29">Server::AddSocket()</a>.
779 <p>
780 Definition at line <a class="el" href="socket_8cpp-source.html#l00264">264</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
781 <p>
782 Referenced by <a class="el" href="socket_8cpp-source.html#l00214">Poll()</a>.<div class="fragment"><pre class="fragment"><a name="l00264"></a>00264 { <span class="keywordflow">return</span> 0; }
783 </pre></div>
784 <p>
785     </td>
786   </tr>
787 </table>
788 <a class="anchor" name="OnTimeout_28_29"></a><!-- doxytag: member="InspSocket::OnTimeout" ref="OnTimeout_28_29" args="()" --><p>
789 <table class="mdTable" cellpadding="2" cellspacing="0">
790   <tr>
791     <td class="mdRow">
792       <table cellpadding="0" cellspacing="0" border="0">
793         <tr>
794           <td class="md" nowrap valign="top">void InspSocket::OnTimeout           </td>
795           <td class="md" valign="top">(&nbsp;</td>
796           <td class="mdname1" valign="top" nowrap>          </td>
797           <td class="md" valign="top">&nbsp;)&nbsp;</td>
798           <td class="md" nowrap><code> [virtual]</code></td>
799         </tr>
800       </table>
801     </td>
802   </tr>
803 </table>
804 <table cellspacing="5" cellpadding="0" border="0">
805   <tr>
806     <td>
807       &nbsp;
808     </td>
809     <td>
810
811 <p>
812 When an outbound connection fails, and the attempt times out, you will receive this event. 
813 <p>
814 The mthod will trigger once maxtime secons are reached (as given in the constructor) just before the socket's descriptor is closed.
815 <p>
816 Definition at line <a class="el" href="socket_8cpp-source.html#l00266">266</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
817 <p>
818 Referenced by <a class="el" href="socket_8cpp-source.html#l00197">Timeout()</a>.<div class="fragment"><pre class="fragment"><a name="l00266"></a>00266 { <span class="keywordflow">return</span>; }
819 </pre></div>
820 <p>
821     </td>
822   </tr>
823 </table>
824 <a class="anchor" name="Poll_28_29"></a><!-- doxytag: member="InspSocket::Poll" ref="Poll_28_29" args="()" --><p>
825 <table class="mdTable" cellpadding="2" cellspacing="0">
826   <tr>
827     <td class="mdRow">
828       <table cellpadding="0" cellspacing="0" border="0">
829         <tr>
830           <td class="md" nowrap valign="top">bool InspSocket::Poll           </td>
831           <td class="md" valign="top">(&nbsp;</td>
832           <td class="mdname1" valign="top" nowrap>          </td>
833           <td class="md" valign="top">&nbsp;)&nbsp;</td>
834           <td class="md" nowrap></td>
835         </tr>
836       </table>
837     </td>
838   </tr>
839 </table>
840 <table cellspacing="5" cellpadding="0" border="0">
841   <tr>
842     <td>
843       &nbsp;
844     </td>
845     <td>
846
847 <p>
848 Only the core should call this function. 
849 <p>
850 When called, it is assumed the socket is ready to read data, and the method call routes the event to the various methods of InspSocket for you to handle. This can also cause the socket's state to change.
851 <p>
852 Definition at line <a class="el" href="socket_8cpp-source.html#l00214">214</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
853 <p>
854 References <a class="el" href="socketengine_8cpp-source.html#l00065">SocketEngine::AddFd()</a>, <a class="el" href="socket_8h-source.html#l00119">client</a>, <a class="el" href="socketengine_8cpp-source.html#l00103">SocketEngine::DelFd()</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FCONNECTED">I_CONNECTED</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FCONNECTING">I_CONNECTING</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FLISTENING">I_LISTENING</a>, <a class="el" href="socket_8h-source.html#l00131">length</a>, <a class="el" href="socket_8cpp-source.html#l00261">OnConnected()</a>, <a class="el" href="socket_8cpp-source.html#l00265">OnDataReady()</a>, <a class="el" href="socket_8cpp-source.html#l00264">OnIncomingConnection()</a>, <a class="el" href="socket_8cpp-source.html#l00245">SetState()</a>, and <a class="el" href="socketengine_8h-source.html#l00044">X_ESTAB_MODULE</a>.<div class="fragment"><pre class="fragment"><a name="l00215"></a>00215 {
855 <a name="l00216"></a>00216         <span class="keywordtype">int</span> incoming = -1;
856 <a name="l00217"></a>00217         
857 <a name="l00218"></a>00218         <span class="keywordflow">switch</span> (this-&gt;state)
858 <a name="l00219"></a>00219         {
859 <a name="l00220"></a>00220                 <span class="keywordflow">case</span> <a class="code" href="socket_8h.html#InspSocketStateI_5FCONNECTING">I_CONNECTING</a>:
860 <a name="l00221"></a>00221                         this-&gt;<a class="code" href="classInspSocket.html#SetState_28InspSocketState_20s_29">SetState</a>(<a class="code" href="socket_8h.html#InspSocketStateI_5FCONNECTED">I_CONNECTED</a>);
861 <a name="l00222"></a>00222                         <span class="comment">/* Our socket was in write-state, so delete it and re-add it</span>
862 <a name="l00223"></a>00223 <span class="comment">                         * in read-state.</span>
863 <a name="l00224"></a>00224 <span class="comment">                         */</span>
864 <a name="l00225"></a>00225                         <a class="code" href="modules_8cpp.html#SE">SE</a>-&gt;<a class="code" href="classSocketEngine.html#DelFd_28int_20fd_29">DelFd</a>(this-&gt;fd);
865 <a name="l00226"></a>00226                         <a class="code" href="modules_8cpp.html#SE">SE</a>-&gt;<a class="code" href="classSocketEngine.html#AddFd_28int_20fd_2C_20bool_20readable_2C_20char_20type_29">AddFd</a>(this-&gt;fd,<span class="keyword">true</span>,<a class="code" href="socketengine_8h.html#X_5FESTAB_5FMODULE">X_ESTAB_MODULE</a>);
866 <a name="l00227"></a>00227                         <span class="keywordflow">return</span> this-&gt;<a class="code" href="classInspSocket.html#OnConnected_28_29">OnConnected</a>();
867 <a name="l00228"></a>00228                 <span class="keywordflow">break</span>;
868 <a name="l00229"></a>00229                 <span class="keywordflow">case</span> <a class="code" href="socket_8h.html#InspSocketStateI_5FLISTENING">I_LISTENING</a>:
869 <a name="l00230"></a>00230                         <a class="code" href="classInspSocket.html#length">length</a> = <span class="keyword">sizeof</span> (<a class="code" href="classInspSocket.html#client">client</a>);
870 <a name="l00231"></a>00231                         incoming = accept (this-&gt;fd, (sockaddr*)&amp;<a class="code" href="classInspSocket.html#client">client</a>,&amp;<a class="code" href="classInspSocket.html#length">length</a>);
871 <a name="l00232"></a>00232                         this-&gt;<a class="code" href="classInspSocket.html#OnIncomingConnection_28int_20newfd_2C_20char_20_2Aip_29">OnIncomingConnection</a>(incoming,inet_ntoa(<a class="code" href="classInspSocket.html#client">client</a>.sin_addr));
872 <a name="l00233"></a>00233                         <span class="keywordflow">return</span> <span class="keyword">true</span>;
873 <a name="l00234"></a>00234                 <span class="keywordflow">break</span>;
874 <a name="l00235"></a>00235                 <span class="keywordflow">case</span> <a class="code" href="socket_8h.html#InspSocketStateI_5FCONNECTED">I_CONNECTED</a>:
875 <a name="l00236"></a>00236                         <span class="keywordflow">return</span> this-&gt;<a class="code" href="classInspSocket.html#OnDataReady_28_29">OnDataReady</a>();
876 <a name="l00237"></a>00237                 <span class="keywordflow">break</span>;
877 <a name="l00238"></a>00238                 <span class="keywordflow">default</span>:
878 <a name="l00239"></a>00239                 <span class="keywordflow">break</span>;
879 <a name="l00240"></a>00240         }
880 <a name="l00241"></a>00241 
881 <a name="l00242"></a>00242         <span class="keywordflow">return</span> <span class="keyword">true</span>;
882 <a name="l00243"></a>00243 }
883 </pre></div>
884 <p>
885     </td>
886   </tr>
887 </table>
888 <a class="anchor" name="Read_28_29"></a><!-- doxytag: member="InspSocket::Read" ref="Read_28_29" args="()" --><p>
889 <table class="mdTable" cellpadding="2" cellspacing="0">
890   <tr>
891     <td class="mdRow">
892       <table cellpadding="0" cellspacing="0" border="0">
893         <tr>
894           <td class="md" nowrap valign="top">char * InspSocket::Read           </td>
895           <td class="md" valign="top">(&nbsp;</td>
896           <td class="mdname1" valign="top" nowrap>          </td>
897           <td class="md" valign="top">&nbsp;)&nbsp;</td>
898           <td class="md" nowrap><code> [virtual]</code></td>
899         </tr>
900       </table>
901     </td>
902   </tr>
903 </table>
904 <table cellspacing="5" cellpadding="0" border="0">
905   <tr>
906     <td>
907       &nbsp;
908     </td>
909     <td>
910
911 <p>
912 Reads all pending bytes from the socket into a char* array which can be up to 16 kilobytes in length. 
913 <p>
914
915 <p>
916 Definition at line <a class="el" href="socket_8cpp-source.html#l00155">155</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
917 <p>
918 References <a class="el" href="modules_8h-source.html#l00023">DEBUG</a>, and <a class="el" href="socket_8h-source.html#l00106">ibuf</a>.<div class="fragment"><pre class="fragment"><a name="l00156"></a>00156 {
919 <a name="l00157"></a>00157         <span class="keywordtype">int</span> n = recv(this-&gt;fd,this-&gt;ibuf,<span class="keyword">sizeof</span>(this-&gt;ibuf),0);
920 <a name="l00158"></a>00158         <span class="keywordflow">if</span> (n &gt; 0)
921 <a name="l00159"></a>00159         {
922 <a name="l00160"></a>00160                 <a class="code" href="classInspSocket.html#ibuf_5B_31_36_33_38_34_5D">ibuf</a>[n] = 0;
923 <a name="l00161"></a>00161                 <span class="keywordflow">return</span> <a class="code" href="classInspSocket.html#ibuf_5B_31_36_33_38_34_5D">ibuf</a>;
924 <a name="l00162"></a>00162         }
925 <a name="l00163"></a>00163         <span class="keywordflow">else</span>
926 <a name="l00164"></a>00164         {
927 <a name="l00165"></a>00165                 log(<a class="code" href="modules_8h.html#DEBUG">DEBUG</a>,<span class="stringliteral">"EOF or error on socket"</span>);
928 <a name="l00166"></a>00166                 <span class="keywordflow">return</span> NULL;
929 <a name="l00167"></a>00167         }
930 <a name="l00168"></a>00168 }
931 </pre></div>
932 <p>
933     </td>
934   </tr>
935 </table>
936 <a class="anchor" name="SetState_28InspSocketState_20s_29"></a><!-- doxytag: member="InspSocket::SetState" ref="SetState_28InspSocketState_20s_29" args="(InspSocketState s)" --><p>
937 <table class="mdTable" cellpadding="2" cellspacing="0">
938   <tr>
939     <td class="mdRow">
940       <table cellpadding="0" cellspacing="0" border="0">
941         <tr>
942           <td class="md" nowrap valign="top">void InspSocket::SetState           </td>
943           <td class="md" valign="top">(&nbsp;</td>
944           <td class="md" nowrap valign="top"><a class="el" href="socket_8h.html#InspSocketState">InspSocketState</a>&nbsp;</td>
945           <td class="mdname1" valign="top" nowrap> <em>s</em>          </td>
946           <td class="md" valign="top">&nbsp;)&nbsp;</td>
947           <td class="md" nowrap></td>
948         </tr>
949       </table>
950     </td>
951   </tr>
952 </table>
953 <table cellspacing="5" cellpadding="0" border="0">
954   <tr>
955     <td>
956       &nbsp;
957     </td>
958     <td>
959
960 <p>
961 Changes the socket's state. 
962 <p>
963 The core uses this to change socket states, and you should not call it directly.
964 <p>
965 Definition at line <a class="el" href="socket_8cpp-source.html#l00245">245</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
966 <p>
967 References <a class="el" href="modules_8h-source.html#l00023">DEBUG</a>, and <a class="el" href="socket_8h-source.html#l00072">state</a>.
968 <p>
969 Referenced by <a class="el" href="socket_8cpp-source.html#l00214">Poll()</a>.<div class="fragment"><pre class="fragment"><a name="l00246"></a>00246 {
970 <a name="l00247"></a>00247         log(<a class="code" href="modules_8h.html#DEBUG">DEBUG</a>,<span class="stringliteral">"Socket state change"</span>);
971 <a name="l00248"></a>00248         this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = s;
972 <a name="l00249"></a>00249 }
973 </pre></div>
974 <p>
975     </td>
976   </tr>
977 </table>
978 <a class="anchor" name="Timeout_28time_5Ft_20current_29"></a><!-- doxytag: member="InspSocket::Timeout" ref="Timeout_28time_5Ft_20current_29" args="(time_t current)" --><p>
979 <table class="mdTable" cellpadding="2" cellspacing="0">
980   <tr>
981     <td class="mdRow">
982       <table cellpadding="0" cellspacing="0" border="0">
983         <tr>
984           <td class="md" nowrap valign="top">bool InspSocket::Timeout           </td>
985           <td class="md" valign="top">(&nbsp;</td>
986           <td class="md" nowrap valign="top">time_t&nbsp;</td>
987           <td class="mdname1" valign="top" nowrap> <em>current</em>          </td>
988           <td class="md" valign="top">&nbsp;)&nbsp;</td>
989           <td class="md" nowrap></td>
990         </tr>
991       </table>
992     </td>
993   </tr>
994 </table>
995 <table cellspacing="5" cellpadding="0" border="0">
996   <tr>
997     <td>
998       &nbsp;
999     </td>
1000     <td>
1001
1002 <p>
1003 This function checks if the socket has timed out yet, given the current time in the parameter. 
1004 <p>
1005 <dl compact><dt><b>Returns:</b></dt><dd>true if timed out, false if not timed out</dd></dl>
1006
1007 <p>
1008 Definition at line <a class="el" href="socket_8cpp-source.html#l00197">197</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.
1009 <p>
1010 References <a class="el" href="socket_8h.html#InspSocketStateI_5FCONNECTING">I_CONNECTING</a>, <a class="el" href="socket_8h.html#InspSocketErrorI_5FERR_5FTIMEOUT">I_ERR_TIMEOUT</a>, <a class="el" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>, <a class="el" href="socket_8cpp-source.html#l00262">OnError()</a>, <a class="el" href="socket_8cpp-source.html#l00266">OnTimeout()</a>, <a class="el" href="socket_8h-source.html#l00072">state</a>, <a class="el" href="socket_8h-source.html#l00097">timeout</a>, and <a class="el" href="socket_8h-source.html#l00091">timeout_end</a>.<div class="fragment"><pre class="fragment"><a name="l00198"></a>00198 {
1011 <a name="l00199"></a>00199         <span class="keywordflow">if</span> ((this-&gt;state == <a class="code" href="socket_8h.html#InspSocketStateI_5FCONNECTING">I_CONNECTING</a>) &amp;&amp; (current &gt; <a class="code" href="classInspSocket.html#timeout_5Fend">timeout_end</a>))
1012 <a name="l00200"></a>00200         {
1013 <a name="l00201"></a>00201                 <span class="comment">// for non-listening sockets, the timeout can occur</span>
1014 <a name="l00202"></a>00202                 <span class="comment">// which causes termination of the connection after</span>
1015 <a name="l00203"></a>00203                 <span class="comment">// the given number of seconds without a successful</span>
1016 <a name="l00204"></a>00204                 <span class="comment">// connection.</span>
1017 <a name="l00205"></a>00205                 this-&gt;<a class="code" href="classInspSocket.html#OnTimeout_28_29">OnTimeout</a>();
1018 <a name="l00206"></a>00206                 this-&gt;<a class="code" href="classInspSocket.html#OnError_28InspSocketError_20e_29">OnError</a>(<a class="code" href="socket_8h.html#InspSocketErrorI_5FERR_5FTIMEOUT">I_ERR_TIMEOUT</a>);
1019 <a name="l00207"></a>00207                 <a class="code" href="classInspSocket.html#timeout">timeout</a> = <span class="keyword">true</span>;
1020 <a name="l00208"></a>00208                 this-&gt;<a class="code" href="classInspSocket.html#state">state</a> = <a class="code" href="socket_8h.html#InspSocketStateI_5FERROR">I_ERROR</a>;
1021 <a name="l00209"></a>00209                 <span class="keywordflow">return</span> <span class="keyword">true</span>;
1022 <a name="l00210"></a>00210         }
1023 <a name="l00211"></a>00211         <span class="keywordflow">return</span> <span class="keyword">false</span>;
1024 <a name="l00212"></a>00212 }
1025 </pre></div>
1026 <p>
1027     </td>
1028   </tr>
1029 </table>
1030 <a class="anchor" name="Write_28std_3A_3Astring_20data_29"></a><!-- doxytag: member="InspSocket::Write" ref="Write_28std_3A_3Astring_20data_29" args="(std::string data)" --><p>
1031 <table class="mdTable" cellpadding="2" cellspacing="0">
1032   <tr>
1033     <td class="mdRow">
1034       <table cellpadding="0" cellspacing="0" border="0">
1035         <tr>
1036           <td class="md" nowrap valign="top">int InspSocket::Write           </td>
1037           <td class="md" valign="top">(&nbsp;</td>
1038           <td class="md" nowrap valign="top"><a class="el" href="namespaceirc.html#string">std::string</a>&nbsp;</td>
1039           <td class="mdname1" valign="top" nowrap> <em>data</em>          </td>
1040           <td class="md" valign="top">&nbsp;)&nbsp;</td>
1041           <td class="md" nowrap><code> [virtual]</code></td>
1042         </tr>
1043       </table>
1044     </td>
1045   </tr>
1046 </table>
1047 <table cellspacing="5" cellpadding="0" border="0">
1048   <tr>
1049     <td>
1050       &nbsp;
1051     </td>
1052     <td>
1053
1054 <p>
1055 Writes a <a class="el" href="namespaceirc.html#string">std::string</a> to the socket. 
1056 <p>
1057 No carriage returns or linefeeds are appended to the string. <dl compact><dt><b>Parameters:</b></dt><dd>
1058   <table border="0" cellspacing="2" cellpadding="0">
1059     <tr><td valign="top"></td><td valign="top"><em>data</em>&nbsp;</td><td>The data to send</td></tr>
1060   </table>
1061 </dl>
1062
1063 <p>
1064 Definition at line <a class="el" href="socket_8cpp-source.html#l00174">174</a> of file <a class="el" href="socket_8cpp-source.html">socket.cpp</a>.<div class="fragment"><pre class="fragment"><a name="l00175"></a>00175 {
1065 <a name="l00176"></a>00176         <span class="keywordtype">char</span>* d = (<span class="keywordtype">char</span>*)data.c_str();
1066 <a name="l00177"></a>00177         <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> written = 0;
1067 <a name="l00178"></a>00178         <span class="keywordtype">int</span> n = 0;
1068 <a name="l00179"></a>00179         <span class="keywordtype">int</span> s = data.length();
1069 <a name="l00180"></a>00180         <span class="keywordflow">while</span> ((written &lt; data.length()) &amp;&amp; (n &gt;= 0))
1070 <a name="l00181"></a>00181         {
1071 <a name="l00182"></a>00182                 n = send(this-&gt;fd,d,s,0);
1072 <a name="l00183"></a>00183                 <span class="keywordflow">if</span> (n &gt; 0)
1073 <a name="l00184"></a>00184                 {
1074 <a name="l00185"></a>00185                         <span class="comment">// If we didnt write everything, advance</span>
1075 <a name="l00186"></a>00186                         <span class="comment">// the pointers so that when we retry</span>
1076 <a name="l00187"></a>00187                         <span class="comment">// the next time around the loop, we try</span>
1077 <a name="l00188"></a>00188                         <span class="comment">// to write what we failed to write before.</span>
1078 <a name="l00189"></a>00189                         written += n;
1079 <a name="l00190"></a>00190                         s -= n;
1080 <a name="l00191"></a>00191                         d += n;
1081 <a name="l00192"></a>00192                 }
1082 <a name="l00193"></a>00193         }
1083 <a name="l00194"></a>00194         <span class="keywordflow">return</span> written;
1084 <a name="l00195"></a>00195 }
1085 </pre></div>
1086 <p>
1087     </td>
1088   </tr>
1089 </table>
1090 <hr><h2>Member Data Documentation</h2>
1091 <a class="anchor" name="addr"></a><!-- doxytag: member="InspSocket::addr" ref="addr" args="" --><p>
1092 <table class="mdTable" cellpadding="2" cellspacing="0">
1093   <tr>
1094     <td class="mdRow">
1095       <table cellpadding="0" cellspacing="0" border="0">
1096         <tr>
1097           <td class="md" nowrap valign="top">sockaddr_in <a class="el" href="classInspSocket.html#addr">InspSocket::addr</a><code> [private]</code>          </td>
1098         </tr>
1099       </table>
1100     </td>
1101   </tr>
1102 </table>
1103 <table cellspacing="5" cellpadding="0" border="0">
1104   <tr>
1105     <td>
1106       &nbsp;
1107     </td>
1108     <td>
1109
1110 <p>
1111 The host being connected to, in sockaddr form. 
1112 <p>
1113
1114 <p>
1115 Definition at line <a class="el" href="socket_8h-source.html#l00078">78</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1116 <p>
1117 Referenced by <a class="el" href="socket_8cpp-source.html#l00062">InspSocket()</a>.    </td>
1118   </tr>
1119 </table>
1120 <a class="anchor" name="addy"></a><!-- doxytag: member="InspSocket::addy" ref="addy" args="" --><p>
1121 <table class="mdTable" cellpadding="2" cellspacing="0">
1122   <tr>
1123     <td class="mdRow">
1124       <table cellpadding="0" cellspacing="0" border="0">
1125         <tr>
1126           <td class="md" nowrap valign="top">in_addr <a class="el" href="classInspSocket.html#addy">InspSocket::addy</a><code> [private]</code>          </td>
1127         </tr>
1128       </table>
1129     </td>
1130   </tr>
1131 </table>
1132 <table cellspacing="5" cellpadding="0" border="0">
1133   <tr>
1134     <td>
1135       &nbsp;
1136     </td>
1137     <td>
1138
1139 <p>
1140 The host being connected to, in in_addr form. 
1141 <p>
1142
1143 <p>
1144 Definition at line <a class="el" href="socket_8h-source.html#l00084">84</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1145 <p>
1146 Referenced by <a class="el" href="socket_8cpp-source.html#l00062">InspSocket()</a>.    </td>
1147   </tr>
1148 </table>
1149 <a class="anchor" name="client"></a><!-- doxytag: member="InspSocket::client" ref="client" args="" --><p>
1150 <table class="mdTable" cellpadding="2" cellspacing="0">
1151   <tr>
1152     <td class="mdRow">
1153       <table cellpadding="0" cellspacing="0" border="0">
1154         <tr>
1155           <td class="md" nowrap valign="top">sockaddr_in <a class="el" href="classInspSocket.html#client">InspSocket::client</a><code> [private]</code>          </td>
1156         </tr>
1157       </table>
1158     </td>
1159   </tr>
1160 </table>
1161 <table cellspacing="5" cellpadding="0" border="0">
1162   <tr>
1163     <td>
1164       &nbsp;
1165     </td>
1166     <td>
1167
1168 <p>
1169 Client sockaddr structure used by accept(). 
1170 <p>
1171
1172 <p>
1173 Definition at line <a class="el" href="socket_8h-source.html#l00119">119</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1174 <p>
1175 Referenced by <a class="el" href="socket_8cpp-source.html#l00214">Poll()</a>.    </td>
1176   </tr>
1177 </table>
1178 <a class="anchor" name="fd"></a><!-- doxytag: member="InspSocket::fd" ref="fd" args="" --><p>
1179 <table class="mdTable" cellpadding="2" cellspacing="0">
1180   <tr>
1181     <td class="mdRow">
1182       <table cellpadding="0" cellspacing="0" border="0">
1183         <tr>
1184           <td class="md" nowrap valign="top">int <a class="el" href="classInspSocket.html#fd">InspSocket::fd</a><code> [private]</code>          </td>
1185         </tr>
1186       </table>
1187     </td>
1188   </tr>
1189 </table>
1190 <table cellspacing="5" cellpadding="0" border="0">
1191   <tr>
1192     <td>
1193       &nbsp;
1194     </td>
1195     <td>
1196
1197 <p>
1198 The file descriptor of this socket. 
1199 <p>
1200
1201 <p>
1202 Definition at line <a class="el" href="socket_8h-source.html#l00054">54</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1203 <p>
1204 Referenced by <a class="el" href="socket_8cpp-source.html#l00139">Close()</a>, <a class="el" href="socket_8cpp-source.html#l00256">GetFd()</a>, and <a class="el" href="socket_8cpp-source.html#l00054">InspSocket()</a>.    </td>
1205   </tr>
1206 </table>
1207 <a class="anchor" name="host"></a><!-- doxytag: member="InspSocket::host" ref="host" args="" --><p>
1208 <table class="mdTable" cellpadding="2" cellspacing="0">
1209   <tr>
1210     <td class="mdRow">
1211       <table cellpadding="0" cellspacing="0" border="0">
1212         <tr>
1213           <td class="md" nowrap valign="top"><a class="el" href="namespaceirc.html#string">std::string</a> <a class="el" href="classInspSocket.html#host">InspSocket::host</a><code> [private]</code>          </td>
1214         </tr>
1215       </table>
1216     </td>
1217   </tr>
1218 </table>
1219 <table cellspacing="5" cellpadding="0" border="0">
1220   <tr>
1221     <td>
1222       &nbsp;
1223     </td>
1224     <td>
1225
1226 <p>
1227 The hostname connected to. 
1228 <p>
1229
1230 <p>
1231 Definition at line <a class="el" href="socket_8h-source.html#l00059">59</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.    </td>
1232   </tr>
1233 </table>
1234 <a class="anchor" name="ibuf_5B_31_36_33_38_34_5D"></a><!-- doxytag: member="InspSocket::ibuf" ref="ibuf_5B_31_36_33_38_34_5D" args="[16384]" --><p>
1235 <table class="mdTable" cellpadding="2" cellspacing="0">
1236   <tr>
1237     <td class="mdRow">
1238       <table cellpadding="0" cellspacing="0" border="0">
1239         <tr>
1240           <td class="md" nowrap valign="top">char <a class="el" href="classInspSocket.html#ibuf_5B_31_36_33_38_34_5D">InspSocket::ibuf</a>[16384]<code> [private]</code>          </td>
1241         </tr>
1242       </table>
1243     </td>
1244   </tr>
1245 </table>
1246 <table cellspacing="5" cellpadding="0" border="0">
1247   <tr>
1248     <td>
1249       &nbsp;
1250     </td>
1251     <td>
1252
1253 <p>
1254 Socket input buffer, used by read(). 
1255 <p>
1256 The class which extends InspSocket is expected to implement an extendable buffer which can grow much larger than 16k, this buffer is just designed to be temporary storage. space.
1257 <p>
1258 Definition at line <a class="el" href="socket_8h-source.html#l00106">106</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1259 <p>
1260 Referenced by <a class="el" href="socket_8cpp-source.html#l00155">Read()</a>.    </td>
1261   </tr>
1262 </table>
1263 <a class="anchor" name="IP"></a><!-- doxytag: member="InspSocket::IP" ref="IP" args="" --><p>
1264 <table class="mdTable" cellpadding="2" cellspacing="0">
1265   <tr>
1266     <td class="mdRow">
1267       <table cellpadding="0" cellspacing="0" border="0">
1268         <tr>
1269           <td class="md" nowrap valign="top"><a class="el" href="namespaceirc.html#string">std::string</a> <a class="el" href="classInspSocket.html#IP">InspSocket::IP</a><code> [private]</code>          </td>
1270         </tr>
1271       </table>
1272     </td>
1273   </tr>
1274 </table>
1275 <table cellspacing="5" cellpadding="0" border="0">
1276   <tr>
1277     <td>
1278       &nbsp;
1279     </td>
1280     <td>
1281
1282 <p>
1283 The IP address being connected to stored in string form for easy retrieval by accessors. 
1284 <p>
1285
1286 <p>
1287 Definition at line <a class="el" href="socket_8h-source.html#l00113">113</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1288 <p>
1289 Referenced by <a class="el" href="socket_8cpp-source.html#l00150">GetIP()</a>, and <a class="el" href="socket_8cpp-source.html#l00054">InspSocket()</a>.    </td>
1290   </tr>
1291 </table>
1292 <a class="anchor" name="length"></a><!-- doxytag: member="InspSocket::length" ref="length" args="" --><p>
1293 <table class="mdTable" cellpadding="2" cellspacing="0">
1294   <tr>
1295     <td class="mdRow">
1296       <table cellpadding="0" cellspacing="0" border="0">
1297         <tr>
1298           <td class="md" nowrap valign="top">socklen_t <a class="el" href="classInspSocket.html#length">InspSocket::length</a><code> [private]</code>          </td>
1299         </tr>
1300       </table>
1301     </td>
1302   </tr>
1303 </table>
1304 <table cellspacing="5" cellpadding="0" border="0">
1305   <tr>
1306     <td>
1307       &nbsp;
1308     </td>
1309     <td>
1310
1311 <p>
1312 Used by accept() to indicate the sizes of the sockaddr_in structures. 
1313 <p>
1314
1315 <p>
1316 Definition at line <a class="el" href="socket_8h-source.html#l00131">131</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1317 <p>
1318 Referenced by <a class="el" href="socket_8cpp-source.html#l00214">Poll()</a>.    </td>
1319   </tr>
1320 </table>
1321 <a class="anchor" name="port"></a><!-- doxytag: member="InspSocket::port" ref="port" args="" --><p>
1322 <table class="mdTable" cellpadding="2" cellspacing="0">
1323   <tr>
1324     <td class="mdRow">
1325       <table cellpadding="0" cellspacing="0" border="0">
1326         <tr>
1327           <td class="md" nowrap valign="top">int <a class="el" href="classInspSocket.html#port">InspSocket::port</a><code> [private]</code>          </td>
1328         </tr>
1329       </table>
1330     </td>
1331   </tr>
1332 </table>
1333 <table cellspacing="5" cellpadding="0" border="0">
1334   <tr>
1335     <td>
1336       &nbsp;
1337     </td>
1338     <td>
1339
1340 <p>
1341 The port connected to, or the port this socket is listening on. 
1342 <p>
1343
1344 <p>
1345 Definition at line <a class="el" href="socket_8h-source.html#l00065">65</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.    </td>
1346   </tr>
1347 </table>
1348 <a class="anchor" name="server"></a><!-- doxytag: member="InspSocket::server" ref="server" args="" --><p>
1349 <table class="mdTable" cellpadding="2" cellspacing="0">
1350   <tr>
1351     <td class="mdRow">
1352       <table cellpadding="0" cellspacing="0" border="0">
1353         <tr>
1354           <td class="md" nowrap valign="top">sockaddr_in <a class="el" href="classInspSocket.html#server">InspSocket::server</a><code> [private]</code>          </td>
1355         </tr>
1356       </table>
1357     </td>
1358   </tr>
1359 </table>
1360 <table cellspacing="5" cellpadding="0" border="0">
1361   <tr>
1362     <td>
1363       &nbsp;
1364     </td>
1365     <td>
1366
1367 <p>
1368 <a class="el" href="classServer.html">Server</a> sockaddr structure used by accept(). 
1369 <p>
1370
1371 <p>
1372 Definition at line <a class="el" href="socket_8h-source.html#l00125">125</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.    </td>
1373   </tr>
1374 </table>
1375 <a class="anchor" name="state"></a><!-- doxytag: member="InspSocket::state" ref="state" args="" --><p>
1376 <table class="mdTable" cellpadding="2" cellspacing="0">
1377   <tr>
1378     <td class="mdRow">
1379       <table cellpadding="0" cellspacing="0" border="0">
1380         <tr>
1381           <td class="md" nowrap valign="top"><a class="el" href="socket_8h.html#InspSocketState">InspSocketState</a> <a class="el" href="classInspSocket.html#state">InspSocket::state</a><code> [private]</code>          </td>
1382         </tr>
1383       </table>
1384     </td>
1385   </tr>
1386 </table>
1387 <table cellspacing="5" cellpadding="0" border="0">
1388   <tr>
1389     <td>
1390       &nbsp;
1391     </td>
1392     <td>
1393
1394 <p>
1395 The state for this socket, either listening, connecting, connected or error. 
1396 <p>
1397
1398 <p>
1399 Definition at line <a class="el" href="socket_8h-source.html#l00072">72</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1400 <p>
1401 Referenced by <a class="el" href="socket_8cpp-source.html#l00251">GetState()</a>, <a class="el" href="socket_8cpp-source.html#l00049">InspSocket()</a>, <a class="el" href="socket_8cpp-source.html#l00245">SetState()</a>, and <a class="el" href="socket_8cpp-source.html#l00197">Timeout()</a>.    </td>
1402   </tr>
1403 </table>
1404 <a class="anchor" name="timeout"></a><!-- doxytag: member="InspSocket::timeout" ref="timeout" args="" --><p>
1405 <table class="mdTable" cellpadding="2" cellspacing="0">
1406   <tr>
1407     <td class="mdRow">
1408       <table cellpadding="0" cellspacing="0" border="0">
1409         <tr>
1410           <td class="md" nowrap valign="top">bool <a class="el" href="classInspSocket.html#timeout">InspSocket::timeout</a><code> [private]</code>          </td>
1411         </tr>
1412       </table>
1413     </td>
1414   </tr>
1415 </table>
1416 <table cellspacing="5" cellpadding="0" border="0">
1417   <tr>
1418     <td>
1419       &nbsp;
1420     </td>
1421     <td>
1422
1423 <p>
1424 This value is true if the socket has timed out. 
1425 <p>
1426
1427 <p>
1428 Definition at line <a class="el" href="socket_8h-source.html#l00097">97</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1429 <p>
1430 Referenced by <a class="el" href="socket_8cpp-source.html#l00062">InspSocket()</a>, and <a class="el" href="socket_8cpp-source.html#l00197">Timeout()</a>.    </td>
1431   </tr>
1432 </table>
1433 <a class="anchor" name="timeout_5Fend"></a><!-- doxytag: member="InspSocket::timeout_end" ref="timeout_5Fend" args="" --><p>
1434 <table class="mdTable" cellpadding="2" cellspacing="0">
1435   <tr>
1436     <td class="mdRow">
1437       <table cellpadding="0" cellspacing="0" border="0">
1438         <tr>
1439           <td class="md" nowrap valign="top">time_t <a class="el" href="classInspSocket.html#timeout_5Fend">InspSocket::timeout_end</a><code> [private]</code>          </td>
1440         </tr>
1441       </table>
1442     </td>
1443   </tr>
1444 </table>
1445 <table cellspacing="5" cellpadding="0" border="0">
1446   <tr>
1447     <td>
1448       &nbsp;
1449     </td>
1450     <td>
1451
1452 <p>
1453 When this time is reached, the socket times out if it is in the CONNECTING state. 
1454 <p>
1455
1456 <p>
1457 Definition at line <a class="el" href="socket_8h-source.html#l00091">91</a> of file <a class="el" href="socket_8h-source.html">socket.h</a>.
1458 <p>
1459 Referenced by <a class="el" href="socket_8cpp-source.html#l00062">InspSocket()</a>, and <a class="el" href="socket_8cpp-source.html#l00197">Timeout()</a>.    </td>
1460   </tr>
1461 </table>
1462 <hr>The documentation for this class was generated from the following files:<ul>
1463 <li><a class="el" href="socket_8h-source.html">socket.h</a><li><a class="el" href="socket_8cpp-source.html">socket.cpp</a></ul>
1464 <hr size="1"><address style="align: right;"><small>Generated on Mon Dec 12 18:31:02 2005 for InspIRCd by&nbsp;
1465 <a href="http://www.doxygen.org/index.html">
1466 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.4-20050815 </small></address>
1467 </body>
1468 </html>