~ubuntu-branches/ubuntu/vivid/cubemap/vivid

« back to all changes in this revision

Viewing changes to accesslog.h

  • Committer: Package Import Robot
  • Author(s): Philipp Kern
  • Date: 2013-09-15 18:23:09 UTC
  • Revision ID: package-import@ubuntu.com-20130915182309-53isxcvl9z3792s6
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#ifndef _ACCESSLOG_H
 
2
#define _ACCESSLOG_H
 
3
 
 
4
// A class to log clients that just disconnected. Since this is shared by all
 
5
// Server instances, we try not to let write() block too much, and rather do
 
6
// all the I/O in a separate I/O thread.
 
7
 
 
8
#include <pthread.h>
 
9
#include <stdio.h>
 
10
#include <string>
 
11
#include <vector>
 
12
 
 
13
#include "client.h"
 
14
#include "thread.h"
 
15
 
 
16
class AccessLogThread : public Thread {
 
17
public:
 
18
        // Used if we do not have a file to log to. The thread will still exist,
 
19
        // but won't actually write anywhere.
 
20
        AccessLogThread();
 
21
 
 
22
        // Log to a given file. If the file can't be opened, log an error
 
23
        // to the error log, and work as if we didn't have a log file.
 
24
        AccessLogThread(const std::string &filename);
 
25
 
 
26
        // Add a log entry. Entries are written out at least once every second.
 
27
        void write(const ClientStats& client);
 
28
 
 
29
private:
 
30
        virtual void do_work();
 
31
 
 
32
        // The file we are logging to. If NULL, do not log.
 
33
        FILE *logfp;
 
34
        std::string filename;
 
35
 
 
36
        pthread_mutex_t mutex;
 
37
        std::vector<ClientStats> pending_writes;
 
38
};
 
39
 
 
40
#endif  // _ACCESSLOG_H