<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 非阻塞connect的一个细节</title>
	<atom:link href="http://blog.yufeng.info/archives/565/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.yufeng.info/archives/565</link>
	<description>Erlang系统深度探索和应用</description>
	<lastBuildDate>Tue, 07 Feb 2012 01:58:33 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Onlys_C</title>
		<link>http://blog.yufeng.info/archives/565/comment-page-1#comment-2170</link>
		<dc:creator>Onlys_C</dc:creator>
		<pubDate>Mon, 16 May 2011 10:55:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.yufeng.info/?p=565#comment-2170</guid>
		<description>第三版，16章352页。。</description>
		<content:encoded><![CDATA[<p>第三版，16章352页。。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: yoyo</title>
		<link>http://blog.yufeng.info/archives/565/comment-page-1#comment-762</link>
		<dc:creator>yoyo</dc:creator>
		<pubDate>Tue, 29 Jun 2010 10:15:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.yufeng.info/?p=565#comment-762</guid>
		<description>这个是APR的写法
int rc;        

    do {
        rc = connect(sock-&gt;socketdes,
                     (const struct sockaddr *)&amp;sa-&gt;sa.sin,
                     sa-&gt;salen);
    } while (rc == -1 &amp;&amp; errno == EINTR);

    /* we can see EINPROGRESS the first time connect is called on a non-blocking
     * socket; if called again, we can see EALREADY
     */
    if ((rc == -1) &amp;&amp; (errno == EINPROGRESS &#124;&#124; errno == EALREADY)
                   &amp;&amp; (sock-&gt;timeout &gt; 0)) {
        rc = apr_wait_for_io_or_timeout(NULL, sock, 0); /** USE SELECT TO WAIT TIMEOUT **/
        if (rc != APR_SUCCESS) {
            return rc;
        }

#ifdef SO_ERROR
        {
            int error;
            apr_socklen_t len = sizeof(error);
            if ((rc = getsockopt(sock-&gt;socketdes, SOL_SOCKET, SO_ERROR, 
                                 (char *)&amp;error, &amp;len)) &lt; 0) {
                return errno;
            }
            if (error) {
                return error;
            }
        }
#endif /* SO_ERROR */
    }

    if (rc == -1 &amp;&amp; errno != EISCONN) {
        return errno;
    }</description>
		<content:encoded><![CDATA[<p>这个是APR的写法<br />
int rc;        </p>
<p>    do {<br />
        rc = connect(sock-&gt;socketdes,<br />
                     (const struct sockaddr *)&amp;sa-&gt;sa.sin,<br />
                     sa-&gt;salen);<br />
    } while (rc == -1 &amp;&amp; errno == EINTR);</p>
<p>    /* we can see EINPROGRESS the first time connect is called on a non-blocking<br />
     * socket; if called again, we can see EALREADY<br />
     */<br />
    if ((rc == -1) &amp;&amp; (errno == EINPROGRESS || errno == EALREADY)<br />
                   &amp;&amp; (sock-&gt;timeout &gt; 0)) {<br />
        rc = apr_wait_for_io_or_timeout(NULL, sock, 0); /** USE SELECT TO WAIT TIMEOUT **/<br />
        if (rc != APR_SUCCESS) {<br />
            return rc;<br />
        }</p>
<p>#ifdef SO_ERROR<br />
        {<br />
            int error;<br />
            apr_socklen_t len = sizeof(error);<br />
            if ((rc = getsockopt(sock-&gt;socketdes, SOL_SOCKET, SO_ERROR,<br />
                                 (char *)&amp;error, &amp;len)) &lt; 0) {<br />
                return errno;<br />
            }<br />
            if (error) {<br />
                return error;<br />
            }<br />
        }<br />
#endif /* SO_ERROR */<br />
    }</p>
<p>    if (rc == -1 &amp;&amp; errno != EISCONN) {<br />
        return errno;<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yu Feng</title>
		<link>http://blog.yufeng.info/archives/565/comment-page-1#comment-622</link>
		<dc:creator>Yu Feng</dc:creator>
		<pubDate>Tue, 18 May 2010 09:21:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.yufeng.info/?p=565#comment-622</guid>
		<description>我之前都没判断,所以觉得很多人不清楚,而且这个SO_ERROR不是每个平台都要这样!</description>
		<content:encoded><![CDATA[<p>我之前都没判断,所以觉得很多人不清楚,而且这个SO_ERROR不是每个平台都要这样!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hoterran</title>
		<link>http://blog.yufeng.info/archives/565/comment-page-1#comment-621</link>
		<dc:creator>hoterran</dc:creator>
		<pubDate>Tue, 18 May 2010 08:23:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.yufeng.info/?p=565#comment-621</guid>
		<description>非阻塞connect 都是这样的啊，返回值，error都要判断，没看到特殊之处</description>
		<content:encoded><![CDATA[<p>非阻塞connect 都是这样的啊，返回值，error都要判断，没看到特殊之处</p>
]]></content:encoded>
	</item>
</channel>
</rss>

