mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-29 05:17:59 +03:00
feat: add recvCounter, allRecved
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
Client::Client()
|
Client::Client()
|
||||||
{
|
{
|
||||||
allRead = false;
|
allRead = false;
|
||||||
|
_received = 0;
|
||||||
this->_fd = -1;
|
this->_fd = -1;
|
||||||
this->_sended = 0;
|
this->_sended = 0;
|
||||||
}
|
}
|
||||||
@@ -12,6 +13,7 @@ Client::Client()
|
|||||||
Client::Client(char *str)
|
Client::Client(char *str)
|
||||||
{
|
{
|
||||||
allRead = false;
|
allRead = false;
|
||||||
|
_received = 0;
|
||||||
this->_fd = -1;
|
this->_fd = -1;
|
||||||
this->_buff = str;
|
this->_buff = str;
|
||||||
this->_sended = 0;
|
this->_sended = 0;
|
||||||
@@ -21,6 +23,7 @@ Client::Client(char *str)
|
|||||||
Client::Client(char *str, ServerConfig *config)
|
Client::Client(char *str, ServerConfig *config)
|
||||||
{
|
{
|
||||||
allRead = false;
|
allRead = false;
|
||||||
|
_received = 0;
|
||||||
this->_fd = -1;
|
this->_fd = -1;
|
||||||
this->_config = config;
|
this->_config = config;
|
||||||
this->_buff = str;
|
this->_buff = str;
|
||||||
@@ -55,6 +58,11 @@ unsigned int Client::getCounter(void) const
|
|||||||
return _sended;
|
return _sended;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int Client::getRecvCounter(void) const
|
||||||
|
{
|
||||||
|
return _received;
|
||||||
|
}
|
||||||
|
|
||||||
void Client::setRawData(char *str)
|
void Client::setRawData(char *str)
|
||||||
{
|
{
|
||||||
this->_buff = str;
|
this->_buff = str;
|
||||||
@@ -96,11 +104,33 @@ bool Client::allSended(void)
|
|||||||
return (true);
|
return (true);
|
||||||
return (false);
|
return (false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Client::allRecved(void)
|
||||||
|
{
|
||||||
|
if (_request.getContentLength() == _received)
|
||||||
|
{
|
||||||
|
std::cout << "contentLength, _received "
|
||||||
|
<< _request.getContentLength()
|
||||||
|
<< " " <<
|
||||||
|
_received << std::endl;
|
||||||
|
return (true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return (false);
|
||||||
|
}
|
||||||
// Функция увеличивает счетчик на количество BUFFERSIZE. Счетчик - количество байтов отправленных клиенту.
|
// Функция увеличивает счетчик на количество BUFFERSIZE. Счетчик - количество байтов отправленных клиенту.
|
||||||
void Client::increaseCounter(void)
|
void Client::increaseCounter(void)
|
||||||
{
|
{
|
||||||
_sended += BUFFSIZE;
|
_sended += BUFFSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Client::increaseRecvCounter(unsigned int n)
|
||||||
|
{
|
||||||
|
if (_received == 0)
|
||||||
|
_received -= _request.getHeaderSize();
|
||||||
|
_received += n;
|
||||||
|
}
|
||||||
|
|
||||||
//Генерирует response. Далее респонс можно получить через функцию getStrToSend()
|
//Генерирует response. Далее респонс можно получить через функцию getStrToSend()
|
||||||
int Client::sendResponse(int fd)
|
int Client::sendResponse(int fd)
|
||||||
{
|
{
|
||||||
@@ -153,7 +183,7 @@ void Client::printClientInfo(void)
|
|||||||
std::cout << PINK << it->first << BLUE << it->second << ZERO_C << std::endl;
|
std::cout << PINK << it->first << BLUE << it->second << ZERO_C << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << TURGUOISE << "Client BODY" << ZERO_C << std::endl;
|
std::cout << TURGUOISE << "Client BODY" << ZERO_C << std::endl;
|
||||||
std::cout << BLUE << _request.getBody().size() << ZERO_C << std::endl;
|
std::cout << GREEN << _request.getBody().size() << ZERO_C << std::endl;
|
||||||
/* std::cout << BLUE << _request.getBody() << ZERO_C << std::endl; */
|
/* std::cout << BLUE << _request.getBody() << ZERO_C << std::endl; */
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ private:
|
|||||||
int _ret;
|
int _ret;
|
||||||
int _fd;
|
int _fd;
|
||||||
unsigned int _sended;
|
unsigned int _sended;
|
||||||
|
unsigned int _received;
|
||||||
char *_buff;
|
char *_buff;
|
||||||
|
|
||||||
|
|
||||||
@@ -37,6 +38,7 @@ public:
|
|||||||
void setRawData(char *);
|
void setRawData(char *);
|
||||||
void setFd(int);
|
void setFd(int);
|
||||||
int getFd(void);
|
int getFd(void);
|
||||||
|
unsigned int getRecvCounter(void) const;
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -46,11 +48,13 @@ public:
|
|||||||
|
|
||||||
bool readyToSend(void);
|
bool readyToSend(void);
|
||||||
bool allSended(void);
|
bool allSended(void);
|
||||||
|
bool allRecved(void);
|
||||||
bool isChunked(void);
|
bool isChunked(void);
|
||||||
int sendResponse(int fd);
|
int sendResponse(int fd);
|
||||||
int sendData(int , std::string data);
|
int sendData(int , std::string data);
|
||||||
void clear(void);
|
void clear(void);
|
||||||
void increaseCounter(void);
|
void increaseCounter(void);
|
||||||
|
void increaseRecvCounter(unsigned int n);
|
||||||
std::string generateRespons(void);
|
std::string generateRespons(void);
|
||||||
|
|
||||||
Client();
|
Client();
|
||||||
|
|||||||
Reference in New Issue
Block a user