1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2<html xml:lang="en-US" lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <meta http-equiv="Content-Style-Type" content="text/css" /> 6 <link rel="stylesheet" href="../../css/manpage.css" type="text/css" /> 7<title>Connect</title> 8 </head> 9 <body> 10<h1><CODE><a href="../../nn/Overview.html">nn</a>::<a href="../../nn/socket/Overview.html">socket</a>::Connect</CODE> Function</h1> 11<h2>Syntax</h2> 12 <div class="section"> 13 <pre class="definition"> 14s32 Connect( 15 s32 s, 16 const <a href="../../nn/socket/SockAddrIn/Overview.html">SockAddrIn</a> * sockAddr 17); 18</pre> 19 </div> 20<h2>Arguments</h2> 21 <div class="section"> 22 <table class="arguments"> 23 <thead> 24 <tr> 25 <td width="15" /> 26<th>Name</th> 27<td>Description</td> 28 </tr> 29 </thead> 30 <tr> 31<td>in</td> 32<th>s</th> 33<td>Specifies the socket descriptor. Specify a socket descriptor created using the <a href="../../nn/socket/Socket.html"><CODE>Socket</CODE></a> function.</td> 34 </tr> 35 <tr> 36<td>in</td> 37<th>sockAddr</th> 38<td>Specifies a pointer to the socket address structure used to maintain address information about the communication target.</td> 39 </tr> </table> 40 </div> 41<h2>Return Values</h2> 42 <div class="section"> 43 <br /> <br /> 44 <table class="arguments"> 45 <thead> 46 <tr> 47<th>Value</th> 48<td>Description</td> 49 </tr> 50 </thead> 51 <tr> 52 <th>0</th> 53<td>Process was successful.</td> 54 </tr> 55 <tr> 56<th><CODE>EAFNOSUPPORT</CODE></th> 57<td>The protocol family of the socket does not support the specified address.</td> 58 </tr> 59 <tr> 60<th><CODE>EALREADY</CODE></th> 61<td>Already attempting connection in non-blocking mode.</td> 62 </tr> 63 <tr> 64<th><CODE>EBADF</CODE></th> 65<td>The socket descriptor is invalid.</td> 66 </tr> 67 <tr> 68<th><CODE>ECONNREFUSED</CODE></th> 69<td>The connection was reset just as a socket was opened for communication with the remote host.</td> 70 </tr> 71 <tr> 72<th><CODE>ECONNRESET</CODE></th> 73<td>The connection was reset for one of the following reasons: The connection was reset by the remote host to which connection is being attempted. A fatal ICMP notification (such as a Destination Unreachable message) was received while attempting connection.</td> 74 </tr> 75 <tr> 76<th><CODE>EINPROGRESS</CODE></th> 77<td>The specified socket is currently changing its status.</td> 78 </tr> 79 <tr> 80<th><CODE>EINVAL</CODE></th> 81<td>Indicates an illegal call of one of the following. The socket address specified in <SPAN class="argument">sockAddr</SPAN> is invalid.</td> 82 </tr> 83 <tr> 84<th><CODE>EISCONN</CODE></th> 85<td>The specified socket cannot be used by this process because it is being used for another purpose (for example, it is already connected).</td> 86 </tr> 87 <tr> 88<th><CODE>ENETDOWN</CODE></th> 89<td>The network is not available.</td> 90 </tr> 91 <tr> 92<th><CODE>ENETRESET</CODE></th> 93<td>Socket library is not initialized.</td> 94 </tr> 95 <tr> 96<th><CODE>ENETUNREACH</CODE></th> 97<td>Could not find the remote host to connect to.</td> 98 </tr> 99 <tr> 100<th><CODE>ENOBUFS</CODE></th> 101<td>Failed to temporarily assign a socket address to a socket that has not been assigned a communication source socket address.</td> 102 </tr> 103 <tr> 104<th><CODE>ENOMEM</CODE></th> 105<td>Cannot allocate the memory required for the process.</td> 106 </tr> 107 <tr> 108<th><CODE>ETIMEDOUT</CODE></th> 109<td>Timed out without receiving a response from the remote host to connect to.</td> 110 </tr> 111 </table> </div> 112<h2>Description</h2> 113 <div class="section"> 114<p>Uses the specified socket descriptor to attempt to connect to the specified remote host.</p><p>If no local address has been bound to the socket using the <a href="../../nn/socket/Bind.html"><CODE>Bind</CODE></a> function, then <a href="../../nn/socket/Connect.html"><CODE>Connect</CODE></a> binds an unused local address to the socket. For a stream socket (<CODE>SO_SOCK_STREAM</CODE>), this function usually blocks until a connection is established but it will return as soon as possible if non-blocking mode has been set by the <a href="../../nn/socket/Fcntl.html"><CODE>Fcntl</CODE></a> function. In such cases, use the <a href="../../nn/socket/Poll.html"><CODE>Poll</CODE></a> function to check whether a connection has been established. If the connection attempt failed, the <CODE>Poll</CODE> return value has its <CODE>POLLRDNORM</CODE> and <CODE>POLLWRNORM</CODE> bits set to <CODE>1</CODE>. You can also detect connection failures via the errors returned by functions that you later call to send or receive data. For a datagram socket (<CODE>SOCK_DGRAM</CODE>), this function has the same behavior in both blocking and non-blocking mode because it simply changes the socket address to which datagrams are sent.</p><!-- write here --></div> 115<h2>See Also</h2> 116 <div class="section"> 117<p class="reference"><a href="../../nn/socket/Socket.html"><CODE>Socket</CODE></a><br /> </p> 118 </div> 119<h2>Revision History</h2> 120 <div class="section"> 121 <dl class="history"> 122 <dt>2010/06/14</dt> 123<dd>Initial version.<br /> 124 </dd> 125 </dl> 126 </div> 127 <hr><p>CONFIDENTIAL</p></body> 128</html> 129