]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/close.c
2 Implement the close 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 Worker routine to close the socket.
21 @param[in] pSocketProtocol Socket protocol structure address
23 @param[in] pErrno Address of the ::errno variable
25 @retval EFI_SUCCESS Successfully closed the socket
30 IN EFI_SOCKET_PROTOCOL
* pSocketProtocol
,
37 // Start closing the socket
39 Status
= pSocketProtocol
->pfnCloseStart ( pSocketProtocol
,
44 // Wait for the socket to close or an error
46 while ( EFI_NOT_READY
== Status
) {
47 Status
= pSocketProtocol
->pfnClosePoll ( pSocketProtocol
,
50 if ( !EFI_ERROR ( Status
)) {
52 // Release the socket resources
54 *pErrno
= EslServiceFreeProtocol ( pSocketProtocol
);
58 "ERROR - Failed to close the socket: %r\r\n",
64 // Return the close status
73 The BslSocketClose routine is called indirectly from the close file
74 system routine. This routine closes the socket and returns the
77 @param[in] pDescriptor Descriptor address for the file
79 @return This routine returns 0 upon success and -1 upon failure.
80 In the case of failure, ::errno contains more information.
86 struct __filedes
* pDescriptor
90 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
93 // Locate the socket protocol
95 pSocketProtocol
= BslValidateSocketFd ( pDescriptor
, &errno
);
96 if ( NULL
!= pSocketProtocol
) {
100 BslSocketCloseWork ( pSocketProtocol
, &errno
);
104 // Return the close status
106 CloseStatus
= ( errno
== 0 ) ? 0 : -1;