From f34ab24d9927b765384adb76e13880487f0e08fb Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Tue, 10 Apr 2012 00:17:08 +0200 Subject: [PATCH] add set_non_blocking() to upnputils.c/h --- minissdpd/upnputils.c | 16 ++++++++++++++-- minissdpd/upnputils.h | 11 +++++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/minissdpd/upnputils.c b/minissdpd/upnputils.c index a407ff6..8e253d7 100644 --- a/minissdpd/upnputils.c +++ b/minissdpd/upnputils.c @@ -1,13 +1,15 @@ -/* $Id: upnputils.c,v 1.3 2011/05/20 09:42:23 nanard Exp $ */ +/* $Id: upnputils.c,v 1.4 2012/02/06 16:21:24 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2011 Thomas Bernard + * (c) 2006-2012 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ #include "config.h" #include +#include +#include #include #include #include @@ -65,4 +67,14 @@ sockaddr_to_string(const struct sockaddr * addr, char * str, size_t size) } +int +set_non_blocking(int fd) +{ + int flags = fcntl(fd, F_GETFL); + if(flags < 0) + return 0; + if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) + return 0; + return 1; +} diff --git a/minissdpd/upnputils.h b/minissdpd/upnputils.h index 29fa2a3..363debf 100644 --- a/minissdpd/upnputils.h +++ b/minissdpd/upnputils.h @@ -1,7 +1,7 @@ -/* $Id: upnputils.h,v 1.1 2011/05/15 08:58:41 nanard Exp $ */ +/* $Id: upnputils.h,v 1.2 2012/02/06 16:21:24 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2011 Thomas Bernard + * (c) 2011-2012 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -16,5 +16,12 @@ int sockaddr_to_string(const struct sockaddr * addr, char * str, size_t size); +/** + * set the file description as non blocking + * return 0 in case of failure, 1 in case of success + */ +int +set_non_blocking(int fd); + #endif