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 * ---------------------------------------------------
17 #include "socketengine.h"
18 #include "inspircd_se_config.h"
19 #include "filelogger.h"
21 FileLogger::FileLogger(InspIRCd* Instance, FILE* logfile)
22 : ServerInstance(Instance), log(logfile), writeops(0)
26 irc::sockets::NonBlocking(fileno(log));
32 bool FileLogger::Readable()
37 void FileLogger::HandleEvent(EventType et, int errornum)
41 ServerInstance->SE->DelFd(this);
44 void FileLogger::WriteLogLine(const std::string &line)
51 int written = fprintf(log,"%s",buffer.c_str());
55 if ((written >= 0) && (written < (int)buffer.length()))
57 buffer.erase(0, buffer.length());
58 ServerInstance->SE->AddFd(this);
60 else if (written == -1)
63 ServerInstance->SE->AddFd(this);
67 /* Wrote the whole buffer, and no need for write callback */
78 void FileLogger::Close()
82 /* Burlex: Windows assumes nonblocking on FILE* pointers anyway, and also "file" fd's aren't the same
86 int flags = fcntl(fileno(log), F_GETFL, 0);
87 fcntl(fileno(log), F_SETFL, flags ^ O_NONBLOCK);
90 fprintf(log,"%s",buffer.c_str());
93 ServerInstance->SE->DelFd(this);
103 FileLogger::~FileLogger()