added TcpConnection::fileno() to expose the internal filedescriptor / socket

This commit is contained in:
Emiel Bruijntjes 2017-12-12 17:10:51 +01:00
parent c63f62189e
commit f05aba0782
4 changed files with 28 additions and 0 deletions

View File

@ -117,6 +117,12 @@ public:
*/ */
virtual ~TcpConnection() noexcept {} virtual ~TcpConnection() noexcept {}
/**
* The filedescriptor that is used for this connection
* @return int
*/
int fileno() const;
/** /**
* Process the TCP connection * Process the TCP connection
* *

View File

@ -143,6 +143,12 @@ public:
close(_socket); close(_socket);
} }
/**
* The filedescriptor of this connection
* @return int
*/
virtual int fileno() const override { return _socket; }
/** /**
* Process the filedescriptor in the object * Process the filedescriptor in the object
* @param fd Filedescriptor that is active * @param fd Filedescriptor that is active

View File

@ -27,6 +27,16 @@ TcpConnection::TcpConnection(TcpHandler *handler, const Address &address) :
_state(new TcpResolver(this, address.hostname(), address.port(), handler)), _state(new TcpResolver(this, address.hostname(), address.port(), handler)),
_connection(this, address.login(), address.vhost()) {} _connection(this, address.login(), address.vhost()) {}
/**
* The filedescriptor that is used for this connection
* @return int
*/
int TcpConnection::fileno() const
{
// pass on to the state object
return _state->fileno();
}
/** /**
* Process the TCP connection * Process the TCP connection
* This method should be called when the filedescriptor that is registered * This method should be called when the filedescriptor that is registered

View File

@ -57,6 +57,12 @@ public:
*/ */
virtual ~TcpState() = default; virtual ~TcpState() = default;
/**
* The filedescriptor of this connection
* @return int
*/
virtual int fileno() const { return -1; }
/** /**
* Process the filedescriptor in the object * Process the filedescriptor in the object
* @param fd The filedescriptor that is active * @param fd The filedescriptor that is active