<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to 21: Support timeout on receive and send operations</title><link>https://sourceforge.net/p/libmms/bugs/21/</link><description>Recent changes to 21: Support timeout on receive and send operations</description><atom:link href="https://sourceforge.net/p/libmms/bugs/21/feed.rss" rel="self"/><language>en</language><lastBuildDate>Sun, 27 Dec 2015 11:54:38 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/libmms/bugs/21/feed.rss" rel="self" type="application/rss+xml"/><item><title>#21 Support timeout on receive and send operations</title><link>https://sourceforge.net/p/libmms/bugs/21/?limit=25#2d76</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I agree that having a non blocking API or a way to limit the timeout would be good, but I do not think that having a fixed timeout is a good idea. How about adding with_timeout postfixed variants of the existing connect functions which take a timeout argument. Note that it is important to maintain API and ABI compatibility with existing users.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Hans&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Hans de Goede</dc:creator><pubDate>Sun, 27 Dec 2015 11:54:38 -0000</pubDate><guid>https://sourceforge.net685f772a1c8f2b1538c87df2abf4d8db141653ff</guid></item><item><title>Support timeout on receive and send operations</title><link>https://sourceforge.net/p/libmms/bugs/21/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;It would be really nice if we can control somehow the connection timeout on receive and send operation because those calls are blocking. (Eg using libmms with GStreamer).&lt;/p&gt;
&lt;p&gt;The following patch reduces the timeout to a fixed value.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span class="gh"&gt;diff --git a/src/mms.c b/src/mms.c&lt;/span&gt;
&lt;span class="gh"&gt;index 4af5f0f..f7a7df3 100644&lt;/span&gt;
&lt;span class="gd"&gt;--- a/src/mms.c&lt;/span&gt;
&lt;span class="gi"&gt;+++ b/src/mms.c&lt;/span&gt;
&lt;span class="gu"&gt;@@ -40,6 +40,7 @@&lt;/span&gt;
 #include &amp;lt;stdio.h&amp;gt;
 #ifdef HAVE_SYS_SOCKET_H
 #include &amp;lt;sys/socket.h&amp;gt;
&lt;span class="gi"&gt;+#include &amp;lt;sys/time.h&amp;gt;&lt;/span&gt;
 #endif
 #ifdef HAVE_NETINET_IN_H
 #include &amp;lt;netinet/in.h&amp;gt;
&lt;span class="gu"&gt;@@ -212,6 +213,7 @@ static off_t fallback_io_write(void *data, int socket, char *buf, off_t num)&lt;/span&gt;
 static int fallback_io_tcp_connect(void *data, const char *host, int port)
 {
   struct addrinfo *r, *res, hints;
&lt;span class="gi"&gt;+  struct timeval timeout;&lt;/span&gt;
   char port_str[16];
   int i, s;

&lt;span class="gu"&gt;@@ -221,6 +223,9 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port)&lt;/span&gt;
   hints.ai_socktype = SOCK_STREAM;
   hints.ai_protocol = IPPROTO_TCP;

&lt;span class="gi"&gt;+  timeout.tv_sec = 15;&lt;/span&gt;
&lt;span class="gi"&gt;+  timeout.tv_usec = 0;&lt;/span&gt;
&lt;span class="gi"&gt;+&lt;/span&gt;
   sprintf(port_str, "%d", port);
   i = getaddrinfo(host, port_str, &amp;amp;hints, &amp;amp;res);
   if (i != 0) {
&lt;span class="gu"&gt;@@ -231,6 +236,12 @@ static int fallback_io_tcp_connect(void *data, const char *host, int port)&lt;/span&gt;
   for (r = res; r != NULL; r = r-&amp;gt;ai_next) {
     s = socket(r-&amp;gt;ai_family, r-&amp;gt;ai_socktype, r-&amp;gt;ai_protocol);
     if (s != -1) {
&lt;span class="gi"&gt;+      if (setsockopt (s, SOL_SOCKET, SO_RCVTIMEO, (char *)&amp;amp;timeout,&lt;/span&gt;
&lt;span class="gi"&gt;+                sizeof(timeout)) &amp;lt; 0)&lt;/span&gt;
&lt;span class="gi"&gt;+        lprintf("Setting socket receive timeout to %ds failed!", timeout.tv_sec);&lt;/span&gt;
&lt;span class="gi"&gt;+      if (setsockopt (s, SOL_SOCKET, SO_SNDTIMEO, (char *)&amp;amp;timeout,&lt;/span&gt;
&lt;span class="gi"&gt;+                sizeof(timeout)) &amp;lt; 0)&lt;/span&gt;
&lt;span class="gi"&gt;+        lprintf("Setting socket send timeout to %ds failed!", timeout.tv_sec);&lt;/span&gt;
       if (connect(s, r-&amp;gt;ai_addr, r-&amp;gt;ai_addrlen) != -1) {
         freeaddrinfo(res);
         return s;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Athanasios Oikonomou</dc:creator><pubDate>Sat, 28 Nov 2015 19:30:16 -0000</pubDate><guid>https://sourceforge.net0ba1000c40968515c8975e45d9a25b4c0654ede3</guid></item></channel></rss>