Consider the following code:
As far as I can see, socket wasn't set to be non-blocking. However, after receiving data from host, recv() starts returning 0 without waiting for any data. Why is that? In fact, it would be great if this function could wait for some data...
int main(int argc, char *argv)
struct addrinfo *res, hints;
char buffer = "GET /intl/en/ HTTP/1.1\r\nHost: www.google.com\r\nX-Header: test\r\n\r\n";
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo("www.google.com", "80", &hints, &res);
cnt= socket(res->ai_family, res->ai_socktype, res->ai_protocol);
connect(cnt, res->ai_addr, res->ai_addrlen);
send(cnt, buffer, 2048, 0);
if (recv(cnt, buffer_in, 1024, 0) == 0)
printf("error :P ");
Thanks in advance for your answers.