Set O_NONBLOCK
This commit is contained in:
15
mud.c
15
mud.c
@@ -5,6 +5,7 @@
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
struct path {
|
||||
@@ -25,6 +26,17 @@ struct mud {
|
||||
struct path *path;
|
||||
};
|
||||
|
||||
static
|
||||
int mud_set_nonblock (int fd)
|
||||
{
|
||||
int flags = fcntl(fd, F_GETFL, 0);
|
||||
|
||||
if (flags==-1)
|
||||
flags = 0;
|
||||
|
||||
return fcntl(fd, F_SETFL, flags|O_NONBLOCK);
|
||||
}
|
||||
|
||||
static
|
||||
struct addrinfo *mud_addrinfo (const char *host, const char *port, int flags)
|
||||
{
|
||||
@@ -186,6 +198,9 @@ int mud_bind (struct mud *mud, const char *host, const char *port)
|
||||
if (fd==-1)
|
||||
continue;
|
||||
|
||||
if (mud_set_nonblock(fd))
|
||||
continue;
|
||||
|
||||
if (!bind(fd, (struct sockaddr *)p->ai_addr, p->ai_addrlen)) {
|
||||
mud_new_sock(mud, fd, p->ai_family);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user