Update contrib.
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // connectors for re-entrant networking system calls
22 #include <sys/socket.h>
27 @param family Specifies the address family used in the communications domain.
28 @param style Type of socket.
29 @param protocol Protocol used with that socket.
31 @return On Success, non-negative integer, the socket file descriptor.
32 On Failure, returns -1, eerno may be set.
34 EXPORT_C int socket (int family, int style, int protocol)
36 struct _reent *r = _REENT2;
38 return -1; // Memory for library globals is not allocated (errno not set).
39 return _socket_r (r, family, style, protocol);
41 EXPORT_C int _socket_r (struct _reent *r, int family, int style, int protocol)
43 MSystemInterface& sysIf=Interface(r);
44 return sysIf.socket(family,style,protocol,r->_errno);
48 Receives a message from a socket.
49 The recv() call can be used on a connection mode socket or a bound,
50 connectionless socket. If no messages are available at the socket,
51 the recv() call waits for a message to arrive unless the socket is nonblocking.
53 @param fd Specifies a socket descriptor to use for the send.
54 @param buf Points to the buffer containing message to send.
55 @param cnt Specifies the length of the message in bytes.
56 @param flags Lets the sender control the way data is sent.
58 @return On Success, returns the number of bytes received.
59 On Failure, returns -1, eerno may be set.
61 EXPORT_C int recv (int fd, char *buf, size_t cnt, int flags)
63 struct _reent *r = _REENT2;
65 return -1; // Memory for library globals is not allocated (errno not set).
66 return _recvfrom_r (r, fd, buf, cnt, flags, 0, 0);
70 @return On Succcess, returns length of message in bytes, can be 0.
71 On Failure, returns -1, errno may be set.
73 EXPORT_C int recvfrom (int fd, char *buf, size_t cnt, int flags, struct sockaddr* from, size_t* fromsize)
75 struct _reent *r = _REENT2;
77 return -1; // Memory for library globals is not allocated (errno not set).
78 return _recvfrom_r (r, fd, buf, cnt, flags, from ,fromsize);
80 EXPORT_C int _recvfrom_r (struct _reent *r, int fd, char *buf, size_t nbyte, int flags, struct sockaddr* from, size_t* fromsize)
82 MSystemInterface& sysIf=Interface(r);
83 return sysIf.recvfrom(fd,buf,nbyte,flags,from,(unsigned long*)fromsize,r->_errno);
87 Initiates transmission of a message from the specified socket to its peer.
88 The send() function sends a message only when the socket is connected.
90 @param fd Specifies a socket descriptor to use for the send.
91 @param buf Points to the buffer containing message to send.
92 @param cnt Specifies the length of the message in bytes.
93 @param flags Lets the sender control the way data is sent.
95 @return On Success, returns the numbers of characters sent.
96 On Failure, returns -1, errno may be set.
98 EXPORT_C int send (int fd, const char *buf, size_t cnt, int flags)
100 struct _reent *r = _REENT2;
102 return -1; // Memory for library globals is not allocated (errno not set).
103 return _sendto_r (r, fd, buf, cnt, flags, 0, 0);
107 @return On Success, returns the numbers of characters sent.
108 On Failure, returns -1, errno may be set.
110 EXPORT_C int sendto (int fd, const char *buf, size_t cnt, int flags, struct sockaddr* to, size_t tosize)
112 struct _reent *r = _REENT2;
114 return -1; // Memory for library globals is not allocated (errno not set).
115 return _sendto_r (r, fd, buf, cnt, flags, to, tosize);
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)
119 MSystemInterface& sysIf=Interface(r);
120 return sysIf.sendto(fd,buf,nbyte,flags,to,tosize,r->_errno);
124 Shuts down all or part of a full-duplex connection on the socket associated with fd.
126 @param fd Is the socket descriptor to shut down.
127 @param how Specifies the type of shutdown.
129 @return On Success, returns 0.
130 On Failure, returns -1, errno may be set.
132 EXPORT_C int shutdown (int fd, int how)
134 struct _reent *r = _REENT2;
136 return -1; // Memory for library globals is not allocated (errno not set).
137 return _shutdown_r (r, fd, how);
139 EXPORT_C int _shutdown_r (struct _reent *r, int fd, int how)
141 MSystemInterface& sysIf=Interface(r);
142 return sysIf.shutdown(fd,how,r->_errno);
146 Marks a connection-mode socket, specified by the socket argument fd,
147 as accepting connections, and limits the number of outstanding connections
148 in the socket's listen queue to the value specified by the n argument.
149 The socket fd is put into 'passive' mode where incoming connection
150 requests are acknowledged and queued pending acceptance by the process.
152 @param fd Is a descriptor identifying a bound, unconnected socket.
153 @param n Is the maximum length that the queue of pending connections
154 may grow to. If this value is SOMAXCONN, then the underlying service provider
155 responsible for socket fd sets the backlog to a maximum "reasonable" value.
157 @return On Success, returns 0.
158 On Failure, returns -1, errno may be set.
160 EXPORT_C int listen (int fd, int n)
162 struct _reent *r = _REENT2;
164 return -1; // Memory for library globals is not allocated (errno not set).
165 return _listen_r (r, fd, n);
167 EXPORT_C int _listen_r (struct _reent *r, int fd, int n)
169 MSystemInterface& sysIf=Interface(r);
170 return sysIf.listen(fd,n,r->_errno);
174 accepts a connection on a socket. An incoming connection is acknowledged and associated with
175 an immediately created socket. The original socket is returned to the listening state.
177 @param fd Is the integer descriptor of the desired socket.
178 @param addr Points to a sockaddr structure containing the socket address.
179 @param size Points to an integer that states the address length in bytes.
181 @return On Success, returns a non-negative integer, which is a descriptor of the accepted socket.
182 Upon return, addrlen contains the actual length in bytes of the address returned.
183 On Failure, returns -1, errno may be set.
185 EXPORT_C int accept (int fd, struct sockaddr *addr, size_t *size)
187 struct _reent *r = _REENT2;
189 return -1; // Memory for library globals is not allocated (errno not set).
190 return _accept_r (r, fd, addr, size);
192 EXPORT_C int _accept_r (struct _reent *r, int fd, struct sockaddr *addr, size_t *size)
194 MSystemInterface& sysIf=Interface(r);
195 int newfd=sysIf.accept(fd,r->_errno);
197 sysIf.sockname(newfd,addr,(unsigned long*)size,1,r->_errno); // getpeername
202 Associate that socket with a port.
204 @param fd Is the integer descriptor of the desired socket.
205 @param addr Points to a sockaddr structure containing the socket address.
206 @param size Points to an integer that states the address length in bytes.
208 @return On Success, returns 0.
209 On Failure, returns -1, errno may be set.
211 EXPORT_C int bind (int fd, struct sockaddr *addr, size_t size)
213 struct _reent *r = _REENT2;
215 return -1; // Memory for library globals is not allocated (errno not set).
216 return _bind_r (r, fd, addr, size);
218 EXPORT_C int _bind_r (struct _reent *r, int fd, struct sockaddr *addr, size_t size)
220 MSystemInterface& sysIf=Interface(r);
221 return sysIf.bind(fd,addr,size,r->_errno);
225 Used by a client program to establish communication with a remote entity
227 @param fd Is the integer descriptor of the desired socket.
228 @param addr Points to a sockaddr structure containing the socket address.
229 @param size Points to an integer that states the address length in bytes.
231 @return On Success, returns 0.
232 On Failure, returns -1, errno may be set.
234 EXPORT_C int connect (int fd, struct sockaddr *addr, size_t size)
236 struct _reent *r = _REENT2;
238 return -1; // Memory for library globals is not allocated (errno not set).
239 return _connect_r (r, fd, addr, size);
241 EXPORT_C int _connect_r (struct _reent *r, int fd, struct sockaddr *addr, size_t size)
243 MSystemInterface& sysIf=Interface(r);
244 return sysIf.connect(fd,addr,size,r->_errno);
248 Returns the current name for the specified socket. The namelen parameter should be initialized
249 to indicate the amount of space pointed to by name. When returned, namelen contains the actual
250 size (in bytes) of the name returned.
252 @param fd Is the integer descriptor of the desired socket.
253 @param addr Points to a sockaddr structure containing the socket address.
254 @param size Points to an integer that states the address length in bytes.
256 @return On Success, returns 0.
257 On Failure, returns -1, errno may be set.
259 EXPORT_C int getsockname (int fd, struct sockaddr *addr, size_t* size)
261 struct _reent *r = _REENT2;
263 return -1; // Memory for library globals is not allocated (errno not set).
264 return _getsockname_r (r, fd, addr, size);
266 EXPORT_C int _getsockname_r (struct _reent *r, int fd, struct sockaddr *addr, size_t* size)
268 MSystemInterface& sysIf=Interface(r);
269 return sysIf.sockname(fd,addr,(unsigned long*)size,0,r->_errno);
273 Returns the peer address of the specified socket.
275 @return On Success, returns 0.
276 On Failure, returns -1, errno may be set.
278 EXPORT_C int getpeername (int fd, struct sockaddr *addr, size_t* size)
280 struct _reent *r = _REENT2;
282 return -1; // Memory for library globals is not allocated (errno not set).
283 return _getpeername_r (r, fd, addr, size);
285 EXPORT_C int _getpeername_r (struct _reent *r, int fd, struct sockaddr *addr, size_t* size)
287 MSystemInterface& sysIf=Interface(r);
288 return sysIf.sockname(fd,addr,(unsigned long*)size,1,r->_errno);
292 Manipulates options associated with a socket.
294 @return On Success, returns 0.
295 On Failure, returns -1, errno may be set.
297 EXPORT_C int getsockopt (int fd, int level, int opt, void* buf, size_t* len)
299 struct _reent *r = _REENT2;
301 return -1; // Memory for library globals is not allocated (errno not set).
302 return _getsockopt_r (r, fd, level, opt, buf, len);
304 EXPORT_C int _getsockopt_r (struct _reent *r, int fd, int level, int opt, void* buf, size_t* len)
306 MSystemInterface& sysIf=Interface(r);
307 return sysIf.getsockopt(fd,level,opt,buf,(unsigned long*)len,r->_errno);
311 Manipulates options associated with a socket. Options can exist at multiple protocol levels.
312 However, the options are always present at the uppermost socket level. Options affect socket
313 operations, such as the routing of packets, out-of-band data transfer, and so on.
315 @param fd Specifies a socket for which an option should be set.
316 @param level Identifies whether the operation applies to the socket itself or to the underlying
317 protocol being used. The socket itself is identified by the symbolic constant SOL_SOCKET.
318 Other protocol levels require the protocol number for the appropriate protocol
319 controlling the option.
320 @param opt Specifies a single option to which the request applies,
321 negative option values are not support on Symbian OS.
322 @param buf Specifies a value for the option.
323 @param len Specifies the length of the option value.
325 @return On Success, returns 0.
326 On Failure, returns -1, errno may be set.
328 EXPORT_C int setsockopt (int fd, int level, int opt, void* buf, size_t len)
330 struct _reent *r = _REENT2;
332 return -1; // Memory for library globals is not allocated (errno not set).
333 return _setsockopt_r (r, fd, level, opt, buf, len);
335 EXPORT_C int _setsockopt_r (struct _reent *r, int fd, int level, int opt, void* buf, size_t len)
337 MSystemInterface& sysIf=Interface(r);
338 return sysIf.setsockopt(fd,level,opt,buf,len,r->_errno);