mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
feat: handle when recv returns 0 or 1
This commit is contained in:
@@ -110,46 +110,39 @@ void Server::sendData(Client &client, int fd)
|
||||
|
||||
void Server::readSocket(Client &client, int fd)
|
||||
{
|
||||
|
||||
int status;
|
||||
int bytes_read;
|
||||
// char buf[BUFFSIZE + 1];
|
||||
std::string stringBUF(BUFFSIZE, 0);
|
||||
|
||||
DBOUT << TURQ << "IN readSocket" << ENDL;
|
||||
DBOUT << "client in readSocket "<< &client << ENDL;
|
||||
// DBOUT << "client in readSocket "<< &client << ENDL;
|
||||
bytes_read = recv(fd, &stringBUF[0], BUFFSIZE, 0);
|
||||
if (bytes_read == 0)
|
||||
{
|
||||
DBOUT << RED << "bytes_read = 0" << ENDL;
|
||||
client.allRead = true;
|
||||
throw std::logic_error("JOPA CLIENTU");
|
||||
return;
|
||||
DBOUT << RED << "bytes_read 0" << ENDL;
|
||||
client.done = true;
|
||||
}
|
||||
/* else if (bytes_read == -1) */
|
||||
/* throw std::logic_error("JOPA CLIENTU"); */
|
||||
// buf[bytes_read + 1] = '\0';
|
||||
// DBOUT << stringBUF << ENDL;
|
||||
else if (bytes_read == -1)
|
||||
{
|
||||
DBOUT << RED << "bytes_read -1" << ENDL;
|
||||
client.allRead = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBUF.erase(bytes_read, stringBUF.size());
|
||||
/* DBOUT << "after erase" <<ENDL; */
|
||||
/* DBOUT << stringBUF << ENDL; */
|
||||
client.setRawData(stringBUF);
|
||||
// client.setRawData(buf);
|
||||
client.increaseRecvCounter(bytes_read);
|
||||
status = client.parseRequest();
|
||||
(void)status;
|
||||
// client_map[fd].printClientInfo();
|
||||
|
||||
// client.printClientInfo();
|
||||
if (client.allRecved())
|
||||
{
|
||||
client.allRead = true;
|
||||
}
|
||||
|
||||
DBOUT << GREEN << "recvCounter " << client.getRecvCounter() << ENDL;
|
||||
DBOUT << GREEN << "contentLength " << client.getRequest().getContentLength() << ENDL;
|
||||
DBOUT << GREEN << "allRead " << client.allRead << ENDL;
|
||||
|
||||
DBOUT << BLUE << "status is " << Response::getReasonPhrase(status) << ENDL;
|
||||
}
|
||||
}
|
||||
|
||||
int Server::delete_client(std::map<int, Client *> &client_map, int fd)
|
||||
|
||||
Reference in New Issue
Block a user