2 Implement the connect API.
4 Copyright (c) 2011, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include <SocketInternals.h>
19 Connect to a remote system via the network.
21 The ::connect routine attempts to establish a connection to a
22 socket on the local or remote system using the specified address.
24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
25 documentation is available online.
27 There are three states associated with a connection:
29 <li>Not connected</li>
30 <li>Connection in progress</li>
33 In the "Not connected" state, calls to ::connect start the connection
34 processing and update the state to "Connection in progress". During
35 the "Connection in progress" state, connect polls for connection completion
36 and moves the state to "Connected" after the connection is established.
37 Note that these states are only visible when the file descriptor is marked
38 with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection
39 completes and may be used by poll or select as an indicator to call
42 @param [in] s Socket file descriptor returned from ::socket.
44 @param [in] address Network address of the remote system
46 @param [in] address_len Length of the remote network address
48 @returns ::connect returns zero if successful and -1 when an error occurs.
49 In the case of an error, errno contains more details.
55 const struct sockaddr
* address
,
61 struct __filedes
* pDescriptor
;
62 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
66 // Locate the context for this socket
68 pSocketProtocol
= BslFdToSocketProtocol ( s
,
71 if ( NULL
!= pSocketProtocol
) {
73 // TODO: Check for NON_BLOCKING
78 // Attempt to connect to a remote system
82 Status
= pSocketProtocol
->pfnConnect ( pSocketProtocol
,
86 } while ( bBlocking
&& ( EFI_NOT_READY
== Status
));
90 // Return the new socket file descriptor
92 ConnectStatus
= (0 == errno
) ? 0 : -1;