Initiates a connection on a specified socket.


#include <prio.h> 

PRStatus PR_Connect(
  PRFileDesc *fd, 
  const PRNetAddr *addr, 
  PRIntervalTime timeout);


The function has the following parameters:

A pointer to a PRFileDesc object representing a socket.
A pointer to the address of the peer to which the socket is to be connected.
A value of type PRIntervalTime specifying the time limit for completion of the connect operation.


The function returns one of the following values:


PR_Connect is usually invoked on a TCP socket, but it may also be invoked on a UDP socket. Both cases are discussed here.

If the socket is a TCP socket, PR_Connect establishes a TCP connection to the peer. If the socket is not bound, it will be bound to an arbitrary local address.

PR_Connect blocks until either the connection is successfully established or an error occurs. If the timeout parameter is not PR_INTERVAL_NO_TIMEOUT and the connection setup cannot complete before the time limit, PR_Connect fails with the error code PR_IO_TIMEOUT_ERROR.

If the socket is a UDP socket, there is no connection setup to speak of, since UDP is connectionless. If PR_Connect is invoked on a UDP socket, it has an overloaded meaning: PR_Connect merely saves the specified address as the default peer address for the socket, so that subsequently one can send and receive datagrams from the socket using PR_Send and PR_Recv instead of the usual PR_SendTo and PR_RecvFrom.