]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/close.c
Add missing IPv6 address definitions.
[mirror_edk2.git] / StdLib / BsdSocketLib / close.c
CommitLineData
d7ce7006 1/** @file\r
2 Implement the close 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 Worker routine to close the socket.\r
20\r
7dc13291 21 @param[in] pSocketProtocol Socket protocol structure address\r
d7ce7006 22\r
a88c3163 23 @param[in] pErrno Address of the ::errno variable\r
d7ce7006 24\r
25 @retval EFI_SUCCESS Successfully closed the socket\r
26\r
27**/\r
28EFI_STATUS\r
29BslSocketCloseWork (\r
30 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,\r
31 IN int * pErrno\r
32 )\r
33{\r
34 EFI_SERVICE_BINDING_PROTOCOL * pServiceBinding;\r
35 EFI_STATUS Status;\r
36\r
37 //\r
38 // Start closing the socket\r
39 //\r
40 Status = pSocketProtocol->pfnCloseStart ( pSocketProtocol,\r
41 FALSE,\r
42 pErrno );\r
43\r
44 //\r
45 // Wait for the socket to close or an error\r
46 //\r
47 while ( EFI_NOT_READY == Status ) {\r
48 Status = pSocketProtocol->pfnClosePoll ( pSocketProtocol,\r
49 pErrno );\r
50 }\r
51 if ( !EFI_ERROR ( Status )) {\r
52 //\r
53 // Locate the socket protocol\r
54 //\r
55 Status = gBS->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid,\r
56 NULL,\r
57 (VOID **) &pServiceBinding );\r
58 if ( !EFI_ERROR ( Status )) {\r
59 //\r
60 // Release the handle\r
61 //\r
62 Status = pServiceBinding->DestroyChild ( pServiceBinding,\r
63 pSocketProtocol->SocketHandle );\r
64 }\r
65 if ( EFI_ERROR ( Status )) {\r
66 *pErrno = EIO;\r
67 }\r
68 }\r
69 else {\r
70 DEBUG (( DEBUG_ERROR,\r
71 "ERROR - Failed to close the socket: %r\r\n",\r
72 Status ));\r
73 *pErrno = EIO;\r
74 }\r
75\r
76 //\r
77 // Return the close status\r
78 //\r
79 return Status;\r
80}\r
81\r
82\r
83/**\r
84 Close the socket\r
85\r
a88c3163 86 The BslSocketClose routine is called indirectly from the close file\r
87 system routine. This routine closes the socket and returns the\r
88 status to the caller.\r
89\r
7dc13291 90 @param[in] pDescriptor Descriptor address for the file\r
d7ce7006 91\r
7dc13291 92 @return This routine returns 0 upon success and -1 upon failure.\r
a88c3163 93 In the case of failure, ::errno contains more information.\r
d7ce7006 94\r
95**/\r
96int\r
7700f0f5 97EFIAPI\r
d7ce7006 98BslSocketClose (\r
99 struct __filedes * pDescriptor\r
100 )\r
101{\r
102 int CloseStatus;\r
103 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
104\r
105 //\r
106 // Locate the socket protocol\r
107 //\r
108 pSocketProtocol = BslValidateSocketFd ( pDescriptor, &errno );\r
109 if ( NULL != pSocketProtocol ) {\r
110 //\r
111 // Close the socket\r
112 //\r
113 BslSocketCloseWork ( pSocketProtocol, &errno );\r
114 }\r
115\r
116 //\r
117 // Return the close status\r
118 //\r
119 CloseStatus = ( errno == 0 ) ? 0 : -1;\r
120 return CloseStatus;\r
121}\r