- /**
- * The hostname connected to
- */
- std::string host;
-
- /**
- * The port connected to, or the port
- * this socket is listening on
- */
- int port;
-
- /**
- * The state for this socket, either
- * listening, connecting, connected
- * or error.
- */
- InspSocketState state;
-
- /**
- * The host being connected to,
- * in sockaddr form
- */
- sockaddr_in addr;
-
- /**
- * The host being connected to,
- * in in_addr form
- */
- in_addr addy;
-
- /**
- * When this time is reached,
- * the socket times out if it is
- * in the CONNECTING state
- */
- time_t timeout_end;
-
- /**
- * This value is true if the
- * socket has timed out.
- */
- bool timeout;
-
- /**
- * Socket input buffer, used by read(). 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.
- */
- char ibuf[65535];
-
- /**
- * The output buffer for this socket
- */
- std::string Buffer;
-
- /**
- * The IP address being connected
- * to stored in string form for
- * easy retrieval by accessors.
- */
- std::string IP;
-
- /**
- * Client sockaddr structure used
- * by accept()
- */
- sockaddr_in client;
-
- /**
- * Server sockaddr structure used
- * by accept()
- */
- sockaddr_in server;
-
- /**
- * Used by accept() to indicate the
- * sizes of the sockaddr_in structures
- */
- socklen_t length;
-
- /** Flushes the write buffer
- */
- void FlushWriteBuffer();
-
-public:
-
- /**
- * The default constructor does nothing
- * and should not be used.
- */
- InspSocket();
-
- /**
- * This constructor is used to associate
- * an existing connecting with an InspSocket
- * class. 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.
- */
- InspSocket(int newfd, char* ip);
-
- /**
- * This constructor is used to create a new
- * socket, either listening for connections, or an outbound connection to another host.
- * Note that if you specify a hostname in the 'host' parameter, then there will be an extra
- * step involved (a nonblocking DNS lookup) which will cause your connection to be established
- * slower than if it was an IP. Therefore, use an IP address where it is available instead.
- * @param host The hostname to connect to, or bind to
- * @param port The port number to connect to, or bind to
- * @param listening true to listen on the given host:port pair, or false to connect to them
- * @param maxtime Number of seconds to wait, if connecting, before the connection times out and an OnTimeout() event is generated
- */
- InspSocket(std::string host, int port, bool listening, unsigned long maxtime);
-
- /**
- * This method is called when an outbound
- * connection on your socket is completed.
- * @return false to abort the connection, true to continue
- */
- virtual bool OnConnected();
-
- /**
- * This method is called when an error occurs.
- * A closed socket in itself is not an error,
- * however errors also generate close events.
- * @param e The error type which occured
- */
- virtual void OnError(InspSocketError e);
-
- /**
- * When an established connection is terminated,
- * the OnDisconnect method is triggered.
- */
- virtual int OnDisconnect();