I'm writing simple http server, firstly let's take a look at this part of code:
static void *connection_handler(void *connection) {
/* cast the connection */
Connection *c = (Connection*)connection;
HttpRequest req;
char buffer[1024];
size_t bytes_recv = recv(c->s, buffer, 1024, 0);
parse_http_request(&req, buffer, bytes_recv);
printf("Received connection!");
//printf("%s", buffer);
/* cleanup */
krystal_close_socket(c->s);
free(connection);
return NULL;
}
this is my connection handler, every connection I push it to the vector of threads and I got strange bug. When printf with received data is commented, all "Received connection" messages show off after the server loop stops (I've set to stop server after 5 connections) but.. when I'm printing received data every connection it works, buffer is printed on every connection. WTF?!