mirror of
https://github.com/inspircd/inspircd.git
synced 2025-03-09 18:49:03 -04:00
DelFd should not fail, it will leave a bad dangling pointer in that case
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@12584 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
parent
ac83d3b0d6
commit
a018f26edd
@ -302,18 +302,9 @@ public:
|
||||
* and false if it failed. This does not free the
|
||||
* EventHandler pointer using delete, if this is
|
||||
* required you must do this yourself.
|
||||
* Note on forcing deletes. DO NOT DO THIS! This is
|
||||
* extremely dangerous and will most likely render the
|
||||
* socketengine dead. This was added only for handling
|
||||
* very rare cases where broken 3rd party libs destroys
|
||||
* the OS socket beyond our control. If you can't explain
|
||||
* in minute details why forcing is absolutely necessary
|
||||
* then you don't need it. That was a NO!
|
||||
* @param eh The event handler object to remove
|
||||
* @param force *DANGEROUS* See method description!
|
||||
* @return True if the event handler was removed
|
||||
*/
|
||||
virtual bool DelFd(EventHandler* eh, bool force = false) = 0;
|
||||
virtual void DelFd(EventHandler* eh) = 0;
|
||||
|
||||
/** Returns true if a file descriptor exists in
|
||||
* the socket engine's list.
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
virtual ~EPollEngine();
|
||||
virtual bool AddFd(EventHandler* eh, int event_mask);
|
||||
virtual void OnSetEvent(EventHandler* eh, int old_mask, int new_mask);
|
||||
virtual bool DelFd(EventHandler* eh, bool force = false);
|
||||
virtual void DelFd(EventHandler* eh);
|
||||
virtual int DispatchEvents();
|
||||
virtual std::string GetName();
|
||||
};
|
||||
@ -155,13 +155,13 @@ void EPollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
|
||||
}
|
||||
}
|
||||
|
||||
bool EPollEngine::DelFd(EventHandler* eh, bool force)
|
||||
void EPollEngine::DelFd(EventHandler* eh)
|
||||
{
|
||||
int fd = eh->GetFd();
|
||||
if ((fd < 0) || (fd > GetMaxFds() - 1))
|
||||
{
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
struct epoll_event ev;
|
||||
@ -169,17 +169,15 @@ bool EPollEngine::DelFd(EventHandler* eh, bool force)
|
||||
ev.data.fd = fd;
|
||||
int i = epoll_ctl(EngineHandle, EPOLL_CTL_DEL, fd, &ev);
|
||||
|
||||
if (i < 0 && !force)
|
||||
if (i < 0)
|
||||
{
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"Cant remove socket: %s", strerror(errno));
|
||||
return false;
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"epoll_ctl can't remove socket: %s", strerror(errno));
|
||||
}
|
||||
|
||||
ref[fd] = NULL;
|
||||
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
|
||||
CurrentSetSize--;
|
||||
return true;
|
||||
}
|
||||
|
||||
int EPollEngine::DispatchEvents()
|
||||
|
@ -39,7 +39,7 @@ public:
|
||||
virtual ~KQueueEngine();
|
||||
bool AddFd(EventHandler* eh, int event_mask);
|
||||
void OnSetEvent(EventHandler* eh, int old_mask, int new_mask);
|
||||
virtual bool DelFd(EventHandler* eh, bool force = false);
|
||||
virtual bool DelFd(EventHandler* eh);
|
||||
virtual int DispatchEvents();
|
||||
virtual std::string GetName();
|
||||
virtual void RecoverFromFork();
|
||||
@ -127,14 +127,14 @@ bool KQueueEngine::AddFd(EventHandler* eh, int event_mask)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KQueueEngine::DelFd(EventHandler* eh, bool force)
|
||||
void KQueueEngine::DelFd(EventHandler* eh)
|
||||
{
|
||||
int fd = eh->GetFd();
|
||||
|
||||
if ((fd < 0) || (fd > GetMaxFds() - 1))
|
||||
{
|
||||
ServerInstance->Logs->Log("SOCKET",DEFAULT,"DelFd() on invalid fd: %d", fd);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
struct kevent ke;
|
||||
@ -148,18 +148,16 @@ bool KQueueEngine::DelFd(EventHandler* eh, bool force)
|
||||
EV_SET(&ke, eh->GetFd(), EVFILT_READ, EV_DELETE, 0, 0, NULL);
|
||||
int j = kevent(EngineHandle, &ke, 1, 0, 0, NULL);
|
||||
|
||||
if ((j < 0) && !force)
|
||||
if (j < 0)
|
||||
{
|
||||
ServerInstance->Logs->Log("SOCKET",DEFAULT,"Failed to remove fd: %d %s",
|
||||
fd, strerror(errno));
|
||||
return false;
|
||||
}
|
||||
|
||||
CurrentSetSize--;
|
||||
ref[fd] = NULL;
|
||||
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
void KQueueEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
|
||||
|
@ -59,7 +59,7 @@ public:
|
||||
virtual bool AddFd(EventHandler* eh, int event_mask);
|
||||
virtual void OnSetEvent(EventHandler* eh, int old_mask, int new_mask);
|
||||
virtual EventHandler* GetRef(int fd);
|
||||
virtual bool DelFd(EventHandler* eh, bool force = false);
|
||||
virtual void DelFd(EventHandler* eh);
|
||||
virtual int DispatchEvents();
|
||||
virtual std::string GetName();
|
||||
};
|
||||
@ -168,20 +168,20 @@ void PollEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
|
||||
events[it->second].events = mask_to_poll(new_mask);
|
||||
}
|
||||
|
||||
bool PollEngine::DelFd(EventHandler* eh, bool force)
|
||||
void PollEngine::DelFd(EventHandler* eh)
|
||||
{
|
||||
int fd = eh->GetFd();
|
||||
if ((fd < 0) || (fd > MAX_DESCRIPTORS))
|
||||
{
|
||||
ServerInstance->Logs->Log("SOCKET", DEBUG, "DelFd out of range: (fd: %d, max: %d)", fd, GetMaxFds());
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
std::map<int, unsigned int>::iterator it = fd_mappings.find(fd);
|
||||
if (it == fd_mappings.end())
|
||||
{
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"DelFd() on unknown fd: %d", fd);
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int index = it->second;
|
||||
@ -213,7 +213,6 @@ bool PollEngine::DelFd(EventHandler* eh, bool force)
|
||||
|
||||
ServerInstance->Logs->Log("SOCKET", DEBUG, "Remove file descriptor: %d (index: %d) "
|
||||
"(Filled gap with: %d (index: %d))", fd, index, last_fd, last_index);
|
||||
return true;
|
||||
}
|
||||
|
||||
int PollEngine::DispatchEvents()
|
||||
|
@ -48,7 +48,7 @@ public:
|
||||
virtual ~PortsEngine();
|
||||
virtual bool AddFd(EventHandler* eh, int event_mask);
|
||||
void OnSetEvent(EventHandler* eh, int old_event, int new_event);
|
||||
virtual bool DelFd(EventHandler* eh, bool force = false);
|
||||
virtual void DelFd(EventHandler* eh);
|
||||
virtual int DispatchEvents();
|
||||
virtual std::string GetName();
|
||||
virtual void WantWrite(EventHandler* eh);
|
||||
@ -131,11 +131,11 @@ void PortsEngine::WantWrite(EventHandler* eh, int old_mask, int new_mask)
|
||||
port_associate(EngineHandle, PORT_SOURCE_FD, eh->GetFd(), mask_to_events(new_mask), eh);
|
||||
}
|
||||
|
||||
bool PortsEngine::DelFd(EventHandler* eh, bool force)
|
||||
void PortsEngine::DelFd(EventHandler* eh)
|
||||
{
|
||||
int fd = eh->GetFd();
|
||||
if ((fd < 0) || (fd > GetMaxFds() - 1))
|
||||
return false;
|
||||
return;
|
||||
|
||||
port_dissociate(EngineHandle, PORT_SOURCE_FD, fd);
|
||||
|
||||
|
@ -32,7 +32,7 @@ public:
|
||||
*/
|
||||
virtual ~SelectEngine();
|
||||
virtual bool AddFd(EventHandler* eh, int event_mask);
|
||||
virtual bool DelFd(EventHandler* eh, bool force = false);
|
||||
virtual void DelFd(EventHandler* eh);
|
||||
void OnSetEvent(EventHandler* eh, int, int);
|
||||
virtual int DispatchEvents();
|
||||
virtual std::string GetName();
|
||||
@ -69,18 +69,17 @@ bool SelectEngine::AddFd(EventHandler* eh, int event_mask)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SelectEngine::DelFd(EventHandler* eh, bool force)
|
||||
void SelectEngine::DelFd(EventHandler* eh)
|
||||
{
|
||||
int fd = eh->GetFd();
|
||||
|
||||
if ((fd < 0) || (fd > GetMaxFds() - 1))
|
||||
return false;
|
||||
return;
|
||||
|
||||
CurrentSetSize--;
|
||||
ref[fd] = NULL;
|
||||
|
||||
ServerInstance->Logs->Log("SOCKET",DEBUG,"Remove file descriptor: %d", fd);
|
||||
return true;
|
||||
}
|
||||
|
||||
void SelectEngine::OnSetEvent(EventHandler* eh, int old_mask, int new_mask)
|
||||
|
@ -195,22 +195,7 @@ void UserManager::QuitUser(User *user, const std::string &quitreason, const char
|
||||
{
|
||||
LocalUser* lu = IS_LOCAL(user);
|
||||
FOREACH_MOD(I_OnUserDisconnect,OnUserDisconnect(lu));
|
||||
UserIOHandler* eh = &lu->eh;
|
||||
eh->DoWrite();
|
||||
if (eh->GetIOHook())
|
||||
{
|
||||
try
|
||||
{
|
||||
eh->GetIOHook()->OnStreamSocketClose(eh);
|
||||
}
|
||||
catch (CoreException& modexcept)
|
||||
{
|
||||
ServerInstance->Logs->Log("USERS",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
|
||||
}
|
||||
}
|
||||
|
||||
ServerInstance->SE->DelFd(eh);
|
||||
eh->Close();
|
||||
lu->eh.Close();
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user