]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/BsdSocketLib/SocketInternals.h
Fix some errors detected by the GCC 4.4 compiler.
[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 BslSocketClose (
86 struct __filedes * pDescriptor
87 );
88
89 /**
90 Worker routine to close the socket.
91
92 @param[in] pSocketProtocol Socket protocol structure address
93
94 @param[in] pErrno Address of the ::errno variable
95
96 @retval EFI_SUCCESS Successfully closed the socket
97
98 **/
99 EFI_STATUS
100 BslSocketCloseWork (
101 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
102 IN int * pErrno
103 );
104
105 /**
106 Poll the socket for activity
107
108 @param [in] pDescriptor Descriptor address for the file
109
110 @param [in] Events Mask of events to detect
111
112 @return Detected events for the socket
113
114 **/
115 short
116 BslSocketPoll (
117 IN struct __filedes * pDescriptor,
118 IN short Events
119 );
120
121 /**
122 Build a file descriptor for a socket.
123
124 @param [in] pSocketProtocol Socket protocol structure address
125
126 @param [in] pErrno Address of the errno variable
127
128 @return The file descriptor for the socket or -1 if an error occurs.
129
130 **/
131 int
132 BslSocketProtocolToFd (
133 IN EFI_SOCKET_PROTOCOL * pSocketProtocol,
134 IN int * pErrno
135 );
136
137 /**
138 Read support routine for sockets
139
140 The BslSocketRead routine is called indirectly by the read file
141 system routine. This routine is typically used for SOCK_STREAM
142 because it waits for receive data from the target system specified
143 in the ::connect call.
144
145 @param [in] pDescriptor Descriptor address for the file
146 @param [in] pOffset File offset
147 @param [in] LengthInBytes Number of bytes to read
148 @param [in] pBuffer Address of the buffer to receive the data
149
150 @return The number of bytes read or -1 if an error occurs.
151 In the case of an error, ::errno contains more details.
152
153 **/
154 ssize_t
155 BslSocketRead (
156 struct __filedes *pDescriptor,
157 off_t * pOffset,
158 size_t LengthInBytes,
159 void * pBuffer
160 );
161
162 /**
163 Write support routine for sockets
164
165 @param [in] pDescriptor Descriptor address for the file
166 @param [in] pOffset File offset
167 @param [in] LengthInBytes Number of bytes to write
168 @param [in] pBuffer Address of the data
169
170 @return The number of bytes written or -1 if an error occurs.
171 In the case of an error, ::errno contains more details.
172
173 **/
174 ssize_t
175 BslSocketWrite (
176 struct __filedes *pDescriptor,
177 off_t * pOffset,
178 size_t LengthInBytes,
179 const void * pBuffer
180 );
181
182 /**
183 Validate the socket's file descriptor
184
185 @param [in] pDescriptor Descriptor for the file
186
187 @param [in] pErrno Address of the errno variable
188
189 @return A pointer to the EFI_SOCKET_PROTOCOL structure or NULL if
190 an invalid file descriptor was passed in.
191
192 **/
193 EFI_SOCKET_PROTOCOL *
194 BslValidateSocketFd (
195 struct __filedes * pDescriptor,
196 int * pErrno
197 );
198
199 //------------------------------------------------------------------------------
200
201 #endif // _SOCKET_INTERNALS_H_