]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/connect.c
Fix @return Doxygen commands to be singular instead of plural.
[mirror_edk2.git] / StdLib / BsdSocketLib / connect.c
1 /** @file
2 Implement the connect API.
3
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
9
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.
12
13 **/
14
15 #include <SocketInternals.h>
16
17
18 /**
19 Connect to a remote system via the network.
20
21 The ::connect routine attempts to establish a connection to a
22 socket on the local or remote system using the specified address.
23 The
24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>
25 documentation is available online.
26
27 There are three states associated with a connection:
28 <ul>
29 <li>Not connected</li>
30 <li>Connection in progress</li>
31 <li>Connected</li>
32 </ul>
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
40 connect again.
41
42 @param [in] s Socket file descriptor returned from ::socket.
43
44 @param [in] address Network address of the remote system
45
46 @param [in] address_len Length of the remote network address
47
48 @return ::connect returns zero if successful and -1 when an error occurs.
49 In the case of an error, errno contains more details.
50
51 **/
52 int
53 connect (
54 int s,
55 const struct sockaddr * address,
56 socklen_t address_len
57 )
58 {
59 BOOLEAN bBlocking;
60 int ConnectStatus;
61 struct __filedes * pDescriptor;
62 EFI_SOCKET_PROTOCOL * pSocketProtocol;
63 EFI_STATUS Status;
64
65 //
66 // Locate the context for this socket
67 //
68 pSocketProtocol = BslFdToSocketProtocol ( s,
69 &pDescriptor,
70 &errno );
71 if ( NULL != pSocketProtocol ) {
72 //
73 // TODO: Check for NON_BLOCKING
74 //
75 bBlocking = TRUE;
76
77 //
78 // Attempt to connect to a remote system
79 //
80 do {
81 errno = 0;
82 Status = pSocketProtocol->pfnConnect ( pSocketProtocol,
83 address,
84 address_len,
85 &errno );
86 } while ( bBlocking && ( EFI_NOT_READY == Status ));
87 }
88
89 //
90 // Return the new socket file descriptor
91 //
92 ConnectStatus = (0 == errno) ? 0 : -1;
93 return ConnectStatus;
94 }