1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
18 #include "socketengine.h"
19 #include "inspircd_se_config.h"
20 #include "filelogger.h"
22 FileLogger::FileLogger(InspIRCd* Instance, FILE* logfile)
23 : ServerInstance(Instance), log(logfile), writeops(0)
27 irc::sockets::NonBlocking(fileno(log));
33 bool FileLogger::Readable()
38 void FileLogger::HandleEvent(EventType et, int errornum)
42 ServerInstance->SE->DelFd(this);
45 void FileLogger::WriteLogLine(const std::string &line)
52 int written = fprintf(log,"%s",buffer.c_str());
56 if ((written >= 0) && (written < (int)buffer.length()))
58 buffer.erase(0, buffer.length());
59 ServerInstance->SE->AddFd(this);
61 else if (written == -1)
64 ServerInstance->SE->AddFd(this);
68 /* Wrote the whole buffer, and no need for write callback */
79 void FileLogger::Close()
83 /* Burlex: Windows assumes nonblocking on FILE* pointers anyway, and also "file" fd's aren't the same
87 int flags = fcntl(fileno(log), F_GETFL, 0);
88 fcntl(fileno(log), F_SETFL, flags ^ O_NONBLOCK);
91 fprintf(log,"%s",buffer.c_str());
94 ServerInstance->SE->DelFd(this);
104 FileLogger::~FileLogger()