sl@0
|
1 |
// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// connectors for re-entrant networking system calls
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include "SYSIF.H"
|
sl@0
|
19 |
#include "LPOSIX.H"
|
sl@0
|
20 |
|
sl@0
|
21 |
#include <reent.h>
|
sl@0
|
22 |
#include <sys/socket.h>
|
sl@0
|
23 |
|
sl@0
|
24 |
extern "C" {
|
sl@0
|
25 |
|
sl@0
|
26 |
/**
|
sl@0
|
27 |
@param family Specifies the address family used in the communications domain.
|
sl@0
|
28 |
@param style Type of socket.
|
sl@0
|
29 |
@param protocol Protocol used with that socket.
|
sl@0
|
30 |
|
sl@0
|
31 |
@return On Success, non-negative integer, the socket file descriptor.
|
sl@0
|
32 |
On Failure, returns -1, eerno may be set.
|
sl@0
|
33 |
*/
|
sl@0
|
34 |
EXPORT_C int socket (int family, int style, int protocol)
|
sl@0
|
35 |
{
|
sl@0
|
36 |
struct _reent *r = _REENT2;
|
sl@0
|
37 |
if (!r)
|
sl@0
|
38 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
39 |
return _socket_r (r, family, style, protocol);
|
sl@0
|
40 |
}
|
sl@0
|
41 |
EXPORT_C int _socket_r (struct _reent *r, int family, int style, int protocol)
|
sl@0
|
42 |
{
|
sl@0
|
43 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
44 |
return sysIf.socket(family,style,protocol,r->_errno);
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
/**
|
sl@0
|
48 |
Receives a message from a socket.
|
sl@0
|
49 |
The recv() call can be used on a connection mode socket or a bound,
|
sl@0
|
50 |
connectionless socket. If no messages are available at the socket,
|
sl@0
|
51 |
the recv() call waits for a message to arrive unless the socket is nonblocking.
|
sl@0
|
52 |
|
sl@0
|
53 |
@param fd Specifies a socket descriptor to use for the send.
|
sl@0
|
54 |
@param buf Points to the buffer containing message to send.
|
sl@0
|
55 |
@param cnt Specifies the length of the message in bytes.
|
sl@0
|
56 |
@param flags Lets the sender control the way data is sent.
|
sl@0
|
57 |
|
sl@0
|
58 |
@return On Success, returns the number of bytes received.
|
sl@0
|
59 |
On Failure, returns -1, eerno may be set.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
EXPORT_C int recv (int fd, char *buf, size_t cnt, int flags)
|
sl@0
|
62 |
{
|
sl@0
|
63 |
struct _reent *r = _REENT2;
|
sl@0
|
64 |
if (!r)
|
sl@0
|
65 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
66 |
return _recvfrom_r (r, fd, buf, cnt, flags, 0, 0);
|
sl@0
|
67 |
}
|
sl@0
|
68 |
|
sl@0
|
69 |
/**
|
sl@0
|
70 |
@return On Succcess, returns length of message in bytes, can be 0.
|
sl@0
|
71 |
On Failure, returns -1, errno may be set.
|
sl@0
|
72 |
*/
|
sl@0
|
73 |
EXPORT_C int recvfrom (int fd, char *buf, size_t cnt, int flags, struct sockaddr* from, size_t* fromsize)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
struct _reent *r = _REENT2;
|
sl@0
|
76 |
if (!r)
|
sl@0
|
77 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
78 |
return _recvfrom_r (r, fd, buf, cnt, flags, from ,fromsize);
|
sl@0
|
79 |
}
|
sl@0
|
80 |
EXPORT_C int _recvfrom_r (struct _reent *r, int fd, char *buf, size_t nbyte, int flags, struct sockaddr* from, size_t* fromsize)
|
sl@0
|
81 |
{
|
sl@0
|
82 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
83 |
return sysIf.recvfrom(fd,buf,nbyte,flags,from,(unsigned long*)fromsize,r->_errno);
|
sl@0
|
84 |
}
|
sl@0
|
85 |
|
sl@0
|
86 |
/**
|
sl@0
|
87 |
Initiates transmission of a message from the specified socket to its peer.
|
sl@0
|
88 |
The send() function sends a message only when the socket is connected.
|
sl@0
|
89 |
|
sl@0
|
90 |
@param fd Specifies a socket descriptor to use for the send.
|
sl@0
|
91 |
@param buf Points to the buffer containing message to send.
|
sl@0
|
92 |
@param cnt Specifies the length of the message in bytes.
|
sl@0
|
93 |
@param flags Lets the sender control the way data is sent.
|
sl@0
|
94 |
|
sl@0
|
95 |
@return On Success, returns the numbers of characters sent.
|
sl@0
|
96 |
On Failure, returns -1, errno may be set.
|
sl@0
|
97 |
*/
|
sl@0
|
98 |
EXPORT_C int send (int fd, const char *buf, size_t cnt, int flags)
|
sl@0
|
99 |
{
|
sl@0
|
100 |
struct _reent *r = _REENT2;
|
sl@0
|
101 |
if (!r)
|
sl@0
|
102 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
103 |
return _sendto_r (r, fd, buf, cnt, flags, 0, 0);
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
@return On Success, returns the numbers of characters sent.
|
sl@0
|
108 |
On Failure, returns -1, errno may be set.
|
sl@0
|
109 |
*/
|
sl@0
|
110 |
EXPORT_C int sendto (int fd, const char *buf, size_t cnt, int flags, struct sockaddr* to, size_t tosize)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
struct _reent *r = _REENT2;
|
sl@0
|
113 |
if (!r)
|
sl@0
|
114 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
115 |
return _sendto_r (r, fd, buf, cnt, flags, to, tosize);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
EXPORT_C int _sendto_r (struct _reent *r, int fd, const char *buf, size_t nbyte, int flags, struct sockaddr* to, size_t tosize)
|
sl@0
|
118 |
{
|
sl@0
|
119 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
120 |
return sysIf.sendto(fd,buf,nbyte,flags,to,tosize,r->_errno);
|
sl@0
|
121 |
}
|
sl@0
|
122 |
|
sl@0
|
123 |
/**
|
sl@0
|
124 |
Shuts down all or part of a full-duplex connection on the socket associated with fd.
|
sl@0
|
125 |
|
sl@0
|
126 |
@param fd Is the socket descriptor to shut down.
|
sl@0
|
127 |
@param how Specifies the type of shutdown.
|
sl@0
|
128 |
|
sl@0
|
129 |
@return On Success, returns 0.
|
sl@0
|
130 |
On Failure, returns -1, errno may be set.
|
sl@0
|
131 |
*/
|
sl@0
|
132 |
EXPORT_C int shutdown (int fd, int how)
|
sl@0
|
133 |
{
|
sl@0
|
134 |
struct _reent *r = _REENT2;
|
sl@0
|
135 |
if (!r)
|
sl@0
|
136 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
137 |
return _shutdown_r (r, fd, how);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
EXPORT_C int _shutdown_r (struct _reent *r, int fd, int how)
|
sl@0
|
140 |
{
|
sl@0
|
141 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
142 |
return sysIf.shutdown(fd,how,r->_errno);
|
sl@0
|
143 |
}
|
sl@0
|
144 |
|
sl@0
|
145 |
/**
|
sl@0
|
146 |
Marks a connection-mode socket, specified by the socket argument fd,
|
sl@0
|
147 |
as accepting connections, and limits the number of outstanding connections
|
sl@0
|
148 |
in the socket's listen queue to the value specified by the n argument.
|
sl@0
|
149 |
The socket fd is put into 'passive' mode where incoming connection
|
sl@0
|
150 |
requests are acknowledged and queued pending acceptance by the process.
|
sl@0
|
151 |
|
sl@0
|
152 |
@param fd Is a descriptor identifying a bound, unconnected socket.
|
sl@0
|
153 |
@param n Is the maximum length that the queue of pending connections
|
sl@0
|
154 |
may grow to. If this value is SOMAXCONN, then the underlying service provider
|
sl@0
|
155 |
responsible for socket fd sets the backlog to a maximum "reasonable" value.
|
sl@0
|
156 |
|
sl@0
|
157 |
@return On Success, returns 0.
|
sl@0
|
158 |
On Failure, returns -1, errno may be set.
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
EXPORT_C int listen (int fd, int n)
|
sl@0
|
161 |
{
|
sl@0
|
162 |
struct _reent *r = _REENT2;
|
sl@0
|
163 |
if (!r)
|
sl@0
|
164 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
165 |
return _listen_r (r, fd, n);
|
sl@0
|
166 |
}
|
sl@0
|
167 |
EXPORT_C int _listen_r (struct _reent *r, int fd, int n)
|
sl@0
|
168 |
{
|
sl@0
|
169 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
170 |
return sysIf.listen(fd,n,r->_errno);
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|
sl@0
|
173 |
/**
|
sl@0
|
174 |
accepts a connection on a socket. An incoming connection is acknowledged and associated with
|
sl@0
|
175 |
an immediately created socket. The original socket is returned to the listening state.
|
sl@0
|
176 |
|
sl@0
|
177 |
@param fd Is the integer descriptor of the desired socket.
|
sl@0
|
178 |
@param addr Points to a sockaddr structure containing the socket address.
|
sl@0
|
179 |
@param size Points to an integer that states the address length in bytes.
|
sl@0
|
180 |
|
sl@0
|
181 |
@return On Success, returns a non-negative integer, which is a descriptor of the accepted socket.
|
sl@0
|
182 |
Upon return, addrlen contains the actual length in bytes of the address returned.
|
sl@0
|
183 |
On Failure, returns -1, errno may be set.
|
sl@0
|
184 |
*/
|
sl@0
|
185 |
EXPORT_C int accept (int fd, struct sockaddr *addr, size_t *size)
|
sl@0
|
186 |
{
|
sl@0
|
187 |
struct _reent *r = _REENT2;
|
sl@0
|
188 |
if (!r)
|
sl@0
|
189 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
190 |
return _accept_r (r, fd, addr, size);
|
sl@0
|
191 |
}
|
sl@0
|
192 |
EXPORT_C int _accept_r (struct _reent *r, int fd, struct sockaddr *addr, size_t *size)
|
sl@0
|
193 |
{
|
sl@0
|
194 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
195 |
int newfd=sysIf.accept(fd,r->_errno);
|
sl@0
|
196 |
if (newfd>=0)
|
sl@0
|
197 |
sysIf.sockname(newfd,addr,(unsigned long*)size,1,r->_errno); // getpeername
|
sl@0
|
198 |
return newfd;
|
sl@0
|
199 |
}
|
sl@0
|
200 |
|
sl@0
|
201 |
/**
|
sl@0
|
202 |
Associate that socket with a port.
|
sl@0
|
203 |
|
sl@0
|
204 |
@param fd Is the integer descriptor of the desired socket.
|
sl@0
|
205 |
@param addr Points to a sockaddr structure containing the socket address.
|
sl@0
|
206 |
@param size Points to an integer that states the address length in bytes.
|
sl@0
|
207 |
|
sl@0
|
208 |
@return On Success, returns 0.
|
sl@0
|
209 |
On Failure, returns -1, errno may be set.
|
sl@0
|
210 |
*/
|
sl@0
|
211 |
EXPORT_C int bind (int fd, struct sockaddr *addr, size_t size)
|
sl@0
|
212 |
{
|
sl@0
|
213 |
struct _reent *r = _REENT2;
|
sl@0
|
214 |
if (!r)
|
sl@0
|
215 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
216 |
return _bind_r (r, fd, addr, size);
|
sl@0
|
217 |
}
|
sl@0
|
218 |
EXPORT_C int _bind_r (struct _reent *r, int fd, struct sockaddr *addr, size_t size)
|
sl@0
|
219 |
{
|
sl@0
|
220 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
221 |
return sysIf.bind(fd,addr,size,r->_errno);
|
sl@0
|
222 |
}
|
sl@0
|
223 |
|
sl@0
|
224 |
/**
|
sl@0
|
225 |
Used by a client program to establish communication with a remote entity
|
sl@0
|
226 |
|
sl@0
|
227 |
@param fd Is the integer descriptor of the desired socket.
|
sl@0
|
228 |
@param addr Points to a sockaddr structure containing the socket address.
|
sl@0
|
229 |
@param size Points to an integer that states the address length in bytes.
|
sl@0
|
230 |
|
sl@0
|
231 |
@return On Success, returns 0.
|
sl@0
|
232 |
On Failure, returns -1, errno may be set.
|
sl@0
|
233 |
*/
|
sl@0
|
234 |
EXPORT_C int connect (int fd, struct sockaddr *addr, size_t size)
|
sl@0
|
235 |
{
|
sl@0
|
236 |
struct _reent *r = _REENT2;
|
sl@0
|
237 |
if (!r)
|
sl@0
|
238 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
239 |
return _connect_r (r, fd, addr, size);
|
sl@0
|
240 |
}
|
sl@0
|
241 |
EXPORT_C int _connect_r (struct _reent *r, int fd, struct sockaddr *addr, size_t size)
|
sl@0
|
242 |
{
|
sl@0
|
243 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
244 |
return sysIf.connect(fd,addr,size,r->_errno);
|
sl@0
|
245 |
}
|
sl@0
|
246 |
|
sl@0
|
247 |
/**
|
sl@0
|
248 |
Returns the current name for the specified socket. The namelen parameter should be initialized
|
sl@0
|
249 |
to indicate the amount of space pointed to by name. When returned, namelen contains the actual
|
sl@0
|
250 |
size (in bytes) of the name returned.
|
sl@0
|
251 |
|
sl@0
|
252 |
@param fd Is the integer descriptor of the desired socket.
|
sl@0
|
253 |
@param addr Points to a sockaddr structure containing the socket address.
|
sl@0
|
254 |
@param size Points to an integer that states the address length in bytes.
|
sl@0
|
255 |
|
sl@0
|
256 |
@return On Success, returns 0.
|
sl@0
|
257 |
On Failure, returns -1, errno may be set.
|
sl@0
|
258 |
*/
|
sl@0
|
259 |
EXPORT_C int getsockname (int fd, struct sockaddr *addr, size_t* size)
|
sl@0
|
260 |
{
|
sl@0
|
261 |
struct _reent *r = _REENT2;
|
sl@0
|
262 |
if (!r)
|
sl@0
|
263 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
264 |
return _getsockname_r (r, fd, addr, size);
|
sl@0
|
265 |
}
|
sl@0
|
266 |
EXPORT_C int _getsockname_r (struct _reent *r, int fd, struct sockaddr *addr, size_t* size)
|
sl@0
|
267 |
{
|
sl@0
|
268 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
269 |
return sysIf.sockname(fd,addr,(unsigned long*)size,0,r->_errno);
|
sl@0
|
270 |
}
|
sl@0
|
271 |
|
sl@0
|
272 |
/**
|
sl@0
|
273 |
Returns the peer address of the specified socket.
|
sl@0
|
274 |
|
sl@0
|
275 |
@return On Success, returns 0.
|
sl@0
|
276 |
On Failure, returns -1, errno may be set.
|
sl@0
|
277 |
*/
|
sl@0
|
278 |
EXPORT_C int getpeername (int fd, struct sockaddr *addr, size_t* size)
|
sl@0
|
279 |
{
|
sl@0
|
280 |
struct _reent *r = _REENT2;
|
sl@0
|
281 |
if (!r)
|
sl@0
|
282 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
283 |
return _getpeername_r (r, fd, addr, size);
|
sl@0
|
284 |
}
|
sl@0
|
285 |
EXPORT_C int _getpeername_r (struct _reent *r, int fd, struct sockaddr *addr, size_t* size)
|
sl@0
|
286 |
{
|
sl@0
|
287 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
288 |
return sysIf.sockname(fd,addr,(unsigned long*)size,1,r->_errno);
|
sl@0
|
289 |
}
|
sl@0
|
290 |
|
sl@0
|
291 |
/**
|
sl@0
|
292 |
Manipulates options associated with a socket.
|
sl@0
|
293 |
|
sl@0
|
294 |
@return On Success, returns 0.
|
sl@0
|
295 |
On Failure, returns -1, errno may be set.
|
sl@0
|
296 |
*/
|
sl@0
|
297 |
EXPORT_C int getsockopt (int fd, int level, int opt, void* buf, size_t* len)
|
sl@0
|
298 |
{
|
sl@0
|
299 |
struct _reent *r = _REENT2;
|
sl@0
|
300 |
if (!r)
|
sl@0
|
301 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
302 |
return _getsockopt_r (r, fd, level, opt, buf, len);
|
sl@0
|
303 |
}
|
sl@0
|
304 |
EXPORT_C int _getsockopt_r (struct _reent *r, int fd, int level, int opt, void* buf, size_t* len)
|
sl@0
|
305 |
{
|
sl@0
|
306 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
307 |
return sysIf.getsockopt(fd,level,opt,buf,(unsigned long*)len,r->_errno);
|
sl@0
|
308 |
}
|
sl@0
|
309 |
|
sl@0
|
310 |
/**
|
sl@0
|
311 |
Manipulates options associated with a socket. Options can exist at multiple protocol levels.
|
sl@0
|
312 |
However, the options are always present at the uppermost socket level. Options affect socket
|
sl@0
|
313 |
operations, such as the routing of packets, out-of-band data transfer, and so on.
|
sl@0
|
314 |
|
sl@0
|
315 |
@param fd Specifies a socket for which an option should be set.
|
sl@0
|
316 |
@param level Identifies whether the operation applies to the socket itself or to the underlying
|
sl@0
|
317 |
protocol being used. The socket itself is identified by the symbolic constant SOL_SOCKET.
|
sl@0
|
318 |
Other protocol levels require the protocol number for the appropriate protocol
|
sl@0
|
319 |
controlling the option.
|
sl@0
|
320 |
@param opt Specifies a single option to which the request applies,
|
sl@0
|
321 |
negative option values are not support on Symbian OS.
|
sl@0
|
322 |
@param buf Specifies a value for the option.
|
sl@0
|
323 |
@param len Specifies the length of the option value.
|
sl@0
|
324 |
|
sl@0
|
325 |
@return On Success, returns 0.
|
sl@0
|
326 |
On Failure, returns -1, errno may be set.
|
sl@0
|
327 |
*/
|
sl@0
|
328 |
EXPORT_C int setsockopt (int fd, int level, int opt, void* buf, size_t len)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
struct _reent *r = _REENT2;
|
sl@0
|
331 |
if (!r)
|
sl@0
|
332 |
return -1; // Memory for library globals is not allocated (errno not set).
|
sl@0
|
333 |
return _setsockopt_r (r, fd, level, opt, buf, len);
|
sl@0
|
334 |
}
|
sl@0
|
335 |
EXPORT_C int _setsockopt_r (struct _reent *r, int fd, int level, int opt, void* buf, size_t len)
|
sl@0
|
336 |
{
|
sl@0
|
337 |
MSystemInterface& sysIf=Interface(r);
|
sl@0
|
338 |
return sysIf.setsockopt(fd,level,opt,buf,len,r->_errno);
|
sl@0
|
339 |
}
|
sl@0
|
340 |
|
sl@0
|
341 |
|
sl@0
|
342 |
} // extern "C"
|