]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/SocketInternals.h
UefiCpuPkg/MicrocodeUpdateDxe: Fix coding style issues in INF file
[mirror_edk2.git] / StdLib / BsdSocketLib / SocketInternals.h
1 /** @file
2 Definitions for the socket library.
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 #ifndef _SOCKET_INTERNALS_H_
16 #define _SOCKET_INTERNALS_H_
17
18 #include <Uefi.h>
19
20 //----------------------------------------------------------------------
21 //
22 // The following private files are required to support file descriptors
23 //
24
25 #include <kfile.h>
26 #include <MainData.h>
27
28 #include <Efi/SysEfi.h>
29
30 //
31 // End of private files
32 //
33 //----------------------------------------------------------------------
34
35 #include <Library/DebugLib.h>
36 #include <Library/UefiBootServicesTableLib.h>
37 #include <Library/UefiLib.h>
38
39 #include <Protocol/EfiSocket.h>
40 #include <Protocol/ServiceBinding.h>
41
42 #include <sys/errno.h>
43 #include <sys/poll.h>
44 #include <sys/EfiSysCall.h>
45 #include <sys/socket.h>
46
47 //------------------------------------------------------------------------------
48 // Support Routines
49 //------------------------------------------------------------------------------
50
51 /**
52 Translate from the socket file descriptor to the socket protocol.
53
54 @param [in] s Socket file descriptor returned from ::socket.
55
56 @param [in] ppDescriptor Address to receive the descriptor structure
57 address for the file
58 @param [in] pErrno Address of the errno variable
59
60 @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
61 an invalid file descriptor was passed in.
62
63 **/
64 EFI_SOCKET_PROTOCOL *
65 BslFdToSocketProtocol (
66 int s,
67 struct __filedes ** ppDescriptor,
68 int * pErrno
69 );
70
71 /**
72 Close the socket
73
74 The BslSocketClose routine is called indirectly from the close file
75 system routine. This routine closes the socket and returns the
76 status to the caller.
77
78 @param[in] pDescriptor Descriptor address for the file
79
80 @return This routine returns 0 upon success and -1 upon failure.
81 In the case of failure, ::errno contains more information.
82
83 **/
84 int
85 EFIAPI
86 BslSocketClose (
87 struct __filedes * pDescriptor
88 );
89
90 /**
91 Worker routine to close the socket.
92
93 @param[in] pSocketProtocol Socket protocol structure address
94
95 @param[in] pErrno Address of the ::errno variable
96
97 @retval EFI_SUCCESS Successfully closed the socket
98
99 **/
100 EFI_STATUS
101 BslSocketCloseWork (
102 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
103 IN int * pErrno
104 );
105
106 /**
107 Poll the socket for activity
108
109 @param [in] pDescriptor Descriptor address for the file
110
111 @param [in] Events Mask of events to detect
112
113 @return Detected events for the socket
114
115 **/
116 short
117 EFIAPI
118 BslSocketPoll (
119 IN struct __filedes * pDescriptor,
120 IN short Events
121 );
122
123 /**
124 Build a file descriptor for a socket.
125
126 @param [in] pSocketProtocol Socket protocol structure address
127
128 @param [in] pErrno Address of the errno variable
129
130 @return The file descriptor for the socket or -1 if an error occurs.
131
132 **/
133 int
134 BslSocketProtocolToFd (
135 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
136 IN int * pErrno
137 );
138
139 /**
140 Read support routine for sockets
141
142 The BslSocketRead routine is called indirectly by the read file
143 system routine. This routine is typically used for SOCK_STREAM
144 because it waits for receive data from the target system specified
145 in the ::connect call.
146
147 @param [in] pDescriptor Descriptor address for the file
148 @param [in] pOffset File offset
149 @param [in] LengthInBytes Number of bytes to read
150 @param [in] pBuffer Address of the buffer to receive the data
151
152 @return The number of bytes read or -1 if an error occurs.
153 In the case of an error, ::errno contains more details.
154
155 **/
156 ssize_t
157 EFIAPI
158 BslSocketRead (
159 struct __filedes *pDescriptor,
160 off_t * pOffset,
161 size_t LengthInBytes,
162 void * pBuffer
163 );
164
165 /**
166 Write support routine for sockets
167
168 @param [in] pDescriptor Descriptor address for the file
169 @param [in] pOffset File offset
170 @param [in] LengthInBytes Number of bytes to write
171 @param [in] pBuffer Address of the data
172
173 @return The number of bytes written or -1 if an error occurs.
174 In the case of an error, ::errno contains more details.
175
176 **/
177 ssize_t
178 EFIAPI
179 BslSocketWrite (
180 struct __filedes *pDescriptor,
181 off_t * pOffset,
182 size_t LengthInBytes,
183 const void * pBuffer
184 );
185
186 /**
187 Validate the socket's file descriptor
188
189 @param [in] pDescriptor Descriptor for the file
190
191 @param [in] pErrno Address of the errno variable
192
193 @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
194 an invalid file descriptor was passed in.
195
196 **/
197 EFI_SOCKET_PROTOCOL *
198 BslValidateSocketFd (
199 struct __filedes * pDescriptor,
200 int * pErrno
201 );
202
203 //------------------------------------------------------------------------------
204
205 #endif // _SOCKET_INTERNALS_H_