|
@ -70,7 +70,7 @@ void Socket::refresh() { |
|
|
std::vector<int>::iterator it; |
|
|
std::vector<int>::iterator it; |
|
|
int valread; |
|
|
int valread; |
|
|
int addrlen = sizeof(_address); |
|
|
int addrlen = sizeof(_address); |
|
|
char buffer[1024]; |
|
|
char buffer[10000]; |
|
|
if (FD_ISSET(_master_socket, &_readfds)) { |
|
|
if (FD_ISSET(_master_socket, &_readfds)) { |
|
|
int new_socket = accept(_master_socket, (struct sockaddr *)&_address, |
|
|
int new_socket = accept(_master_socket, (struct sockaddr *)&_address, |
|
|
(socklen_t *)&addrlen); |
|
|
(socklen_t *)&addrlen); |
|
@ -88,7 +88,7 @@ void Socket::refresh() { |
|
|
} |
|
|
} |
|
|
for (it = _clients.begin(); it < _clients.end(); it++) { |
|
|
for (it = _clients.begin(); it < _clients.end(); it++) { |
|
|
if (FD_ISSET(*it, &_readfds)) { |
|
|
if (FD_ISSET(*it, &_readfds)) { |
|
|
valread = read(*it, buffer, 1024); |
|
|
valread = read(*it, buffer, 10000); |
|
|
if (valread == 0) { |
|
|
if (valread == 0) { |
|
|
getpeername(*it, (struct sockaddr *)&_address, |
|
|
getpeername(*it, (struct sockaddr *)&_address, |
|
|
(socklen_t *)&addrlen); |
|
|
(socklen_t *)&addrlen); |
|
@ -96,11 +96,13 @@ void Socket::refresh() { |
|
|
<< ", port " << ntohs(_address.sin_port) << "\n"; |
|
|
<< ", port " << ntohs(_address.sin_port) << "\n"; |
|
|
close(*it); |
|
|
close(*it); |
|
|
_clients.erase(it); |
|
|
_clients.erase(it); |
|
|
} else |
|
|
} else { |
|
|
|
|
|
buffer[valread]='\0'; |
|
|
this->answer(*it, buffer); |
|
|
this->answer(*it, buffer); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void Socket::answer(int fd, string request) { |
|
|
void Socket::answer(int fd, string request) { |
|
|
string uri = "path/to/page/"; |
|
|
string uri = "path/to/page/"; |
|
@ -108,7 +110,7 @@ void Socket::answer(int fd, string request) { |
|
|
(void)route; |
|
|
(void)route; |
|
|
char r404[72] = |
|
|
char r404[72] = |
|
|
"HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 4\n\n404!"; |
|
|
"HTTP/1.1 200 OK\nContent-Type: text/plain\nContent-Length: 4\n\n404!"; |
|
|
cout << request << "\n"; |
|
|
cout << request << "\n|===|===|===|\n"; |
|
|
#ifdef __linux__ |
|
|
#ifdef __linux__ |
|
|
send(fd, r404, strlen(r404), MSG_NOSIGNAL); |
|
|
send(fd, r404, strlen(r404), MSG_NOSIGNAL); |
|
|
#elif __APPLE__ |
|
|
#elif __APPLE__ |
|
|