*/
inline int GetFd() const { return fd; }
+ /** Checks if this event handler has a fd associated with it. */
+ inline bool HasFd() const { return fd >= 0; }
+
inline int GetEventMask() const { return event_mask; }
/** Set a new file desciptor
void Rehash(const std::string& dnsserver, std::string sourceaddr, unsigned int sourceport)
{
- if (this->GetFd() > -1)
+ if (this->HasFd())
{
SocketEngine::Shutdown(this, 2);
SocketEngine::Close(this);
ListenSocket::~ListenSocket()
{
- if (this->GetFd() > -1)
+ if (this->HasFd())
{
ServerInstance->Logs->Log("SOCKET", LOG_DEBUG, "Shut down listener on fd %d", this->fd);
SocketEngine::Shutdown(this, 2);
/* Remove ident socket from engine, and close it, but dont detatch it
* from its parent user class, or attempt to delete its memory.
*/
- if (GetFd() > -1)
+ if (HasFd())
{
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Close ident socket %d", GetFd());
SocketEngine::Close(this);
{
// Create a TreeServer object that will start connecting immediately in the background
TreeSocket* newsocket = new TreeSocket(x, y, sa);
- if (newsocket->GetFd() > -1)
- {
- /* Handled automatically on success */
- }
- else
+ if (!newsocket->HasFd())
{
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
x->Name.c_str(), newsocket->getError().c_str());
if (!CheckDupe) /* Check that nobody tried to connect it successfully while we were resolving */
{
TreeSocket* newsocket = new TreeSocket(MyLink, myautoconnect, sa);
- if (newsocket->GetFd() > -1)
- {
- /* We're all OK */
- }
- else
+ if (!newsocket->HasFd())
{
/* Something barfed, show the opers */
ServerInstance->SNO->WriteToSnoMask('l', "CONNECT: Error connecting \002%s\002: %s.",
}
ListenSocket* ll = new ListenSocket(tag, sa);
- if (ll->GetFd() < 0)
+ if (!ll->HasFd())
{
ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "Failed to listen on %s from tag at %s: %s",
sa.str().c_str(), tag->getTagLocation().c_str(), strerror(errno));
bool SocketEngine::BoundsCheckFd(EventHandler* eh)
{
- if (!eh)
- return false;
- if (eh->GetFd() < 0)
- return false;
- return true;
+ return eh && eh->HasFd();
}