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