From 71bedf497cde8b0b38afbb366828b3df9c2803d6 Mon Sep 17 00:00:00 2001 From: brain Date: Mon, 19 Dec 2005 18:04:22 +0000 Subject: git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@2578 e03df62e-2008-0410-955e-edbf42e46eb7 --- docs/module-doc/classInspSocket.html | 557 ++++++++++++++++++++--------------- 1 file changed, 316 insertions(+), 241 deletions(-) (limited to 'docs/module-doc/classInspSocket.html') diff --git a/docs/module-doc/classInspSocket.html b/docs/module-doc/classInspSocket.html index 315270d80..934175061 100644 --- a/docs/module-doc/classInspSocket.html +++ b/docs/module-doc/classInspSocket.html @@ -74,6 +74,10 @@ Collaboration diagram for InspSocket:
-Definition at line 48 of file socket.cpp. +Definition at line 45 of file socket.cpp.
-References I_DISCONNECTED, and state.
00049 { -00050 this->state = I_DISCONNECTED; -00051 } +References I_DISCONNECTED, and state.00046 { +00047 this->state = I_DISCONNECTED; +00048 }@@ -199,15 +206,15 @@ This constructor is used to associate an existing connecting with an InspSocket
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.
-Definition at line 53 of file socket.cpp. +Definition at line 50 of file socket.cpp.
-References SocketEngine::AddFd(), fd, I_CONNECTED, IP, state, and X_ESTAB_MODULE.
00054 { -00055 this->fd = newfd; -00056 this->state = I_CONNECTED; -00057 this->IP = ip; -00058 SE->AddFd(this->fd,true,X_ESTAB_MODULE); -00059 socket_ref[this->fd] = this; -00060 } +References SocketEngine::AddFd(), fd, I_CONNECTED, IP, InspIRCd::SE, state, and X_ESTAB_MODULE.00051 { +00052 this->fd = newfd; +00053 this->state = I_CONNECTED; +00054 this->IP = ip; +00055 ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); +00056 socket_ref[this->fd] = this; +00057 }@@ -271,85 +278,85 @@ This constructor is used to create a new socket, either listening for connection
-Definition at line 62 of file socket.cpp. -
-References SocketEngine::AddFd(), addr, addy, BindSocket(), Close(), DEBUG, ERROR, fd, I_CONNECTING, I_ERR_BIND, I_ERR_CONNECT, I_ERR_SOCKET, I_ERROR, I_LISTENING, IP, log(), OnError(), OpenTCPSocket(), state, timeout, timeout_end, and X_ESTAB_MODULE.
00063 { -00064 if (listening) { -00065 if ((this->fd = OpenTCPSocket()) == ERROR) -00066 { -00067 this->fd = -1; -00068 this->state = I_ERROR; -00069 this->OnError(I_ERR_SOCKET); -00070 log(DEBUG,"OpenTCPSocket() error"); -00071 return; -00072 } -00073 else -00074 { -00075 if (BindSocket(this->fd,this->client,this->server,port,(char*)host.c_str()) == ERROR) -00076 { -00077 this->Close(); -00078 this->fd = -1; -00079 this->state = I_ERROR; -00080 this->OnError(I_ERR_BIND); -00081 log(DEBUG,"BindSocket() error %s",strerror(errno)); -00082 return; -00083 } -00084 else -00085 { -00086 this->state = I_LISTENING; -00087 SE->AddFd(this->fd,true,X_ESTAB_MODULE); -00088 socket_ref[this->fd] = this; -00089 log(DEBUG,"New socket now in I_LISTENING state"); -00090 return; -00091 } -00092 } -00093 } else { -00094 char* ip; -00095 this->host = host; -00096 hostent* hoste = gethostbyname(host.c_str()); -00097 if (!hoste) { -00098 ip = (char*)host.c_str(); -00099 } else { -00100 struct in_addr* ia = (in_addr*)hoste->h_addr; -00101 ip = inet_ntoa(*ia); -00102 } -00103 -00104 this->IP = ip; -00105 -00106 timeout_end = time(NULL)+maxtime; -00107 timeout = false; -00108 if ((this->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) -00109 { -00110 this->state = I_ERROR; -00111 this->OnError(I_ERR_SOCKET); -00112 return; -00113 } -00114 this->port = port; -00115 inet_aton(ip,&addy); -00116 addr.sin_family = AF_INET; -00117 addr.sin_addr = addy; -00118 addr.sin_port = htons(this->port); -00119 -00120 int flags; -00121 flags = fcntl(this->fd, F_GETFL, 0); -00122 fcntl(this->fd, F_SETFL, flags | O_NONBLOCK); -00123 -00124 if(connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1) -00125 { -00126 if (errno != EINPROGRESS) -00127 { -00128 this->Close(); -00129 this->OnError(I_ERR_CONNECT); -00130 this->state = I_ERROR; -00131 return; -00132 } -00133 } -00134 this->state = I_CONNECTING; -00135 SE->AddFd(this->fd,false,X_ESTAB_MODULE); -00136 socket_ref[this->fd] = this; -00137 return; -00138 } -00139 } +Definition at line 59 of file socket.cpp. ++References SocketEngine::AddFd(), addr, addy, BindSocket(), Close(), DEBUG, ERROR, fd, I_CONNECTING, I_ERR_BIND, I_ERR_CONNECT, I_ERR_SOCKET, I_ERROR, I_LISTENING, IP, log(), OnError(), OpenTCPSocket(), InspIRCd::SE, state, timeout, timeout_end, and X_ESTAB_MODULE.
00060 { +00061 if (listening) { +00062 if ((this->fd = OpenTCPSocket()) == ERROR) +00063 { +00064 this->fd = -1; +00065 this->state = I_ERROR; +00066 this->OnError(I_ERR_SOCKET); +00067 log(DEBUG,"OpenTCPSocket() error"); +00068 return; +00069 } +00070 else +00071 { +00072 if (BindSocket(this->fd,this->client,this->server,port,(char*)host.c_str()) == ERROR) +00073 { +00074 this->Close(); +00075 this->fd = -1; +00076 this->state = I_ERROR; +00077 this->OnError(I_ERR_BIND); +00078 log(DEBUG,"BindSocket() error %s",strerror(errno)); +00079 return; +00080 } +00081 else +00082 { +00083 this->state = I_LISTENING; +00084 ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); +00085 socket_ref[this->fd] = this; +00086 log(DEBUG,"New socket now in I_LISTENING state"); +00087 return; +00088 } +00089 } +00090 } else { +00091 char* ip; +00092 this->host = host; +00093 hostent* hoste = gethostbyname(host.c_str()); +00094 if (!hoste) { +00095 ip = (char*)host.c_str(); +00096 } else { +00097 struct in_addr* ia = (in_addr*)hoste->h_addr; +00098 ip = inet_ntoa(*ia); +00099 } +00100 +00101 this->IP = ip; +00102 +00103 timeout_end = time(NULL)+maxtime; +00104 timeout = false; +00105 if ((this->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) +00106 { +00107 this->state = I_ERROR; +00108 this->OnError(I_ERR_SOCKET); +00109 return; +00110 } +00111 this->port = port; +00112 inet_aton(ip,&addy); +00113 addr.sin_family = AF_INET; +00114 addr.sin_addr = addy; +00115 addr.sin_port = htons(this->port); +00116 +00117 int flags; +00118 flags = fcntl(this->fd, F_GETFL, 0); +00119 fcntl(this->fd, F_SETFL, flags | O_NONBLOCK); +00120 +00121 if(connect(this->fd, (sockaddr*)&this->addr,sizeof(this->addr)) == -1) +00122 { +00123 if (errno != EINPROGRESS) +00124 { +00125 this->Close(); +00126 this->OnError(I_ERR_CONNECT); +00127 this->state = I_ERROR; +00128 return; +00129 } +00130 } +00131 this->state = I_CONNECTING; +00132 ServerInstance->SE->AddFd(this->fd,false,X_ESTAB_MODULE); +00133 socket_ref[this->fd] = this; +00134 return; +00135 } +00136 }@@ -383,11 +390,11 @@ The destructor may implicitly call 272 of file socket.cpp. +Definition at line 271 of file socket.cpp.
-References Close().
00273 { -00274 this->Close(); -00275 } +References Close().00272 { +00273 this->Close(); +00274 }@@ -422,20 +429,71 @@ This method causes the socket to close, and may also be triggered by other metho
-Definition at line 141 of file socket.cpp. +Definition at line 138 of file socket.cpp. +
+References fd, and OnClose(). +
+Referenced by InspSocket(), and ~InspSocket().
+00139 { +00140 if (this->fd != -1) +00141 { +00142 this->OnClose(); +00143 shutdown(this->fd,2); +00144 close(this->fd); +00145 socket_ref[this->fd] = NULL; +00146 this->fd = -1; +00147 } +00148 } ++
+
++ ++ ++
++ +void InspSocket::FlushWriteBuffer +( ++ ) ++ [private]+
+ + + ++ + @@ -469,11 +527,11 @@ This method returns the socket's file descriptor as assigned by the operating sy+Flushes the write buffer. +
+ +
+Definition at line 181 of file socket.cpp.
-References fd, and OnClose(). +References Buffer.
-Referenced by InspSocket(), and ~InspSocket().
00142 { -00143 if (this->fd != -1) -00144 { -00145 this->OnClose(); -00146 shutdown(this->fd,2); -00147 close(this->fd); -00148 socket_ref[this->fd] = NULL; -00149 this->fd = -1; -00150 } -00151 } +Referenced by Timeout(), and Write().00182 { +00183 int result = 0; +00184 if (this->Buffer.length()) +00185 { +00186 result = send(this->fd,this->Buffer.c_str(),this->Buffer.length(),0); +00187 if (result > 0) +00188 { +00189 /* If we wrote some, advance the buffer forwards */ +00190 char* n = (char*)this->Buffer.c_str(); +00191 n += result; +00192 this->Buffer = n; +00193 } +00194 } +00195 }
-Definition at line 259 of file socket.cpp. +Definition at line 258 of file socket.cpp.
-References fd.
00260 { -00261 return this->fd; -00262 } +References fd.00259 { +00260 return this->fd; +00261 }@@ -507,11 +565,11 @@ Returns the IP address associated with this connection, or an empty string if no
-Definition at line 153 of file socket.cpp. +Definition at line 150 of file socket.cpp.
-References IP.
00154 { -00155 return this->IP; -00156 } +References IP.00151 { +00152 return this->IP; +00153 }@@ -545,11 +603,11 @@ Returns the current socket state.
-Definition at line 254 of file socket.cpp. +Definition at line 253 of file socket.cpp.
-References state.
00255 { -00256 return this->state; -00257 } +References state.00254 { +00255 return this->state; +00256 }@@ -583,9 +641,9 @@ Whenever close() is called, OnError(), OnTimeout(), and Close(), and also when cancelling a listening socket by calling the destructor indirectly.
-Definition at line 270 of file socket.cpp. +Definition at line 269 of file socket.cpp.
-Referenced by Close().
00270 { return; } +Referenced by Close().@@ -620,9 +678,9 @@ This method is called when an outbound connection on your socket is completed.
- Returns:
- false to abort the connection, true to continue
-Definition at line 264 of file socket.cpp. +Definition at line 263 of file socket.cpp.
-Referenced by Poll().
00264 { return true; } +Referenced by Poll().@@ -657,9 +715,9 @@ When there is data waiting to be read on a socket, the Read() 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 InspSocket::Close() and deletes it.
- Returns:
- false to close the socket
-Definition at line 268 of file socket.cpp. +Definition at line 267 of file socket.cpp.
-Referenced by Poll().
00268 { return true; } +Referenced by Poll().@@ -693,7 +751,7 @@ When an established connection is terminated, the OnDisconnect method is trigger
-Definition at line 266 of file socket.cpp.
00266 { return 0; } +Definition at line 265 of file socket.cpp.@@ -733,9 +791,9 @@ A closed socket in itself is not an error, however errors also generate close ev
-Definition at line 265 of file socket.cpp. +Definition at line 264 of file socket.cpp.
-Referenced by InspSocket(), and Timeout().
00265 { return; } +Referenced by InspSocket(), and Timeout().@@ -781,9 +839,9 @@ Given the new file descriptor in the parameters, and the IP, it is recommended y MySocket* newsocket = new MySocket(newfd,ip);
Once you have done this, you can then associate the new socket with the core using Server::AddSocket().
-Definition at line 267 of file socket.cpp. +Definition at line 266 of file socket.cpp.
-Referenced by Poll().
00267 { return 0; } +Referenced by Poll().@@ -817,9 +875,9 @@ When an outbound connection fails, and the attempt times out, you will receive t
The mthod will trigger once maxtime secons are reached (as given in the constructor) just before the socket's descriptor is closed.
-Definition at line 269 of file socket.cpp. +Definition at line 268 of file socket.cpp.
-Referenced by Timeout().
00269 { return; } +Referenced by Timeout().@@ -853,37 +911,37 @@ Only the core should call this function.
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.
-Definition at line 217 of file socket.cpp. -
-References SocketEngine::AddFd(), client, SocketEngine::DelFd(), I_CONNECTED, I_CONNECTING, I_LISTENING, length, OnConnected(), OnDataReady(), OnIncomingConnection(), SetState(), and X_ESTAB_MODULE.
00218 { -00219 int incoming = -1; -00220 -00221 switch (this->state) -00222 { -00223 case I_CONNECTING: -00224 this->SetState(I_CONNECTED); -00225 /* Our socket was in write-state, so delete it and re-add it -00226 * in read-state. -00227 */ -00228 SE->DelFd(this->fd); -00229 SE->AddFd(this->fd,true,X_ESTAB_MODULE); -00230 return this->OnConnected(); -00231 break; -00232 case I_LISTENING: -00233 length = sizeof (client); -00234 incoming = accept (this->fd, (sockaddr*)&client,&length); -00235 this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr)); -00236 return true; -00237 break; -00238 case I_CONNECTED: -00239 return this->OnDataReady(); -00240 break; -00241 default: -00242 break; -00243 } -00244 -00245 return true; -00246 } +Definition at line 216 of file socket.cpp. ++References SocketEngine::AddFd(), client, SocketEngine::DelFd(), I_CONNECTED, I_CONNECTING, I_LISTENING, length, OnConnected(), OnDataReady(), OnIncomingConnection(), InspIRCd::SE, SetState(), and X_ESTAB_MODULE.
00217 { +00218 int incoming = -1; +00219 +00220 switch (this->state) +00221 { +00222 case I_CONNECTING: +00223 this->SetState(I_CONNECTED); +00224 /* Our socket was in write-state, so delete it and re-add it +00225 * in read-state. +00226 */ +00227 ServerInstance->SE->DelFd(this->fd); +00228 ServerInstance->SE->AddFd(this->fd,true,X_ESTAB_MODULE); +00229 return this->OnConnected(); +00230 break; +00231 case I_LISTENING: +00232 length = sizeof (client); +00233 incoming = accept (this->fd, (sockaddr*)&client,&length); +00234 this->OnIncomingConnection(incoming,inet_ntoa(client.sin_addr)); +00235 return true; +00236 break; +00237 case I_CONNECTED: +00238 return this->OnDataReady(); +00239 break; +00240 default: +00241 break; +00242 } +00243 +00244 return true; +00245 }@@ -917,21 +975,21 @@ Reads all pending bytes from the socket into a char* array which can be up to 16
-Definition at line 158 of file socket.cpp. +Definition at line 155 of file socket.cpp.
-References DEBUG, ibuf, and log().
00159 { -00160 int n = recv(this->fd,this->ibuf,sizeof(this->ibuf),0); -00161 if (n > 0) -00162 { -00163 ibuf[n] = 0; -00164 return ibuf; -00165 } -00166 else -00167 { -00168 log(DEBUG,"EOF or error on socket"); -00169 return NULL; -00170 } -00171 } +References DEBUG, ibuf, and log().00156 { +00157 int n = recv(this->fd,this->ibuf,sizeof(this->ibuf),0); +00158 if (n > 0) +00159 { +00160 ibuf[n] = 0; +00161 return ibuf; +00162 } +00163 else +00164 { +00165 log(DEBUG,"EOF or error on socket"); +00166 return NULL; +00167 } +00168 }@@ -966,14 +1024,14 @@ Changes the socket's state.
The core uses this to change socket states, and you should not call it directly.
-Definition at line 248 of file socket.cpp. +Definition at line 247 of file socket.cpp.
-References DEBUG, log(), and state. +References DEBUG, log(), and state.
-Referenced by Poll().
00249 { -00250 log(DEBUG,"Socket state change"); -00251 this->state = s; -00252 } +Referenced by Poll().@@ -1009,23 +1067,25 @@ This function checks if the socket has timed out yet, given the current time in
- Returns:
- true if timed out, false if not timed out
-Definition at line 200 of file socket.cpp. -
-References I_CONNECTING, I_ERR_TIMEOUT, I_ERROR, OnError(), OnTimeout(), state, timeout, and timeout_end.
00201 { -00202 if ((this->state == I_CONNECTING) && (current > timeout_end)) -00203 { -00204 // for non-listening sockets, the timeout can occur -00205 // which causes termination of the connection after -00206 // the given number of seconds without a successful -00207 // connection. -00208 this->OnTimeout(); -00209 this->OnError(I_ERR_TIMEOUT); -00210 timeout = true; -00211 this->state = I_ERROR; -00212 return true; -00213 } -00214 return false; -00215 } +Definition at line 197 of file socket.cpp. ++References FlushWriteBuffer(), I_CONNECTING, I_ERR_TIMEOUT, I_ERROR, OnError(), OnTimeout(), state, timeout, and timeout_end.
00198 { +00199 if ((this->state == I_CONNECTING) && (current > timeout_end)) +00200 { +00201 // for non-listening sockets, the timeout can occur +00202 // which causes termination of the connection after +00203 // the given number of seconds without a successful +00204 // connection. +00205 this->OnTimeout(); +00206 this->OnError(I_ERR_TIMEOUT); +00207 timeout = true; +00208 this->state = I_ERROR; +00209 return true; +00210 } +00211 if (this->Buffer.length()) +00212 this->FlushWriteBuffer(); +00213 return false; +00214 }@@ -1065,27 +1125,13 @@ No carriage returns or linefeeds are appended to the string.
-Definition at line 177 of file socket.cpp.
00178 { -00179 char* d = (char*)data.c_str(); -00180 unsigned int written = 0; -00181 int n = 0; -00182 int s = data.length(); -00183 while ((written < data.length()) && (n >= 0)) -00184 { -00185 n = send(this->fd,d,s,0); -00186 if (n > 0) -00187 { -00188 // If we didnt write everything, advance -00189 // the pointers so that when we retry -00190 // the next time around the loop, we try -00191 // to write what we failed to write before. -00192 written += n; -00193 s -= n; -00194 d += n; -00195 } -00196 } -00197 return written; -00198 } +Definition at line 174 of file socket.cpp. ++References Buffer, and FlushWriteBuffer().
00175 { +00176 this->Buffer = this->Buffer + data; +00177 this->FlushWriteBuffer(); +00178 return data.length(); +00179 }@@ -1118,7 +1164,7 @@ The host being connected to, in sockaddr form.
Definition at line 78 of file socket.h.
-Referenced by InspSocket(). +Referenced by InspSocket().
@@ -1147,7 +1193,36 @@ The host being connected to, in in_addr form.
Definition at line 84 of file socket.h.
-Referenced by InspSocket(). +Referenced by InspSocket(). + + +
+
+
++ ++ ++
++ +std::string InspSocket::Buffer +[private]+
+ + + ++ + +The output buffer for this socket. +
+ +
+Definition at line 111 of file socket.h. +
+Referenced by FlushWriteBuffer(), and Write().
@@ -1174,9 +1249,9 @@ Client sockaddr structure used by accept().
-Definition at line 119 of file socket.h. +Definition at line 124 of file socket.h.
-Referenced by Poll(). +Referenced by Poll().
@@ -1205,7 +1280,7 @@ The file descriptor of this socket.
Definition at line 54 of file socket.h.
-Referenced by Close(), GetFd(), and InspSocket(). +Referenced by Close(), GetFd(), and InspSocket().
@@ -1235,13 +1310,13 @@ The hostname connected to. Definition at line 59 of file socket.h. -
@@ -1257,11 +1332,11 @@ Definition at line 59 of f
- char InspSocket::ibuf[16384] +[private]char InspSocket::ibuf[65535] [private]Socket input buffer, used by read().
-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. +The class which extends InspSocket is expected to implement an extendable buffer which can grow much larger than 64k, this buffer is just designed to be temporary storage. space.
@@ -1288,9 +1363,9 @@ The IP address being connected to stored in string form for easy retrieval by ac
-Definition at line 113 of file socket.h. +Definition at line 118 of file socket.h.
-Referenced by GetIP(), and InspSocket(). +Referenced by GetIP(), and InspSocket().
@@ -1317,9 +1392,9 @@ Used by accept() to indicate the sizes of the sockaddr_in structures.
-Definition at line 131 of file socket.h. +Definition at line 136 of file socket.h.
-Referenced by Poll(). +Referenced by Poll().
@@ -1373,7 +1448,7 @@ Definition at line 65 of f
-Definition at line 125 of file socket.h. +Definition at line 130 of file socket.h.
@@ -1402,7 +1477,7 @@ The state for this socket, either listening, connecting, connected or error.
Definition at line 72 of file socket.h.
-Referenced by GetState(), InspSocket(), SetState(), and Timeout(). +Referenced by GetState(), InspSocket(), SetState(), and Timeout().
@@ -1431,7 +1506,7 @@ This value is true if the socket has timed out.
Definition at line 97 of file socket.h.
-Referenced by InspSocket(), and Timeout(). +Referenced by InspSocket(), and Timeout().
@@ -1460,12 +1535,12 @@ When this time is reached, the socket times out if it is in the CONNECTING state
Definition at line 91 of file socket.h.
-Referenced by InspSocket(), and Timeout(). +Referenced by InspSocket(), and Timeout().
The documentation for this class was generated from the following files: -
Generated on Thu Dec 15 11:14:18 2005 for InspIRCd by +
Generated on Mon Dec 19 18:02:15 2005 for InspIRCd by1.4.4-20050815