]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/BsdSocketLib/close.c
UefiCpuPkg/MicrocodeUpdateDxe: Fix coding style issues in INF file
[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
d7ce7006 34 EFI_STATUS Status;\r
35\r
36 //\r
37 // Start closing the socket\r
38 //\r
39 Status = pSocketProtocol->pfnCloseStart ( pSocketProtocol,\r
40 FALSE,\r
41 pErrno );\r
42\r
43 //\r
44 // Wait for the socket to close or an error\r
45 //\r
46 while ( EFI_NOT_READY == Status ) {\r
47 Status = pSocketProtocol->pfnClosePoll ( pSocketProtocol,\r
48 pErrno );\r
49 }\r
50 if ( !EFI_ERROR ( Status )) {\r
51 //\r
4652be0c 52 // Release the socket resources\r
d7ce7006 53 //\r
4652be0c 54 *pErrno = EslServiceFreeProtocol ( pSocketProtocol );\r
d7ce7006 55 }\r
56 else {\r
57 DEBUG (( DEBUG_ERROR,\r
58 "ERROR - Failed to close the socket: %r\r\n",\r
59 Status ));\r
60 *pErrno = EIO;\r
61 }\r
62\r
63 //\r
64 // Return the close status\r
65 //\r
66 return Status;\r
67}\r
68\r
69\r
70/**\r
71 Close the socket\r
72\r
a88c3163 73 The BslSocketClose routine is called indirectly from the close file\r
74 system routine. This routine closes the socket and returns the\r
75 status to the caller.\r
76\r
7dc13291 77 @param[in] pDescriptor Descriptor address for the file\r
d7ce7006 78\r
7dc13291 79 @return This routine returns 0 upon success and -1 upon failure.\r
a88c3163 80 In the case of failure, ::errno contains more information.\r
d7ce7006 81\r
82**/\r
83int\r
7700f0f5 84EFIAPI\r
d7ce7006 85BslSocketClose (\r
86 struct __filedes * pDescriptor\r
87 )\r
88{\r
89 int CloseStatus;\r
90 EFI_SOCKET_PROTOCOL * pSocketProtocol;\r
91\r
92 //\r
93 // Locate the socket protocol\r
94 //\r
95 pSocketProtocol = BslValidateSocketFd ( pDescriptor, &errno );\r
96 if ( NULL != pSocketProtocol ) {\r
97 //\r
98 // Close the socket\r
99 //\r
100 BslSocketCloseWork ( pSocketProtocol, &errno );\r
101 }\r
102\r
103 //\r
104 // Return the close status\r
105 //\r
106 CloseStatus = ( errno == 0 ) ? 0 : -1;\r
107 return CloseStatus;\r
108}\r