From b2723d2577b124d5a3ed188b01136a3eae9e9343 Mon Sep 17 00:00:00 2001 From: w00t Date: Wed, 2 Jul 2008 14:22:48 +0000 Subject: Back out the incomplete linebuffering stuff that shouldn't have been committed.. git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9948 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/linebuffer.h | 110 --------------------------------------------------- include/users.h | 39 ++++++------------ 2 files changed, 13 insertions(+), 136 deletions(-) delete mode 100644 include/linebuffer.h (limited to 'include') diff --git a/include/linebuffer.h b/include/linebuffer.h deleted file mode 100644 index 8b579c452..000000000 --- a/include/linebuffer.h +++ /dev/null @@ -1,110 +0,0 @@ -/* +------------------------------------+ - * | Inspire Internet Relay Chat Daemon | - * +------------------------------------+ - * - * InspIRCd: (C) 2002-2008 InspIRCd Development Team - * See: http://www.inspircd.org/wiki/index.php/Credits - * - * This program is free but copyrighted software; see - * the file COPYING for details. - * - * --------------------------------------------------- - */ - -/** Right, Line Buffers. Time for an explanation as to how sendqs work. By the way, ircd people, - * before you jump up and down screaming, this is not anything like Adrian Chadd's linebuffer - * stuff done for hybrid(and never really completed.) Rather, this is (I think) where linebuffer - * was heading, and should have been. - * - * Enough introduction, actual explanation starts here. - * In IRCd, we have a sendq. Traditionally, a sendq has been a big string. Stuff is tacked onto - * the end, and when we can, we send the user some data off the start of it. A circular buffer. - * - * This model works okay, and is quite simplistic to code, but has a drawback in that most IRC - * messages are multicast: topic changes, joins, parts, channel messages, and so on. - * This means that for each of these messages, we must do O(n^n) amount of work: bytes ^ recipients - * of writes will be made to sendqs, and this is a slow and expensive operation. - * - * The solution comes with the use of this linebuffer class below, which is managed entirely by - * the user class (though it *may* be possible to add a server to server implementation of this later, - * but that's nowhere near so needed, and nowhere near so trivial, thanks to the inherited nature - * of buffered socket, but I digress). - * - * What this class does, in a nutshell: - * When we need to send a message to a user, we create a LineBuffer object. It has a reference count, and - * we copy the string we need to send into the LineBuffer object also. - * We then tack a pointer to this LineBuffer into an std::list stored in the User class. - * When the user writes data, a ptr is advanced depending how much of that line they wrote. If they wrote all - * of the line, the pointer is popped off the std::list, the ptr is reset, and the buffer's refcount is - * decremented - and if it reaches 0, the linebuffer is destroyed as it has fulfilled it's purpose. - * - * Effectively, this means that multicast writes become O(n) + time taken to copy message once, or just about. - * - * We gain efficiency, and much, much better RAM usage. - */ -static unsigned int totalbuffers = 0; - -class LineBuffer -{ - private: - std::string msg; - unsigned long refcount; - - // Don't let it be copied. - LineBuffer(const LineBuffer &) { } - - public: - ~LineBuffer() - { - totalbuffers--; - printf("Destroying LineBuffer with %u bytes, total buffers is %u\n", msg.length(), totalbuffers); - msg.resize(0); - } - - LineBuffer(std::string &m) - { - if (m.length() > MAXBUF - 2) /* MAXBUF has a value of 514, to account for line terminators */ - { - // Trim the message to fit, 510 characters max. - m = m.substr(0, MAXBUF - 4); // MAXBUF is 514, we need 510. - } - - // Add line terminator - m.append("\r\n"); - - // And copy - msg = m; - refcount = 0; - totalbuffers++; - printf("Creating LineBuffer with %u bytes, total buffers is %u\n", msg.length(), totalbuffers); - } - - std::string &GetMessage() - { - return msg; - } - - unsigned long GetMessageLength() - { - return msg.length(); - } - - // To be used after creation, when we know how many recipients we actually have. - void SetRefcount(unsigned long r) - { - refcount = r; - } - - unsigned long DecrementCount() - { - if (refcount == 0) - { - throw "decrementing a refcount when nobody is using it is weird and wrong"; - } - - refcount--; - return refcount; - } - - // There is no increment method as it isn't really needed. -}; diff --git a/include/users.h b/include/users.h index 883fbadf8..f098500e3 100644 --- a/include/users.h +++ b/include/users.h @@ -17,17 +17,12 @@ #include "socket.h" #include "connection.h" #include "dns.h" -#include "mode.h" -#include "linebuffer.h" - -#include // XXX XXX XXX this should probably be moved to globals.h, and globals.h should probably be merged in with inspircd.h sometime. -- w00t -#define _GLIBCXX_FORCE_NEW 1 +#include "mode.h" /** Channel status for a user */ -enum ChanStatus -{ +enum ChanStatus { /** Op */ STATUS_OP = 4, /** Halfop */ @@ -40,8 +35,7 @@ enum ChanStatus /** connect class types */ -enum ClassTypes -{ +enum ClassTypes { /** connect:allow */ CC_ALLOW = 0, /** connect:deny */ @@ -50,8 +44,7 @@ enum ClassTypes /** RFC1459 channel modes */ -enum UserModes -{ +enum UserModes { /** +s: Server notices */ UM_SERVERNOTICE = 's' - 65, /** +w: WALLOPS */ @@ -67,17 +60,16 @@ enum UserModes /** Registration state of a user, e.g. * have they sent USER, NICK, PASS yet? */ -enum RegistrationState -{ -#ifndef REG_NONE /* This is already defined in win32, luckily it is still 0. -- Burlex - XXX perhaps we should undef it just in case.. Relying on magic numbers... -- w00t */ +enum RegistrationState { + +#ifndef WIN32 // Burlex: This is already defined in win32, luckily it is still 0. REG_NONE = 0, /* Has sent nothing */ #endif REG_USER = 1, /* Has sent USER */ REG_NICK = 2, /* Has sent NICK */ REG_NICKUSER = 3, /* Bitwise combination of REG_NICK and REG_USER */ - REG_ALL = 7 /* REG_NICKUSER plus next bit along */ + REG_ALL = 7 /* REG_NICKUSER plus next bit along */ }; /* Required forward declaration */ @@ -606,15 +598,10 @@ class CoreExport User : public connection */ std::string recvq; - /** How many bytes are currently in the user's sendq. - */ - unsigned long sendqlength; - /** List of pointers to buffer objects, this is the actual user's sendq. - */ - std::list > sendq; - /** How far into the current sendq line is the user? + /** User's send queue. + * Lines waiting to be sent are stored here until their buffer is flushed. */ - unsigned long sendqpos; + std::string sendq; /** Message user will quit with. Not to be set externally. */ @@ -856,13 +843,13 @@ class CoreExport User : public connection */ const char* GetWriteError(); - /** Adds a line buffer to the user's sendq. + /** 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. * @param data The data to add to the write buffer */ - void AddWriteBuf(LineBuffer *l); + void AddWriteBuf(const std::string &data); /** Flushes as much of the user's buffer to the file descriptor as possible. * This function may not always flush the entire buffer, rather instead as much of it -- cgit v1.2.3