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