diff --git a/includes/webserv.hpp b/includes/webserv.hpp index 8fbdda7..8639449 100644 --- a/includes/webserv.hpp +++ b/includes/webserv.hpp @@ -27,6 +27,7 @@ #include #include #include +#include #include diff --git a/src/Client/Client.cpp b/src/Client/Client.cpp index ba0603a..cda7671 100644 --- a/src/Client/Client.cpp +++ b/src/Client/Client.cpp @@ -195,6 +195,22 @@ bool Client::isEmpty(void) return (false); } +bool Client::TimeToDie(void) +{ + struct timeval curTime; + + gettimeofday(&curTime, NULL); + if ((curTime.tv_sec - _time.tv_sec) >= _request.getLifeTime()) + return (true); + else + return (false); +} + +void Client::updateTimeToDie(void) +{ + gettimeofday(&_time, NULL); +} + void Client::clear(void) { _fd = -1; diff --git a/src/Client/Client.hpp b/src/Client/Client.hpp index 65a0857..dcd92c5 100644 --- a/src/Client/Client.hpp +++ b/src/Client/Client.hpp @@ -17,6 +17,7 @@ private: private: int _ret; int _fd; + struct timeval _time; unsigned int _sended; char *_buff; @@ -39,7 +40,8 @@ public: int getFd(void); unsigned int getRecvCounter(void) const; bool isEmpty(void); - + bool TimeToDie(void); + void updateTimeToDie(void); public: int parseRequest(void); diff --git a/src/Client/Request.cpp b/src/Client/Request.cpp index e1201bb..8e78362 100644 --- a/src/Client/Request.cpp +++ b/src/Client/Request.cpp @@ -12,6 +12,7 @@ Request::Request() _body_ok = false; _received = 0; _headerSize = 0; + _lifeTime = 5; } @@ -26,6 +27,7 @@ Request::Request(char *str) _chunked = false; _contentLength = 0; _headerSize = 0; + _lifeTime = 5; } //-------------------------------------------------Get/Set--------------------------------------- @@ -74,6 +76,10 @@ int Request::getCode(void) { return (_ret); } +int Request::getLifeTime(void) +{ + return (_lifeTime); +} std::map Request::getClientFields(void) { return (_headerField); diff --git a/src/Client/Request.hpp b/src/Client/Request.hpp index b0441d5..c68f1e2 100644 --- a/src/Client/Request.hpp +++ b/src/Client/Request.hpp @@ -12,6 +12,7 @@ private: int _ret; int _row; + int _lifeTime; unsigned int _contentLength; unsigned int _received; unsigned int _headerSize; @@ -44,6 +45,7 @@ public: std::string getConnection(void); ServerConfig *getConfig(void); int getCode(void); + int getLifeTime(void); unsigned int getContentLength(void) const; unsigned int getHeaderSize(void) const; unsigned int getRecved(void)const;