<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Portability Blog (Entries tagged as bsd)</title>
    <link>http://portabilityblog.com/blog/</link>
    <description>tales about building software on many platforms</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.2.1 - http://www.s9y.org/</generator>
    <managingEditor>df.portabilityblog@erinye.com</managingEditor>
<webMaster>df.portabilityblog@erinye.com</webMaster>
<pubDate>Tue, 24 Mar 2009 12:30:29 GMT</pubDate>

    <image>
        <url>http://portabilityblog.com/blog/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Portability Blog - tales about building software on many platforms</title>
        <link>http://portabilityblog.com/blog/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>SO_SNDTIMEO and SO_RCVTIMEO</title>
    <link>http://portabilityblog.com/blog/archives/10-SO_SNDTIMEO-and-SO_RCVTIMEO.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/10-SO_SNDTIMEO-and-SO_RCVTIMEO.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=10</wfw:comment>

    <slash:comments>3</slash:comments>
    <wfw:commentRss>http://portabilityblog.com/blog/rss.php?version=2.0&amp;type=comments&amp;cid=10</wfw:commentRss>
    

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    Implementations of the BSD socket interface support various socket options. Two of them are SO_SNDTIMEO and SO_RCVTIMEO. They allow the user to specify a timeout for otherwise blocking send() and recv() calls. They&#039;re often described as the two socket options that have the most different implementations and are therefore among the most unportable ones at all.&lt;br /&gt;
&lt;p/&gt;&lt;br /&gt;
It&#039;s not quite as bad, but among the major UNIX and Unix-like operating systems, there are at least three different beaviours for stream sockets, ignoring that the behaviour for datagram sockets may yet be different.&lt;br /&gt;
&lt;p/&gt;&lt;br /&gt;
Most of the operating systems I tested this on actually support these timeouts. Mac OS X, Linux, FreeBSD and AIX were all among the platforms where I was able to use these timeouts in a simple test, using reasonably recent versions of these operating systems. This means that the OSes accepted setting the option and the timeout that was configured did actually work. The BSD socket implementation that is used in Microsoft Windows also falls into this category, the timeouts work reliably there.&lt;br /&gt;
&lt;p/&gt;&lt;br /&gt;
One notable exception was Solaris, which reported that the protocol did not support this option. This means that the setsockopt() call failed. Since this is detectable, it&#039;s not a problem; there are other ways to implement timeouts without support from the socket layer.&lt;br /&gt;
&lt;p/&gt;&lt;br /&gt;
The other notable exception was HP-UX (tested with 11iv3 and 11iv1). On HP-UX, you can get the same behaviour as on Solaris if you use the UNIX03 socket library, meaning setsockopt() fails with ENOPROTOOPT. However, if you&#039;re using the BSD socket library that is also provided with HP-UX, then you &lt;i&gt;are&lt;/i&gt; allowed to set the timeouts, but they are silently ignored.&lt;br /&gt;
&lt;br /&gt;
Even worse, the system will remember the timout you set, and querying it with getsockopt() will return it. This means you can&#039;t verify that the timeout is available by querying it after setting it and comparing it to the value you set it to. Setting it is allowed and querying it will yield the timeout that was previously set, but &lt;i&gt;the timeout setting will be silently ignored by HP-UX&lt;/i&gt;.&lt;br /&gt;
&lt;p/&gt;&lt;br /&gt;
&lt;b&gt;In summary,&lt;/b&gt; you can actually expect these timeouts to either work or cause an error when you try to set them on most UNIX and Unix-like operating systems, and also on Windows, but if you are really concerned about portability, you need a backup plan, and either a whitelist of platforms where the backup plan is not necessary, or a very short blacklist that mostly consists of HP-UX.&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Tue, 24 Mar 2009 13:30:29 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/10-guid.html</guid>
    <category>bsd</category>
<category>hp-ux</category>
<category>sockets</category>
<category>unix</category>

</item>

</channel>
</rss>