fix: delete client, if he empty

This commit is contained in:
Talyx
2022-02-01 17:39:45 +03:00
parent d63e122778
commit f8343098e8
4 changed files with 19 additions and 5 deletions

View File

@@ -149,7 +149,10 @@ std::string Client::generateRespons(void)
bool Client::readyToSend(void) bool Client::readyToSend(void)
{ {
return(_request.ok()); if (_request.ok())
return(_request.ok());
else
return false;
} }
void Client::printClientInfo(void) void Client::printClientInfo(void)
@@ -183,6 +186,15 @@ void Client::printClientInfo(void)
} }
bool Client::isEmpty(void)
{
if (!_request.ok() && _request.getHeaderSize() == 0
&& _request.getContentLength() == 0)
return (true);
else
return (false);
}
void Client::clear(void) void Client::clear(void)
{ {
_fd = -1; _fd = -1;

View File

@@ -37,8 +37,8 @@ public:
void setRawData(char *); void setRawData(char *);
void setFd(int); void setFd(int);
int getFd(void); int getFd(void);
unsigned int getRecvCounter(void) const; unsigned int getRecvCounter(void) const;
bool isEmpty(void);
public: public:
int parseRequest(void); int parseRequest(void);

View File

@@ -11,6 +11,7 @@ Request::Request()
_head_ok = false; _head_ok = false;
_body_ok = false; _body_ok = false;
_received = 0; _received = 0;
_headerSize = 0;
} }
@@ -24,6 +25,7 @@ Request::Request(char *str)
_received = 0; _received = 0;
_chunked = false; _chunked = false;
_contentLength = 0; _contentLength = 0;
_headerSize = 0;
} }
//-------------------------------------------------Get/Set--------------------------------------- //-------------------------------------------------Get/Set---------------------------------------

View File

@@ -154,7 +154,7 @@ void Server::start(void)
std::cout << TURQ << "IN SEND LOOP" << RESET << std::endl; std::cout << TURQ << "IN SEND LOOP" << RESET << std::endl;
Client &client = client_it->second; Client &client = client_it->second;
if (!client.allRead) if (!client.allRead && !client.isEmpty())
{ {
readSocket(client_it->first, client_map); readSocket(client_it->first, client_map);
} }
@@ -168,7 +168,7 @@ void Server::start(void)
} }
if (client.readyToSend() && client.allSended()) if ((client.readyToSend() && client.allSended()) || client.isEmpty())
{ {
client_map[fd].printClientInfo(); client_map[fd].printClientInfo();
close(client_it->first); close(client_it->first);