add: struct timeval in Client class, and lifeTime in Request

This commit is contained in:
Talyx
2022-02-01 18:34:50 +03:00
parent f8343098e8
commit 0efe9d1bc3
5 changed files with 28 additions and 1 deletions

View File

@@ -27,6 +27,7 @@
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <sys/time.h>
#include <arpa/inet.h>

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);

View File

@@ -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;