<?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 hp-ux)</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>
<item>
    <title>socklen_t confusion</title>
    <link>http://portabilityblog.com/blog/archives/7-socklen_t-confusion.html</link>
            <category>Operating Systems</category>
    
    <comments>http://portabilityblog.com/blog/archives/7-socklen_t-confusion.html#comments</comments>
    <wfw:comment>http://portabilityblog.com/blog/wfwcomment.php?cid=7</wfw:comment>

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

    <author>nospam@example.com (Daniel Fischer)</author>
    <content:encoded>
    The BSD socket API (accept, bind, and so on) uses a struct sockaddr to pass socket addresses. Additionally, there&#039;s a parameter for passing the size of the memory block allocated for a struct sockaddr to the socket functions. This argument is passed as a pointer to the actual size, and upon completion of the API call, will contain the actual length of the address stored in the memory block instead of its size. In the original BSD API, this argument was of type int *.&lt;br /&gt;
&lt;br /&gt;
At one point, a draft of the POSIX.1g standard defined this to be size_t *. This was a bit broken because size_t is usually not the same type as int on 64-bit platforms, the re-definition thus resulting in an unintended and incompatible change. The short of it is that people complained, and the type was changed again. Instead of reverting to int *, however, a new type socklen_t was introduced. This new type is defined to be the same as int on most platforms. As Linus Torvalds puts it,&lt;br /&gt;
&lt;blockquote&gt;_Any_ sane library _must_ have &quot;socklen_t&quot; be the same size as int. Anything else breaks any BSD socket layer stuff. POSIX initially did make it a size_t, and I (and hopefully others, but obviously not too many) complained to them very loudly indeed. Making it a size_t is completely broken, exactly because size_t very seldom is the same size as &quot;int&quot; on 64-bit architectures, for example. And it has to be the same size as &quot;int&quot; because that&#039;s what the BSD socket interface is.&lt;br /&gt;
&lt;/blockquote&gt;&lt;br /&gt;
(Quote taken from man 2 accept on Linux.)&lt;br /&gt;
&lt;br /&gt;
So for a small period of time, operating system vendors were preparing for POSIX.1g as it was known back then and started to use size_t instead of int. As the draft was changed to use socklen_t, and later SUSv2 included socklen_t, they mostly started to use socklen_t and defined it to int. Some defined it to be the same type as size_t. One example that is mentioned in Linux&#039; man 2 accept is SunOS 5. This includes the current release of Solaris, being based on SunOS 5.10. However, that&#039;s not a &lt;i&gt;big&lt;/i&gt; portability issue. It&#039;s broken as described above, but code that uses socklen_t in all places should be just fine.&lt;br /&gt;
&lt;br /&gt;
On HP-UX, you get the worst of both worlds. On the one hand, you can use the old BSD API with pointers to int. On the other hand, you can define _XOPEN_SOURCE_EXTENDED and get the new API with socklen_t. However, if you don&#039;t define _XOPEN_SOURCE_EXTENDED, you still get a definition of socklen_t to size_t.  The type exists but is completely worthless as it can&#039;t be used with the socket API, which expects int.&lt;br /&gt;
&lt;br /&gt;
I&#039;ve actually seen code that fell over this in both possible ways, using int * in one place and socklen_t * in another...&lt;br /&gt;
 
    </content:encoded>

    <pubDate>Sat, 22 Dec 2007 14:22:00 +0100</pubDate>
    <guid isPermaLink="false">http://portabilityblog.com/blog/archives/7-guid.html</guid>
    <category>hp-ux</category>
<category>posix</category>

</item>

</channel>
</rss>