mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 13:27: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/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,22 @@ bool Client::isEmpty(void)
|
|||||||
return (false);
|
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)
|
void Client::clear(void)
|
||||||
{
|
{
|
||||||
_fd = -1;
|
_fd = -1;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ private:
|
|||||||
private:
|
private:
|
||||||
int _ret;
|
int _ret;
|
||||||
int _fd;
|
int _fd;
|
||||||
|
struct timeval _time;
|
||||||
unsigned int _sended;
|
unsigned int _sended;
|
||||||
char *_buff;
|
char *_buff;
|
||||||
|
|
||||||
@@ -39,7 +40,8 @@ public:
|
|||||||
int getFd(void);
|
int getFd(void);
|
||||||
unsigned int getRecvCounter(void) const;
|
unsigned int getRecvCounter(void) const;
|
||||||
bool isEmpty(void);
|
bool isEmpty(void);
|
||||||
|
bool TimeToDie(void);
|
||||||
|
void updateTimeToDie(void);
|
||||||
public:
|
public:
|
||||||
int parseRequest(void);
|
int parseRequest(void);
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ Request::Request()
|
|||||||
_body_ok = false;
|
_body_ok = false;
|
||||||
_received = 0;
|
_received = 0;
|
||||||
_headerSize = 0;
|
_headerSize = 0;
|
||||||
|
_lifeTime = 5;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ Request::Request(char *str)
|
|||||||
_chunked = false;
|
_chunked = false;
|
||||||
_contentLength = 0;
|
_contentLength = 0;
|
||||||
_headerSize = 0;
|
_headerSize = 0;
|
||||||
|
_lifeTime = 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------Get/Set---------------------------------------
|
//-------------------------------------------------Get/Set---------------------------------------
|
||||||
@@ -74,6 +76,10 @@ int Request::getCode(void)
|
|||||||
{
|
{
|
||||||
return (_ret);
|
return (_ret);
|
||||||
}
|
}
|
||||||
|
int Request::getLifeTime(void)
|
||||||
|
{
|
||||||
|
return (_lifeTime);
|
||||||
|
}
|
||||||
std::map<std::string, std::string> Request::getClientFields(void)
|
std::map<std::string, std::string> Request::getClientFields(void)
|
||||||
{
|
{
|
||||||
return (_headerField);
|
return (_headerField);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ private:
|
|||||||
|
|
||||||
int _ret;
|
int _ret;
|
||||||
int _row;
|
int _row;
|
||||||
|
int _lifeTime;
|
||||||
unsigned int _contentLength;
|
unsigned int _contentLength;
|
||||||
unsigned int _received;
|
unsigned int _received;
|
||||||
unsigned int _headerSize;
|
unsigned int _headerSize;
|
||||||
@@ -44,6 +45,7 @@ public:
|
|||||||
std::string getConnection(void);
|
std::string getConnection(void);
|
||||||
ServerConfig *getConfig(void);
|
ServerConfig *getConfig(void);
|
||||||
int getCode(void);
|
int getCode(void);
|
||||||
|
int getLifeTime(void);
|
||||||
unsigned int getContentLength(void) const;
|
unsigned int getContentLength(void) const;
|
||||||
unsigned int getHeaderSize(void) const;
|
unsigned int getHeaderSize(void) const;
|
||||||
unsigned int getRecved(void)const;
|
unsigned int getRecved(void)const;
|
||||||
|
|||||||
Reference in New Issue
Block a user