]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/connect.c
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 There are three states associated with a connection:
26 <li>Not connected</li>
27 <li>Connection in progress</li>
30 In the initial "Not connected" state, calls to connect start the connection
31 processing and update the state to "Connection in progress". During
32 the "Connection in progress" state, connect polls for connection completion
33 and moves the state to "Connected" after the connection is established.
34 Note that these states are only visible when the file descriptor is marked
35 with O_NONBLOCK. Also, the POLLOUT bit is set when the connection
36 completes and may be used by poll or select as an indicator to call
40 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
41 documentation is available online.
43 @param [in] s Socket file descriptor returned from ::socket.
45 @param [in] address Network address of the remote system
47 @param [in] address_len Length of the remote network address
49 @return This routine returns zero if successful and -1 when an error occurs.
50 In the case of an error, ::errno contains more details.
56 const struct sockaddr
* address
,
62 struct __filedes
* pDescriptor
;
63 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
67 // Locate the context for this socket
69 pSocketProtocol
= BslFdToSocketProtocol ( s
,
72 if ( NULL
!= pSocketProtocol
) {
74 // Determine if the operation is blocking
76 bBlocking
= (BOOLEAN
)( 0 == ( pDescriptor
->Oflags
& O_NONBLOCK
));
79 // Attempt to connect to a remote system
83 Status
= pSocketProtocol
->pfnConnect ( pSocketProtocol
,
87 } while ( bBlocking
&& ( EFI_NOT_READY
== Status
));
91 // Return the new socket file descriptor
93 ConnectStatus
= (0 == errno
) ? 0 : -1;