]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/connect.c
Fix @return Doxygen commands to be singular instead of plural.
[mirror_edk2.git] / StdLib / BsdSocketLib / connect.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the connect API.\r
3\r
4 Copyright (c) 2011, Intel Corporation\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <SocketInternals.h>\r
16\r
17\r
18/**\r
19 Connect to a remote system via the network.\r
20\r
21 The ::connect routine attempts to establish a connection to a\r
22 socket on the local or remote system using the specified address.\r
23 The\r
24 <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/connect.html">POSIX</a>\r
25 documentation is available online.\r
26\r
27 There are three states associated with a connection:\r
28 <ul>\r
29 <li>Not connected</li>\r
30 <li>Connection in progress</li>\r
31 <li>Connected</li>\r
32 </ul>\r
33 In the "Not connected" state, calls to ::connect start the connection\r
34 processing and update the state to "Connection in progress". During\r
35 the "Connection in progress" state, connect polls for connection completion\r
36 and moves the state to "Connected" after the connection is established.\r
37 Note that these states are only visible when the file descriptor is marked\r
38 with O_NONBLOCK. Also, the POLL_WRITE bit is set when the connection\r
39 completes and may be used by poll or select as an indicator to call\r
40 connect again.\r
41\r
42 @param [in] s Socket file descriptor returned from ::socket.\r
43\r
44 @param [in] address Network address of the remote system\r
7dc13291 45\r
d7ce7006 46 @param [in] address_len Length of the remote network address\r
47\r
7dc13291 48 @return ::connect returns zero if successful and -1 when an error occurs.\r
d7ce7006 49 In the case of an error, errno contains more details.\r
50\r
51 **/\r
52int\r
53connect (\r
54 int s,\r
55 const struct sockaddr * address,\r
56 socklen_t address_len\r
57 )\r
58{\r
59 BOOLEAN bBlocking;\r
60 int ConnectStatus;\r
61 struct __filedes * pDescriptor;\r
62 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
63 EFI_STATUS Status;\r
7dc13291 64\r
d7ce7006 65 //\r
66 // Locate the context for this socket\r
67 //\r
68 pSocketProtocol = BslFdToSocketProtocol ( s,\r
69 &pDescriptor,\r
70 &errno );\r
71 if ( NULL != pSocketProtocol ) {\r
72 //\r
73 // TODO: Check for NON_BLOCKING\r
74 //\r
75 bBlocking = TRUE;\r
76\r
77 //\r
78 // Attempt to connect to a remote system\r
79 //\r
80 do {\r
81 errno = 0;\r
82 Status = pSocketProtocol->pfnConnect ( pSocketProtocol,\r
83 address,\r
84 address_len,\r
85 &errno );\r
86 } while ( bBlocking && ( EFI_NOT_READY == Status ));\r
87 }\r
7dc13291 88\r
d7ce7006 89 //\r
90 // Return the new socket file descriptor\r
91 //\r
92 ConnectStatus = (0 == errno) ? 0 : -1;\r
93 return ConnectStatus;\r
94}\r