<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>Hello, we had a problem where the connection was taking much too long to timeout, so I configured the socket as non-blocking using the global RTMP timeout settings so that we could ditch the connection quicker if a host doesn’t exist. I test it on Windows and Ubuntu so take a look and let me know what ya’ll think, thanks!<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Index: rtmp.c<o:p></o:p></p><p class=MsoNormal>===================================================================<o:p></o:p></p><p class=MsoNormal>--- rtmp.c (revision 548)<o:p></o:p></p><p class=MsoNormal>+++ rtmp.c (working copy)<o:p></o:p></p><p class=MsoNormal>@@ -800,6 +800,7 @@<o:p></o:p></p><p class=MsoNormal> RTMP_Connect0(RTMP *r, struct sockaddr * service)<o:p></o:p></p><p class=MsoNormal> {<o:p></o:p></p><p class=MsoNormal> int on = 1;<o:p></o:p></p><p class=MsoNormal>+ int sflags;<o:p></o:p></p><p class=MsoNormal> r->m_sb.sb_timedout = FALSE;<o:p></o:p></p><p class=MsoNormal> r->m_pausing = 0;<o:p></o:p></p><p class=MsoNormal> r->m_fDuration = 0.0;<o:p></o:p></p><p class=MsoNormal>@@ -807,15 +808,44 @@<o:p></o:p></p><p class=MsoNormal> r->m_sb.sb_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);<o:p></o:p></p><p class=MsoNormal> if (r->m_sb.sb_socket != -1)<o:p></o:p></p><p class=MsoNormal> {<o:p></o:p></p><p class=MsoNormal>- if (connect(r->m_sb.sb_socket, service, sizeof(struct sockaddr)) < 0)<o:p></o:p></p><p class=MsoNormal>+ // set non-blocking<o:p></o:p></p><p class=MsoNormal>+#ifdef WIN32<o:p></o:p></p><p class=MsoNormal>+ u_long nonbon = 1;<o:p></o:p></p><p class=MsoNormal>+ ioctlsocket(r->m_sb.sb_socket, FIONBIO, &nonbon);<o:p></o:p></p><p class=MsoNormal>+#else<o:p></o:p></p><p class=MsoNormal>+ sflags = fcntl(r->m_sb.sb_socket, F_GETFL, 0); // Get socket flags<o:p></o:p></p><p class=MsoNormal>+ fcntl(r->m_sb.sb_socket, F_SETFL, sflags | O_NONBLOCK); // Add non-blocking flag<o:p></o:p></p><p class=MsoNormal>+#endif<o:p></o:p></p><p class=MsoNormal>+int ret;<o:p></o:p></p><p class=MsoNormal>+ if ((ret = connect(r->m_sb.sb_socket, service, sizeof(struct sockaddr))) < 0)<o:p></o:p></p><p class=MsoNormal> {<o:p></o:p></p><p class=MsoNormal> int err = GetSockError();<o:p></o:p></p><p class=MsoNormal>- RTMP_Log(RTMP_LOGERROR, "%s, failed to connect socket. %d (%s)",<o:p></o:p></p><p class=MsoNormal>- __FUNCTION__, err, strerror(err));<o:p></o:p></p><p class=MsoNormal>- RTMP_Close(r);<o:p></o:p></p><p class=MsoNormal>- return FALSE;<o:p></o:p></p><p class=MsoNormal>+ if (err != 10035 && err != 115){<o:p></o:p></p><p class=MsoNormal>+ RTMP_Log(RTMP_LOGERROR, "%s, failed to connect socket. %d (%s) %d",<o:p></o:p></p><p class=MsoNormal>+ __FUNCTION__, err, strerror(err), ret);<o:p></o:p></p><p class=MsoNormal>+ RTMP_Close(r);<o:p></o:p></p><p class=MsoNormal>+ return FALSE;<o:p></o:p></p><p class=MsoNormal>+ }<o:p></o:p></p><p class=MsoNormal> }<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal>+ // wait for data<o:p></o:p></p><p class=MsoNormal>+ fd_set rset, wset;<o:p></o:p></p><p class=MsoNormal>+ struct timeval tval;<o:p></o:p></p><p class=MsoNormal>+ FD_ZERO(&rset);<o:p></o:p></p><p class=MsoNormal>+ FD_SET(r->m_sb.sb_socket, &rset);<o:p></o:p></p><p class=MsoNormal>+ wset = rset;<o:p></o:p></p><p class=MsoNormal>+ tval.tv_sec = r->Link.timeout;<o:p></o:p></p><p class=MsoNormal>+ tval.tv_usec = 0;<o:p></o:p></p><p class=MsoNormal>+<o:p></o:p></p><p class=MsoNormal>+ int n;<o:p></o:p></p><p class=MsoNormal>+ if ( (n = select(r->m_sb.sb_socket+1, &rset, &wset, NULL, &tval)) == 0) {<o:p></o:p></p><p class=MsoNormal>+ close(r->m_sb.sb_socket);<o:p></o:p></p><p class=MsoNormal>+ RTMP_Log(RTMP_LOGERROR, "%s, socket connection timedout after %ds.", __FUNCTION__, r->Link.timeout);<o:p></o:p></p><p class=MsoNormal>+ RTMP_Close(r);<o:p></o:p></p><p class=MsoNormal>+ return FALSE;<o:p></o:p></p><p class=MsoNormal>+ }<o:p></o:p></p><p class=MsoNormal>+<o:p></o:p></p><p class=MsoNormal>+<o:p></o:p></p><p class=MsoNormal> if (r->Link.socksport)<o:p></o:p></p><p class=MsoNormal> {<o:p></o:p></p><p class=MsoNormal> RTMP_Log(RTMP_LOGDEBUG, "%s ... SOCKS negotiation", __FUNCTION__);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>