4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Implement the connect API.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Copyright (c) 2011, Intel Corporation
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync All rights reserved. This program and the accompanying materials
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync are licensed and made available under the terms and conditions of the BSD License
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync which accompanies this distribution. The full text of the license may be found at
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Connect to a remote system via the network.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync The connect routine attempts to establish a connection to a
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync socket on the local or remote system using the specified address.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync There are three states associated with a connection:
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync <li>Not connected</li>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync <li>Connection in progress</li>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync <li>Connected</li>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync In the initial "Not connected" state, calls to connect start the connection
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync processing and update the state to "Connection in progress". During
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync the "Connection in progress" state, connect polls for connection completion
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync and moves the state to "Connected" after the connection is established.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Note that these states are only visible when the file descriptor is marked
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync with O_NONBLOCK. Also, the POLLOUT bit is set when the connection
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync completes and may be used by poll or select as an indicator to call
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync connect again.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync documentation is available online.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param [in] s Socket file descriptor returned from ::socket.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param [in] address Network address of the remote system
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @param [in] address_len Length of the remote network address
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync @return This routine returns zero if successful and -1 when an error occurs.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync In the case of an error, ::errno contains more details.
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Locate the context for this socket
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Determine if the operation is blocking
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync bBlocking = (BOOLEAN)( 0 == ( pDescriptor->Oflags & O_NONBLOCK ));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Attempt to connect to a remote system
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync Status = pSocketProtocol->pfnConnect ( pSocketProtocol,
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync } while ( bBlocking && ( EFI_NOT_READY == Status ));
4fd606d1f5abe38e1f42c38de1d2e895166bd0f4vboxsync // Return the new socket file descriptor