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
,
34 EFI_SERVICE_BINDING_PROTOCOL
* pServiceBinding
;
38 // Start closing the socket
40 Status
= pSocketProtocol
->pfnCloseStart ( pSocketProtocol
,
45 // Wait for the socket to close or an error
47 while ( EFI_NOT_READY
== Status
) {
48 Status
= pSocketProtocol
->pfnClosePoll ( pSocketProtocol
,
51 if ( !EFI_ERROR ( Status
)) {
53 // Locate the socket protocol
55 Status
= gBS
->LocateProtocol ( &gEfiSocketServiceBindingProtocolGuid
,
57 (VOID
**) &pServiceBinding
);
58 if ( !EFI_ERROR ( Status
)) {
62 Status
= pServiceBinding
->DestroyChild ( pServiceBinding
,
63 pSocketProtocol
->SocketHandle
);
65 if ( EFI_ERROR ( Status
)) {
71 "ERROR - Failed to close the socket: %r\r\n",
77 // Return the close status
86 @param[in] pDescriptor Descriptor address for the file
88 @return This routine returns 0 upon success and -1 upon failure.
89 In the case of failure, errno contains more information.
94 struct __filedes
* pDescriptor
98 EFI_SOCKET_PROTOCOL
* pSocketProtocol
;
101 // Locate the socket protocol
103 pSocketProtocol
= BslValidateSocketFd ( pDescriptor
, &errno
);
104 if ( NULL
!= pSocketProtocol
) {
108 BslSocketCloseWork ( pSocketProtocol
, &errno
);
112 // Return the close status
114 CloseStatus
= ( errno
== 0 ) ? 0 : -1;