File: accesslog.h

package info (click to toggle)
cubemap 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 428 kB
  • sloc: cpp: 4,431; sh: 114; perl: 102; makefile: 60
file content (40 lines) | stat: -rw-r--r-- 1,053 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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 <pthread.h>
#include <stdio.h>
#include <string>
#include <vector>

#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<ClientStats> pending_writes;
};

#endif  // _ACCESSLOG_H