> Thanks Pierre-Yves!
> I modified my code setting non-blocking socket using the way you described.
> The problem is still the same.
You need to listen(fd, backlog) on your server socket before attempting to
connect. How about something like this:
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/ioctl.h>
int server_socket(char *address, char *port)
{
struct addrinfo *info = NULL;
int handle = -1, flag = 1;
if (!getaddrinfo(address, port, NULL, &info) &&
(handle = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
!setsockopt(handle, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag)) &&
!bind(handle, (struct sockaddr *)info->ai_addr, sizeof(struct
sockaddr)) &&
!listen(handle, -1) &&
!ioctl(handle, FIONBIO, &flag))
{
freeaddrinfo(info);
return handle;
}
freeaddrinfo(info);
close(handle);
return -1;
}
int main(int argc, char **argv)
{
int fd;
if ((fd = server_socket("localhost", "http-alt")) < 0)
{
perror("server_socket");
return 1;
}
// do something like accept() ...
return 0;
}
--
Pierre-Yves
_______________________________________________
libev mailing list
[email protected]
http://lists.schmorp.de/cgi-bin/mailman/listinfo/libev