Branch: Tag:

2014-08-26

2014-08-26 09:37:07 by Per Hedbor <ph@opera.com>

Added support for TCP_FASTOPEN (server and client)

The server support is always enabled if possible, on the client side
it is enabled if you pass an additional argument to connect (see the documentation).

172:   <span class='homogen--name'><b>connect</b></span>   </dt>   <dd><p><code><code class='datatype'>bool</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code><b>)</b></code><br> - <code><code class='datatype'>bool</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code>, <code class='datatype'>string</code> <code class='argument'>src_addr</code>, <code class='datatype'>int</code> <code class='argument'>src_port</code><b>)</b></code></p></dd> + <code><code class='datatype'>bool</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code>, <code class='datatype'>string</code> <code class='argument'>src_addr</code>, <code class='datatype'>int</code> <code class='argument'>src_port</code><b>)</b></code><br> + <code><code class='datatype'>string(8bit)</code>|<code class='datatype'>int(0..0)</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>dest_addr</code>, <code class='datatype'>int</code> <code class='argument'>dest_port</code>, <code class='datatype'>string</code>|<code class='datatype'>int(0..0)</code> <code class='argument'>src_addr</code>, <code class='datatype'>int</code>|<code class='datatype'>int(0..0)</code> <code class='argument'>src_port</code>, <code class='datatype'>string(8bit)</code> <code class='argument'>data</code><b>)</b></code></p></dd>      <dt class='head--doc'>Description</dt>   <dd class='body--doc'><p>Open a TCP/IP connection to the specified destination.</p>   <p> In nonblocking mode, success is indicated with the write-callback,    and failure with the close-callback or the read_oob-callback.</p> -  + <p> If the <code>data</code> argument is included the socket will use +  TCP_FAST_OPEN if available, if not the data will <i>not be +  sent</i>. In the data case the function either returns the data +  that has not been sent (only one packet can be sent with this +  option) or 0 if the connection failed immediately.</p>   </dd>   <dt class='head--doc'>Returns</dt> - <dd class='body--doc'><p>Returns <code class='expr'>1</code> on success, and <code class='expr'>0</code> on failure.</p> + <dd class='body--doc'><p>Returns <code class='expr'>1</code> or the remaining <code class='expr'>data</code> on success, and +  <code class='expr'>0</code> on failure.</p>   </dd>   <dt class='head--doc'>Note</dt>   <dd class='body--doc'><p>In nonblocking mode <code class='expr'>0</code> (zero) may be returned and <code>errno()</code> set
194:   <dt class='head--type'><span class='homogen--type'>Method</span>   <span class='homogen--name'><b>connect</b></span>   </dt> - <dd><p><code><code class='datatype'>int</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>host</code>, <code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>void</code>|<code class='datatype'>string</code> <code class='argument'>client</code>, <code class='datatype'>void</code>|<code class='datatype'>int</code>|<code class='datatype'>string</code> <code class='argument'>client_port</code><b>)</b></code></p></dd> + <dd><p><code><code class='modifier'>variant</code> <code class='datatype'>int</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>host</code>, <code class='datatype'>int(0..)</code>|<code class='datatype'>string</code> <code class='argument'>port</code><b>)</b></code><br> + <code><code class='modifier'>variant</code> <code class='datatype'>int</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>host</code>, <code class='datatype'>int(0..)</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>string</code> <code class='argument'>client</code>, <code class='datatype'>int(0..)</code>|<code class='datatype'>string</code> <code class='argument'>client_port</code><b>)</b></code><br> + <code><code class='modifier'>variant</code> <code class='datatype'>string</code> <b><span class='method'>connect</span>(</b><code class='datatype'>string</code> <code class='argument'>host</code>, <code class='datatype'>int(0..)</code>|<code class='datatype'>string</code> <code class='argument'>port</code>, <code class='datatype'>int(0..0)</code>|<code class='datatype'>string</code> <code class='argument'>client</code>, <code class='datatype'>int(0..)</code>|<code class='datatype'>string</code> <code class='argument'>client_port</code>, <code class='datatype'>string</code> <code class='argument'>data</code><b>)</b></code></p></dd>      <dt class='head--doc'>Description</dt> - <dd class='body--doc'><p>This function connects a socket previously created with -  <code>open_socket()</code> to a remote socket through TCP/IP. The -  <code>host</code> argument is the hostname or IP number of the remote machine. -  A local IP and port can be explicitly bound by specifying <code>client</code> -  and <code>client_port</code>.</p> + <dd class='body--doc'><p>Open a TCP/IP connection to the specified destination.</p> + <p> In nonblocking mode, success is indicated with the write-callback, +  and failure with the close-callback or the read_oob-callback.</p> + <p> The <code>host</code> argument is the hostname or IP number of the remote +  machine.</p> + <p> A local IP and port can be explicitly bound by specifying +  <code>client</code> and <code>client_port</code>.</p> + <p> If the <code>data</code> argument is included the socket will use +  TCP_FAST_OPEN if posible. In this mode the the function will +  return the part of the data that has not been sent to the remote +  server yet instead of 1 (you will have to use <code>write</code> to send +  this data).</p> + <p> Note that TCP_FAST_OPEN requires server support, the connection +  might fail even though the remote server exists. It might be +  advicable to retry without TCP_FAST_OPEN (and remember this +  fact)</p>   </dd>   <dt class='head--doc'>Returns</dt> - <dd class='body--doc'><p>This function returns 1 for success, 0 otherwise.</p> + <dd class='body--doc'><p>This function returns 1 or the remaining <code>data</code> for success, 0 +  otherwise.</p>   </dd>   <dt class='head--doc'>Note</dt>   <dd class='body--doc'><p>In nonblocking mode <code class='expr'>0</code> (zero) may be returned and -  <code>errno()</code> set to <code class='expr'>EWOULDBLOCK</code> or -  <code class='expr'>WSAEWOULDBLOCK</code>. This should not be regarded as a +  <code>errno()</code> set to <code class='expr'>EWOULDBLOCK</code> or <code class='expr'>WSAEWOULDBLOCK</code>.</p> + <p> This should not be regarded as a    connection failure. In nonblocking mode you need to wait for a    write or close callback before you know if the connection failed    or not.</p>
2456:    to an interface with that host name or IP number. Omitting this    will bind to all available IPv4 addresses; specifying "::" will    bind to all IPv4 and IPv6 addresses.</p> + <p> If the OS supports TCP_FASTOPEN it is enabled automatically.</p>   </dd>   <dt class='head--doc'>Returns</dt>   <dd class='body--doc'><p>1 is returned on success, zero on failure. <code>errno</code> provides