always handle EAGAIN, EWOULDBLOCK and EINTR after recv()/recvfrom() calls

This commit is contained in:
Thomas Bernard 2012-02-02 18:45:43 +01:00
parent 567808b8cd
commit 73ef11624a
5 changed files with 54 additions and 17 deletions

View File

@ -1,4 +1,7 @@
$Id: Changelog.txt,v 1.248 2012/01/20 21:57:45 nanard Exp $
$Id: Changelog.txt,v 1.249 2012/02/01 11:13:29 nanard Exp $
2012/02/01:
always handle EAGAIN, EWOULDBLOCK and EINTR after recv()/recvfrom() calls
2012/01/20:
Always #include <netinet/in.h> before #include <arpa/inet.h> (for OpenBSD)

View File

@ -1,7 +1,7 @@
/* $Id: minissdp.c,v 1.27 2011/05/23 12:39:41 nanard Exp $ */
/* $Id: minissdp.c,v 1.28 2012/02/01 11:13:30 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 */
@ -12,6 +12,7 @@
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <syslog.h>
#include "config.h"
#include "upnpdescstrings.h"
@ -403,7 +404,14 @@ ProcessSSDPRequest(int s, unsigned short port)
(struct sockaddr *)&sendername, &len_r);
if(n < 0)
{
syslog(LOG_ERR, "recvfrom(udp): %m");
/* EAGAIN, EWOULDBLOCK, EINTR : silently ignore (try again next time)
* other errors : log to LOG_ERR */
if(errno != EAGAIN &&
errno != EWOULDBLOCK &&
errno != EINTR)
{
syslog(LOG_ERR, "recvfrom(udp): %m");
}
return;
}
ProcessSSDPData(s, bufr, n, (struct sockaddr *)&sendername, port);

View File

@ -1,6 +1,6 @@
/* $Id: natpmp.c,v 1.26 2011/07/15 07:48:26 nanard Exp $ */
/* $Id: natpmp.c,v 1.27 2012/02/01 11:13:30 nanard Exp $ */
/* MiniUPnP project
* (c) 2007-2010 Thomas Bernard
* (c) 2007-2012 Thomas Bernard
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -8,6 +8,7 @@
#include <string.h>
#include <unistd.h>
#include <syslog.h>
#include <errno.h>
#include <time.h>
#include <sys/types.h>
#include <sys/socket.h>
@ -116,7 +117,13 @@ void ProcessIncomingNATPMPPacket(int s)
n = recvfrom(s, req, sizeof(req), 0,
(struct sockaddr *)&senderaddr, &senderaddrlen);
if(n<0) {
syslog(LOG_ERR, "recvfrom(natpmp): %m");
/* EAGAIN, EWOULDBLOCK and EINTR : silently ignore (retry next time)
* other errors : log to LOG_ERR */
if(errno != EAGAIN &&
errno != EWOULDBLOCK &&
errno != EINTR) {
syslog(LOG_ERR, "recvfrom(natpmp): %m");
}
return;
}
if(!inet_ntop(AF_INET, &senderaddr.sin_addr,

View File

@ -1,7 +1,7 @@
/* $Id: upnpevents.c,v 1.17 2011/06/27 11:24:00 nanard Exp $ */
/* $Id: upnpevents.c,v 1.18 2012/02/01 11:13:30 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2008-2011 Thomas Bernard
* (c) 2008-2012 Thomas Bernard
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
@ -390,12 +390,19 @@ static void upnp_event_recv(struct upnp_event_notify * obj)
int n;
n = recv(obj->s, obj->buffer, obj->buffersize, 0);
if(n<0) {
syslog(LOG_ERR, "%s: recv(): %m", "upnp_event_recv");
obj->state = EError;
if(errno != EAGAIN &&
errno != EWOULDBLOCK &&
errno != EINTR) {
syslog(LOG_ERR, "%s: recv(): %m", "upnp_event_recv");
obj->state = EError;
}
return;
}
syslog(LOG_DEBUG, "%s: (%dbytes) %.*s", "upnp_event_recv",
n, n, obj->buffer);
/* TODO : do something with the data recevied ?
* right now, n (number of bytes received) is ignored
* We may need to recv() more bytes. */
obj->state = EFinished;
if(obj->sub)
obj->sub->seq++;

View File

@ -1,8 +1,8 @@
/* $Id: upnphttp.c,v 1.65 2012/01/20 21:45:57 nanard Exp $ */
/* $Id: upnphttp.c,v 1.66 2012/02/01 11:13:30 nanard Exp $ */
/* Project : miniupnp
* Website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* Author : Thomas Bernard
* Copyright (c) 2005-2011 Thomas Bernard
* Copyright (c) 2005-2012 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file included in this distribution.
* */
@ -554,8 +554,14 @@ Process_upnphttp(struct upnphttp * h)
n = recv(h->socket, buf, 2048, 0);
if(n<0)
{
syslog(LOG_ERR, "recv (state0): %m");
h->state = 100;
if(errno != EAGAIN &&
errno != EWOULDBLOCK &&
errno != EINTR)
{
syslog(LOG_ERR, "recv (state0): %m");
h->state = 100;
}
/* if errno is EAGAIN, EWOULDBLOCK or EINTR, try again later */
}
else if(n==0)
{
@ -584,8 +590,14 @@ Process_upnphttp(struct upnphttp * h)
n = recv(h->socket, buf, 2048, 0);
if(n<0)
{
syslog(LOG_ERR, "recv (state1): %m");
h->state = 100;
if(errno != EAGAIN &&
errno != EWOULDBLOCK &&
errno != EINTR)
{
syslog(LOG_ERR, "recv (state1): %m");
h->state = 100;
}
/* if errno is EAGAIN, EWOULDBLOCK or EINTR, try again later */
}
else if(n==0)
{