X-Git-Url: https://git.sesse.net/?p=cubemap;a=blobdiff_plain;f=accesslog.h;fp=accesslog.h;h=66be5a861543244824664a9778a70494bb0e84d9;hp=0000000000000000000000000000000000000000;hb=136469d722a9986be6bbad68788619284919d876;hpb=92100dd95f705d079c926783c9009fbb6d8b984a diff --git a/accesslog.h b/accesslog.h new file mode 100644 index 0000000..66be5a8 --- /dev/null +++ b/accesslog.h @@ -0,0 +1,40 @@ +#ifndef _ACCESSLOG_H +#define _ACCESSLOG_H + +// A class to log clients that just disconnected. Since this is shared by all +// Server instances, we try not to let write() block too much, and rather do +// all the I/O in a separate I/O thread. + +#include + +#include +#include + +#include "client.h" +#include "thread.h" + +class AccessLogThread : public Thread { +public: + // Used if we do not have a file to log to. The thread will still exist, + // but won't actually write anywhere. + AccessLogThread(); + + // Log to a given file. If the file can't be opened, log an error + // to the error log, and work as if we didn't have a log file. + AccessLogThread(const std::string &filename); + + // Add a log entry. Entries are written out at least once every second. + void write(const ClientStats& client); + +private: + virtual void do_work(); + + // The file we are logging to. If NULL, do not log. + FILE *logfp; + std::string filename; + + pthread_mutex_t mutex; + std::vector pending_writes; +}; + +#endif // _ACCESSLOG_H