feat: check sent amount

This commit is contained in:
3lswear
2022-02-21 00:38:57 +03:00
parent 45c21b9043
commit 582310c70d

View File

@@ -1,8 +1,6 @@
#include "Server.hpp" #include "Server.hpp"
#include <exception> #include <exception>
#include <cassert> #include <cassert>
#include <cstdio>
#include <map>
#define THREAD_NUM 100 #define THREAD_NUM 100
#define MAX_EVENTS #define MAX_EVENTS
@@ -10,7 +8,6 @@
Server::Server() Server::Server()
{ {
bzero(_events, sizeof(_events)); bzero(_events, sizeof(_events));
} }
void Server::readConfig(char *filename) void Server::readConfig(char *filename)
@@ -45,6 +42,7 @@ void Server::sendData(Client &client, int fd)
char *tmp = client.getStrToSend(); char *tmp = client.getStrToSend();
size_t size_diff = client.response_len - client.getCounter(); size_t size_diff = client.response_len - client.getCounter();
size_t send_len; size_t send_len;
ssize_t sent;
if (size_diff < BUFFSIZE) if (size_diff < BUFFSIZE)
send_len = size_diff; send_len = size_diff;
@@ -54,13 +52,15 @@ void Server::sendData(Client &client, int fd)
/* DBOUT << YELLO << tmp << ENDL; */ /* DBOUT << YELLO << tmp << ENDL; */
/* DBOUT << GREEN << client.getCounter() << ENDL; */ /* DBOUT << GREEN << client.getCounter() << ENDL; */
DBOUT << "sent " << send_len << " to client " << fd << ENDL; DBOUT << "sent " << send_len << " to client " << fd << ENDL;
sent = send(fd, tmp + client.getCounter(), send_len, MSG_NOSIGNAL);
if (send(fd, tmp + client.getCounter(), send_len, MSG_NOSIGNAL) < 0) if (sent < 0)
{ {
DBOUT << RED << "SEND FAILED !@!!!" << ENDL; DBOUT << RED << "SEND FAILED !@!!!" << ENDL;
client.done = true; client.done = true;
} }
client.increaseCounter(); else if (sent > 0)
client.increaseCounter();
} }
void Server::readSocket(Client &client, int fd) void Server::readSocket(Client &client, int fd)