mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
add: struct timeval in Client class, and lifeTime in Request
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<std::string, std::string> Request::getClientFields(void)
|
||||
{
|
||||
return (_headerField);
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user