- /**
- * 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 IP address being connected
- * to stored in string form for
- * easy retrieval by accessors.
- */
- char IP[MAXBUF];
-
- /**
- * 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
- */
- bool FlushWriteBuffer();
-
- /** Set the queue sizes
- * This private method sets the operating system queue
- * sizes for this socket to 65535 so that it can queue
- * more information without application-level queueing
- * which was required in older software.
- */
- void SetQueues(int nfd);
-
- /** When the socket has been marked as closing, this flag
- * will be set to true, then the next time the socket is
- * examined, the socket is deleted and closed.
- */
- bool ClosePending;
-
-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(const 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();
-
- /**
- * When there is data waiting to be read on a
- * socket, the OnDataReady() method is called.
- * Within this method, you *MUST* call 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.
- * @return false to close the socket
- */
- virtual bool OnDataReady();