summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-07-19 19:17:15 +0000
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>2008-07-19 19:17:15 +0000
commite93827e41cdb958314eb669e94c9dd1280b691c9 (patch)
treea2b258edd4693fa0e084d4cbadad12a2c9a12f92
parent1a307616adeef74eddb0e0093b56c8da2195b24c (diff)
Fix compile. Also remove write error stuff, as that was used prior to the goodness of global culllist. This makes getting user's quit messages to them (on excess recvq etc) much easier.
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@10042 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--include/users.h29
-rw-r--r--src/cull_list.cpp2
-rw-r--r--src/inspircd.cpp2
-rw-r--r--src/users.cpp130
4 files changed, 52 insertions, 111 deletions
diff --git a/include/users.h b/include/users.h
index b50023533..39abc6309 100644
--- a/include/users.h
+++ b/include/users.h
@@ -447,6 +447,10 @@ class CoreExport User : public connection
*/
std::string cached_fullrealhost;
+ /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
+ */
+ std::string cachedip;
+
/** When we erase the user (in the destructor),
* we call this method to subtract one from all
* mode characters this user is making use of.
@@ -624,10 +628,6 @@ class CoreExport User : public connection
* GetIPString/GetPort to obtain its values.
*/
sockaddr* ip;
-
- /** Set by GetIPString() to avoid constantly re-grabbing IP via sockets voodoo.
- */
- std::string cachedip;
/** Initialize the clients sockaddr
* @param protocol_family The protocol family of the IP address, AF_INET or AF_INET6
@@ -660,10 +660,6 @@ class CoreExport User : public connection
*/
const char *GetCIDRMask(int range);
- /* Write error string
- */
- std::string WriteError;
-
/** This is true if the user matched an exception (E:Line). It is used to save time on ban checks.
*/
bool exempt;
@@ -829,24 +825,9 @@ class CoreExport User : public connection
*/
std::string GetBuffer();
- /** Sets the write error for a connection. This is done because the actual disconnect
- * of a client may occur at an inopportune time such as half way through /LIST output.
- * The WriteErrors of clients are checked at a more ideal time (in the mainloop) and
- * errored clients purged.
- * @param error The error string to set.
- */
- void SetWriteError(const std::string &error);
-
- /** Returns the write error which last occured on this connection or an empty string
- * if none occured.
- * @return The error string which has occured for this user
- */
- const char* GetWriteError();
-
/** Adds to the user's write buffer.
* You may add any amount of text up to this users sendq value, if you exceed the
- * sendq value, SetWriteError() will be called to set the users error string to
- * "SendQ exceeded", and further buffer adds will be dropped.
+ * sendq value, the user will be removed, and further buffer adds will be dropped.
* @param data The data to add to the write buffer
*/
void AddWriteBuf(const std::string &data);
diff --git a/src/cull_list.cpp b/src/cull_list.cpp
index a7f8d3316..5c7eb7b42 100644
--- a/src/cull_list.cpp
+++ b/src/cull_list.cpp
@@ -63,7 +63,7 @@ int CullList::Apply()
if (IS_LOCAL(u))
{
- if ((!u->sendq.empty()) && (!(*u->GetWriteError())))
+ if (!u->sendq.empty())
u->FlushWriteBuf();
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index ac5ee4510..1d8ce7625 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -95,7 +95,7 @@ void InspIRCd::Cleanup()
/* Close all client sockets, or the new process inherits them */
for (std::vector<User*>::const_iterator i = this->Users->local_users.begin(); i != this->Users->local_users.end(); i++)
{
- (*i)->SetWriteError("Server shutdown");
+ this->Users->QuitUser((*i), "Server shutdown");
(*i)->CloseSocket();
}
diff --git a/src/users.cpp b/src/users.cpp
index f7b646754..a0ed42446 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -190,12 +190,11 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance
age = ServerInstance->Time();
Penalty = 0;
lines_in = lastping = signon = idle_lastmsg = nping = registered = 0;
- ChannelCount = timeout = bytes_in = bytes_out = cmds_in = cmds_out = 0;
+ bytes_in = bytes_out = cmds_in = cmds_out = 0;
quietquit = OverPenalty = ExemptFromPenalty = quitting = exempt = haspassed = dns_done = false;
fd = -1;
recvq.clear();
sendq.clear();
- WriteError.clear();
res_forward = res_reverse = NULL;
Visibility = NULL;
ip = NULL;
@@ -560,7 +559,7 @@ bool User::AddBuffer(const std::string &a)
if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax()))
{
- this->SetWriteError("RecvQ exceeded");
+ ServerInstance->Users->QuitUser(this, "RecvQ exceeded");
ServerInstance->SNO->WriteToSnoMask('A', "User %s RecvQ of %lu exceeds connect class maximum of %lu",this->nick.c_str(),(unsigned long int)recvq.length(),this->MyClass->GetRecvqMax());
return false;
}
@@ -620,7 +619,7 @@ std::string User::GetBuffer()
void User::AddWriteBuf(const std::string &data)
{
- if (*this->GetWriteError())
+ if (this->quitting)
return;
if (this->MyClass && (sendq.length() + data.length() > this->MyClass->GetSendqMax()))
@@ -630,7 +629,7 @@ void User::AddWriteBuf(const std::string &data)
* if we dont it'll recursively call here over and over again trying
* to repeatedly add the text to the sendq!
*/
- this->SetWriteError("SendQ exceeded");
+ ServerInstance->Users->QuitUser(this, "SendQ exceeded");
ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ of %lu exceeds connect class maximum of %lu",this->nick.c_str(),(unsigned long int)sendq.length() + data.length(),this->MyClass->GetSendqMax());
return;
}
@@ -644,71 +643,53 @@ void User::AddWriteBuf(const std::string &data)
// send AS MUCH OF THE USERS SENDQ as we are able to (might not be all of it)
void User::FlushWriteBuf()
{
- try
+ if (this->fd == FD_MAGIC_NUMBER)
{
- if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
- {
- sendq.clear();
- }
- if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
- {
- int old_sendq_length = sendq.length();
- int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
+ sendq.clear();
+ return;
+ }
- if (n_sent == -1)
+ if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
+ {
+ int old_sendq_length = sendq.length();
+ int n_sent = ServerInstance->SE->Send(this, this->sendq.data(), this->sendq.length(), 0);
+
+ if (n_sent == -1)
+ {
+ if (errno == EAGAIN)
{
- if (errno == EAGAIN)
- {
- /* The socket buffer is full. This isnt fatal,
- * try again later.
- */
- this->ServerInstance->SE->WantWrite(this);
- }
- else
- {
- /* Fatal error, set write error and bail
- */
- this->SetWriteError(errno ? strerror(errno) : "EOF from client");
- return;
- }
+ /* The socket buffer is full. This isnt fatal,
+ * try again later.
+ */
+ ServerInstance->SE->WantWrite(this);
}
else
{
- /* advance the queue */
- if (n_sent)
- this->sendq = this->sendq.substr(n_sent);
- /* update the user's stats counters */
- this->bytes_out += n_sent;
- this->cmds_out++;
- if (n_sent != old_sendq_length)
- this->ServerInstance->SE->WantWrite(this);
+ /* Fatal error, set write error and bail */
+ ServerInstance->Users->QuitUser(this, errno ? strerror(errno) : "Write error");
+ return;
}
}
+ else
+ {
+ /* advance the queue */
+ if (n_sent)
+ this->sendq = this->sendq.substr(n_sent);
+ /* update the user's stats counters */
+ this->bytes_out += n_sent;
+ this->cmds_out++;
+ if (n_sent != old_sendq_length)
+ this->ServerInstance->SE->WantWrite(this);
+ }
}
- catch (...)
- {
- ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::FlushWriteBuf()");
- }
-
+ /* note: NOT else if! */
if (this->sendq.empty())
{
FOREACH_MOD(I_OnBufferFlushed,OnBufferFlushed(this));
}
}
-void User::SetWriteError(const std::string &error)
-{
- // don't try to set the error twice, its already set take the first string.
- if (this->WriteError.empty())
- this->WriteError = error;
-}
-
-const char* User::GetWriteError()
-{
- return this->WriteError.c_str();
-}
-
void User::Oper(const std::string &opertype, const std::string &opername)
{
char* mycmd;
@@ -882,7 +863,6 @@ void User::CheckClass()
}
this->nping = ServerInstance->Time() + a->GetPingTime() + ServerInstance->Config->dns_timeout;
- this->timeout = ServerInstance->Time() + a->GetRegTimeout();
this->MaxChans = a->GetMaxChans();
}
@@ -1979,37 +1959,17 @@ void User::HandleEvent(EventType et, int errornum)
if (this->quitting) // drop everything, user is due to be quit
return;
- /* WARNING: May delete this user! */
- int thisfd = this->GetFd();
-
- try
+ switch (et)
{
- switch (et)
- {
- case EVENT_READ:
- ServerInstance->ProcessUser(this);
- break;
- case EVENT_WRITE:
- this->FlushWriteBuf();
- break;
- case EVENT_ERROR:
- /** This should be safe, but dont DARE do anything after it -- Brain */
- this->SetWriteError(errornum ? strerror(errornum) : "EOF from client");
- break;
- }
- }
- catch (...)
- {
- ServerInstance->Logs->Log("USERS", DEBUG,"Exception in User::HandleEvent intercepted");
- }
-
- /* If the user has raised an error whilst being processed, quit them now we're safe to */
- if ((ServerInstance->SE->GetRef(thisfd) == this))
- {
- if (!WriteError.empty())
- {
- ServerInstance->Users->QuitUser(this, GetWriteError());
- }
+ case EVENT_READ:
+ ServerInstance->ProcessUser(this);
+ break;
+ case EVENT_WRITE:
+ this->FlushWriteBuf();
+ break;
+ case EVENT_ERROR:
+ ServerInstance->Users->QuitUser(this, errornum ? strerror(errornum) : "Client closed the connection");
+ break;
}
}