00001
00002
00003 #ifndef BASE_WORKERTHREAD_H
00004 #define BASE_WORKERTHREAD_H
00005
00006 #include <ctime>
00007 #include "MTSocketDaemon.h"
00008 #include "Log.h"
00009 #include "Mutex.h"
00010 #include "Socket.h"
00011 #include "Thread.h"
00012 #include "WorkPile.h"
00013
00014 namespace base {
00016
00020 class PPBASE_EXPORT WorkerThread: public Thread, public Mutex {
00021 public:
00023
00028 WorkerThread(MTSocketDaemon *daemon, time_t lifetime = 0, bool web = false);
00029
00031 ~WorkerThread();
00032
00034
00037 time_t getLifetime() const;
00038
00040
00043 Log *getLog();
00044
00046
00052 void getStatus(int *status, String &request, String &addr, u_longlong_t *tv);
00053
00055
00058 bool isAuxiliary() const;
00059
00061
00064 bool isWeb() const;
00065
00067 void run();
00068
00070 void run(Socket *sock);
00071
00072 protected:
00074 virtual void config();
00075
00077 virtual void handle() = 0;
00078
00080 bool readln(String &buf, bool strip = false);
00081
00083
00089 void setStatus(int status, const String &request, const String &addr, u_longlong_t tv = 0);
00090
00092 void write(const String &s);
00093
00095 void writef(const char *fmt, ...)
00096 #ifdef __GNUC__
00097 __attribute__((format(printf, 2, 3)))
00098 #endif
00099 ;
00100
00101 String _addr;
00102 MTSocketDaemon *_daemon;
00103 time_t _lifetime;
00104 Log *_log;
00105 WorkPile<Socket*> *_queue;
00106 Socket *_sock;
00107 int _status;
00108 String _status_addr;
00109 String _status_request;
00110 u_longlong_t _status_time;
00111 int _timeout;
00112 bool _web;
00113 };
00114 }
00115
00116 #endif