ServerThread.h 866 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef SERVERTHREAD_H
  2. #define SERVERTHREAD_H
  3. #include <ctime>
  4. #include <pthread.h>
  5. #include <iostream>
  6. #include <ctime>
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <sys/socket.h>
  10. #include <string.h>
  11. #define BUFFERLENGTH 8192
  12. #define WORKDIR "/tmp"
  13. #define WDLEN 11
  14. #define term "\r\n\r\n"
  15. class ServerThread {
  16. private:
  17. int socket;
  18. pthread_t tid;
  19. std::time_t start;
  20. char buffer[BUFFERLENGTH];
  21. char header[BUFFERLENGTH];
  22. bool marked;
  23. bool serving;
  24. public:
  25. ServerThread(int socket);
  26. virtual ~ServerThread();
  27. void Serve();
  28. void Run();
  29. bool Terminate(bool force);
  30. int GetSocket() {
  31. return this->socket;
  32. }
  33. time_t GetStartTime() {
  34. return this->start;
  35. }
  36. pthread_t GetThreadID() {
  37. return this->tid;
  38. }
  39. void MarkFT() {
  40. marked = true;
  41. }
  42. bool IsMarked() {
  43. return marked;
  44. }
  45. };
  46. #endif // SERVERTHREAD_H