From: Youness Alaoui Date: Wed, 9 Jul 2014 22:55:44 +0000 (-0400) Subject: agent: Fix infinite loop when the peer closes a TCP connection remotely X-Git-Tag: 0.1.8~123 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=969129b72d873a688a0c6631f254bc6787fa1296;p=platform%2Fupstream%2Flibnice.git agent: Fix infinite loop when the peer closes a TCP connection remotely --- diff --git a/agent/agent.c b/agent/agent.c index 4087e61..8bcb828 100644 --- a/agent/agent.c +++ b/agent/agent.c @@ -3243,6 +3243,19 @@ agent_recv_message_unlocked ( * return an error to make the socket fail/closed */ retval = -1; + } else { + gint flags = G_SOCKET_MSG_PEEK; + + /* If available bytes are 0, but the socket is still considered + * connected, then either we're just trying to see if there's more + * data available or the peer closed the connection. + * The only way to know is to do a read, so we do here a peek and + * check the return value, if it's 0, it means the peer has closed + * the connection, so we must return an error instead of WOULD_BLOCK + */ + if (g_socket_receive_message (nicesock->fileno, NULL, + NULL, 0, NULL, NULL, &flags, NULL, NULL) == 0) + retval = -1; } } else if (agent->rfc4571_expecting_length == 0) { if ((gsize) available >= sizeof(guint16)) {