- /** Create an outbound connection to a listening socket
- */
- bool MakeOutboundConnection(char* newhost, int newport);
-
- /** Return the servername on this established connection
- */
- std::string GetServerName();
-
- /** Set the server name of this connection
- */
- void SetServerName(std::string serv);
-
- /** Get the file descriptor associated with this connection
- */
- int GetDescriptor();
-
- /** Set the file descriptor for this connection
- */
- void SetDescriptor(int fd);
-
- /** Get the state flags for this connection
- */
- int GetState();
-
- /** Set the state flags for this connection
- */
- void SetState(int state);
-
- /** Get the ip address (not servername) associated with this connection
- */
- char* GetServerIP();
-
- /** Get the server description of this connection
- */
- std::string GetDescription();
-
- /** Set the server description of this connection
- */
- void SetDescription(std::string desc);
-
- /** Get the port number being used for this connection
- * If the connection is outbound this will be the remote port
- * otherwise it will be the local port, so it can always be
- * gautanteed as open at the address given in GetServerIP().
- */
- int GetServerPort();
-
- /** Set the port used by this connection
- */
- void SetServerPort(int p);
-
- /** Set both the host and the port in one operation for this connection
- */
- bool SetHostAndPort(char* newhost, int newport);
-
- /** Close the connection by calling close() on its file descriptor
- * This function call updates no other data.
- */
- void CloseConnection();
-
- /** This method adds text to the ircd connection's buffer
- * This buffer's maximum size is one megabyte, the method returning false
- * if the buffer is full.
- */
- bool AddBuffer(std::string a);
-
- /** This method returns true if the buffer contains at least one
- * carriage return character, e.g. one line can be read from the
- * buffer successfully.
- */
- bool BufferIsComplete();
-
- /** This method clears the server's buffer by setting it to an empty string.
- */
- void ClearBuffer();
-
- /** This method retrieves the first string from the tail end of the
- * buffer and advances the tail end of the buffer past the returned
- * string, in a similar manner to strtok().
- */
- std::string GetBuffer();
-
- /** This method sets the version string of the remote server
- */
- void SetVersionString(std::string newversion);
-
- /** This method returns the version string of the remote server.
- * If the server has no version string an empty string is returned.
- */
- std::string GetVersionString();
-
- /** Adds data to the connection's sendQ to be flushed later
- * Fails if there is an error pending on the connection.
- */
- bool AddWriteBuf(std::string data);
-
- /** Flushes as much of the data from the buffer as possible,
- * and advances the queue pointer to what is left.
- */
- bool FlushWriteBuf();
-
- /** Sets the error string for this connection
- */
- void SetWriteError(std::string error);
-
- /** Gets the error string for this connection
- */
- std::string GetWriteError();
-
- /** Returns true if there is data to be written that hasn't been sent yet
- */
- bool HasBufferedOutput();
-
- /** Checks if the connection replied to its last ping, and if it did
- * sends another and returns true, if not, returns false.
- */
- bool CheckPing();
-
- /** Resets the ping counter
- */
- void ResetPing();
-};
-
-
-/** Please note: classes serverrec and userrec both inherit from class connection.
- */
-class connection : public Extensible
-{
- public:
- /** File descriptor of the connection
- */
- int fd;
-
- /** Hostname of connection. Not used if this is a serverrec
- */
- char host[160];
-
- /** IP of connection.
- */
- char ip[16];
-