OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [classpath/] [native/] [jni/] [java-nio/] [javanio.h] - Blame information for rev 774

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 774 jeremybenn
/* javanio.h -- reference implementation of native functions.
2
   Copyright (C) 2006  Free Software Foundation, Inc.
3
 
4
This file is a part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or (at
9
your option) any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19
USA
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
37
 
38
 
39
#ifndef __JAVANIO_H__
40
#define __JAVANIO_H__
41
 
42
#include <sys/time.h>
43
 
44
/**
45
 * This header defines functions that are called by our JNI reference
46
 * implementation of java.nio.*. In our reference implementation, these
47
 * functions map exactly to their counterparts in POSIX; in implementations
48
 * that can't use these functions directly (such as systems that use user-land
49
 * threads, and thus can't call blocking system calls directly) can provide
50
 * their own implementations suitable for their system.
51
 */
52
 
53
/**
54
 * This macro is used in all function prototypes below; if any additional
55
 * keywords need to be added to a prototype, declare them in this macro.
56
 */
57
#define CPNIO_EXPORT static inline
58
 
59
/**
60
 * Read bytes from the given file descriptor into the given memory address, which
61
 * has sufficient space for NBYTES bytes.
62
 *
63
 * \param fd     The file descriptor to read from.
64
 * \param buf    The memory address to read bytes into.
65
 * \param nbytes The number of bytes available to store in BUF.
66
 * \return The number of bytes read, possibly zero, on success; return -1 on failure,
67
 *  and set ERRNO to an appropriate value.
68
 * \see read(2)
69
 *
70
 * Allowed errno values:
71
 *   [EBADF]   If FD is not a valid file descriptor, or is not open for reading.
72
 *   [EFAULT]  If BUF points outside the process's address space.
73
 *   [EIO]     An I/O error occurrs.
74
 *   [EINTR]   If the read is interrupted by a signal.
75
 *   [EINVAL]  If FD is negative.
76
 *   [EAGAIN]  If FD was marked for non-blocking I/O, and no data were ready to
77
 *             be read.
78
 */
79
CPNIO_EXPORT ssize_t cpnio_read (int fd, void *buf, size_t nbytes);
80
 
81
/*
82
 * Read bytes from a file descriptor into a sequence of IO buffers.
83
 *
84
 * The iovec structure is defined as:
85
 *
86
 *   struct iovec {
87
 *     char   *iov_base;
88
 *     size_t  iov_len;
89
 *   };
90
 *
91
 * The call to _cp_readv should do a scattering read, where for each struct iovec
92
 * in the supplied list, up to IOV_LEN bytes are read into IOV_BASE. The function
93
 * returns the total number of bytes read into all supplied buffers.
94
 *
95
 * \param fd     The file descriptor.
96
 * \param iov    A pointer to the head of a list of iovec structures.
97
 * \param iovcnt The number of iovec structures pointed to by IOV.
98
 * \return The total number of bytes read accross all buffers, possibly zero. On
99
 *  error, -1 is returned and ERRNO is set.
100
 * \see readv(2)
101
 *
102
 * Allowed ERRNO values include all of those listed for _cp_read, as well as the
103
 * following:
104
 *   [EINVAL] If IOVCNT overflows the maximum number of iovec structures
105
 *            this platform supports (usually 16), if any IOV_LEN value
106
 *            is negative, or if the sum of all IOV_LEN values is too
107
 *            large to be stored in a ssize_t (usually a 32-bit integer).
108
 *   [EFAULT] If part of IOV points outside the process's address space.
109
 */
110
CPNIO_EXPORT ssize_t cpnio_readv (int fd, const struct iovec *iov, int iovcnt);
111
 
112
/*
113
 * Write NBYTES bytes from BUF to the file descriptor FD, returning the number
114
 * of bytes successfully written.
115
 *
116
 * \param fd     The file descriptor.
117
 * \param buf    A pointer to the bytes to write.
118
 * \param nbytes The maximum number of bytes to write.
119
 * \return The number of bytes written to the file descriptor, possibly zero. -1
120
 *  is returned if an error is encountered, and ERRNO will be set.
121
 * \see write(2)
122
 *
123
 * Allowed ERRNO values:
124
 *   [EBADF]   If FD is not a valid file descriptor or is not open for writing.
125
 *   [EPIPE]   If FD is a pipe, when the other side is disconnected; if FD is a
126
 *             socket, when the peer is not connected.
127
 *   [EFBIG]   When FD is a file, and writing to it overflows the process's
128
 *             or the system's maximim file size.
129
 *   [EFAULT]  If the buffer to write points outside the process's address
130
 *             space.
131
 *   [EINVAL]  If the descriptor FD is negative.
132
 *   [ENOSPC]  If FD is a file, and there is insufficient space on the
133
 *             filesystem.
134
 *   [EDQUOT]  If FD is a file, and the user's disk quota has been exceeded.
135
 *   [EIO]     If an I/O error occurs.
136
 *   [EINTR]   If the call is interrupted by a signal.
137
 *   [EAGAIN]  If FD is in non-blocking mode, and no bytes could be immediately
138
 *             written.
139
 */
140
CPNIO_EXPORT ssize_t cpnio_write (int fd, const void *buf, size_t nbytes);
141
 
142
/*
143
 * Write data from a sequence of IOVCNT buffers IOV to a file descriptor FD.
144
 *
145
 * \param fd     The file descriptor.
146
 * \param iov    The list of buffers to write.
147
 * \param iovcnt The number of iovec structures pointed to by IOV.
148
 * \return The total number of bytes written from the given buffers, possibly
149
 *   zero. -1 if an error occurs, and ERRNO will be set.
150
 * \see writev(2)
151
 *
152
 * Allowed ERRNO values include those mentioned in _cp_write, as well as:
153
 *  [EDESTADDRREQ]  If the descriptor is a datagram socket, and the peer is
154
 *                  no longer available.
155
 *  [EINVAL]        If IOVCNT is out of range, if any IOV_LEN value is
156
 *                  negative, or if the sum of all IOVCNT IOV_LEN values
157
 *                  will overflow a ssize_t.
158
 *  [ENOBUFS]       If the mbuf pool is exhausted (???).
159
 */
160
CPNIO_EXPORT ssize_t cpnio_writev (int fd, const struct iovec *iov, size_t iovcnt);
161
 
162
/**
163
 * Open a new, unbound and unconnected socket.
164
 *
165
 * \param domain The socket domain. Implementations need only handle AF_INET.
166
 * \param type   The socket type; implementations need only handle types
167
 *  SOCK_STREAM (for streaming sockets) and SOCK_DGRAM (for datagram sockets).
168
 * \param protocol This should always be 0. It can be ignored.
169
 * \return A new file descriptor pointing to a newly created socket, or -1 on
170
 *  error, and ERRNO set.
171
 *
172
 * Allowed ERRNO values:
173
 *  [EPROTONOSUPPORT]  If TYPE is unrecognized.
174
 *  [EMFILE]           If a new file descriptor cannot be allocated, because
175
 *                     the process's descriptor table is full.
176
 *  [ENFILE]           Likewise, but when the system table is full.
177
 *  [EACCES]           If this operation is not allowed.
178
 *  [ENOBUFS]          If there is not enough buffer space available for the
179
 *                     new socket.
180
 */
181
CPNIO_EXPORT int cpnio_socket (int domain, int type, int protocol);
182
 
183
/**
184
 * Connect a socket to a remote address.
185
 *
186
 * \param fd      The file descriptor of the socket to connect.
187
 * \param addr    The address to connect to. In practice, this should be
188
 *                either a `struct sockaddr_in' or a `struct sockaddr_in6'.
189
 * \param addrlen The size of the address structure passed by ADDR.
190
 * \return Zero if the connect succeeds. -1 on error, and ERRNO should be set.
191
 *
192
 * Allowed ERRNO values:
193
 *  [EBADF]         If FD is not a valid file descriptor.
194
 *  [ENOTSOCK]      If FD is not a socket descriptor.
195
 *  [EADDRNOTAVAIL] If ADDR is not available for use to this process.
196
 *  [EAFNOSUPPORT]  If the address family of ADDR is not supported.
197
 *  [EISCONN]       If the socket is already connected.
198
 *  [ETIMEDOUT]     If the connection could not be made in a reasonable
199
 *                  amount of time.
200
 *  [ECONNREFUSED]  If the connection attempt was rejected.
201
 *  [ENETUNREACH]   If the network ADDR is on is unreachable.
202
 *  [EADDRINUSE]    If the address is already in use.
203
 *  [EFAULT]        If ADDR points outside the addressable space.
204
 *  [EINPROGRESS]   If FD is in non-blocking mode, and the connection could
205
 *                  not be completed immediately.
206
 *  [EALREADY]      If FD is in non-blocking mode, and a connection attempt
207
 *                  is still pending.
208
 *  [EACCESS]       If ADDR is the broadcast address, and the socket option
209
 *                  SO_BROADCAST is not set.
210
 */
211
CPNIO_EXPORT int cpnio_connect (int fd, const struct sockaddr *addr, socklen_t addrlen);
212
 
213
/**
214
 * Accept an incoming connection on a socket, returning a new socket for
215
 * the connection, and storing the peer address in ADDR.
216
 *
217
 * \param fd      The socket file descriptor.
218
 * \param addr    The structure to store the peer address in.
219
 * \param addrlen The size of the data available in ADDR; upon return, the
220
 *                number of bytes stored in ADDR will be placed here.
221
 * \return The new socket file descriptor, or -1 on error, and ERRNO set.
222
 *
223
 * Allowed ERRNO values:
224
 *  [EBADF]         If FD is not a valid file descriptor.
225
 *  [ENOTSOCK]      If FD in not a socket descriptor.
226
 *  [EOPNOTSUPP]    If the socket is not a SOCK_STREAM socket.
227
 *  [EFAULT]        If ADDR points outside the process's addressable space.
228
 *  [EWOULDBLOCK]   If the socket is in non-blocking mode, and no connection
229
 *                  attempt is currently ready.
230
 *  [EMFILE]        If the process's descriptor table is full.
231
 *  [ENFILE]        If the system's descriptor table is full.
232
 */
233
CPNIO_EXPORT int cpnio_accept (int fd, struct sockaddr *addr, socklen_t *addrlen);
234
 
235
/**
236
 * Send a datagram to the given address.
237
 *
238
 * \param fd    The socket file descriptor.
239
 * \param msg   A pointer to the message to send.
240
 * \param len   The size of the message to send.
241
 * \param flags Flags for sending.
242
 * \param to    The remote address to send the message to.
243
 * \param tolen The size of the TO address structure.
244
 * \return The number of bytes written, possibly zero, on success. Returns
245
 *  -1 on failure, and sets ERRNO.
246
 * \see sendto(2)
247
 *
248
 * Allowed ERRNO values:
249
 *  [EBADF]
250
 *  [ENOTSOCK]
251
 *  [EFAULT]
252
 *  [EMSGSIZE]
253
 *  [EAGAIN]
254
 *  [ENOBUFS]
255
 *  [EACCES]
256
 *  [EHOSTUNREACH]
257
 */
258
CPNIO_EXPORT ssize_t cpnio_sendto (int fd, const void *msg, size_t len, int flags,
259
                                   const struct sockaddr *to, socklen_t tolen);
260
 
261
/**
262
 * Receive a message on a socket, storing the remote host's address in
263
 * FROM.
264
 *
265
 * \param fd      The socket file descriptor.
266
 * \param buf     The buffer to store received bytes in.
267
 * \param flags   Flags to control the receive.
268
 * \param from    Where to store the remote address.
269
 * \param fromlen Pointer to the size of FROM; on return, it will contain the
270
 *  size of the structure placed in FROM.
271
 * \return The number of bytes received on success. -1 on error, and ERRNO will
272
 *  be set.
273
 * \see recvfrom(2)
274
 *
275
 * Allewed ERRNO values:
276
 *  [EBADF]    FD is not a valid file descriptor.
277
 *  [ENOTCONN] If the socket is stream-oriented, and no prior call to
278
 *             connect(2) was made.
279
 *  [ENOTSOCK] FD is not a socket.
280
 *  [EAGAIN]   FD is in non-blocking mode, and no message was
281
 *             immediately available.
282
 *  [EINTR]    The system call was interrupted by a signal.
283
 *  [EFAULT]   BUF, FROM, or FROMLEN lie outside the process's address
284
 *             space.
285
 */
286
CPNIO_EXPORT ssize_t cpnio_recvfrom (int fd, void *buf, size_t len, int flags,
287
                                     struct sockaddr *from, socklen_t *fromlen);
288
 
289
 
290
/**
291
 * Control file descriptor properties.
292
 *
293
 * \param fd  The file descriptor to control.
294
 * \param cmd The command to execute.
295
 * \param arg The command argument.
296
 * \return A value other than -1, specific to CMD. On error, -1 is
297
 *  returned, and ERRNO is set.
298
 *
299
 * Allowed ERRNO values:
300
 *  FIXME
301
 */
302
CPNIO_EXPORT int cpnio_fcntl (int fd, int cmd, long arg);
303
 
304
 
305
/**
306
 * Select from one of the given file descriptor sets a descriptor that
307
 * is ready for the given operation (read, write, etc.).
308
 *
309
 * \param nfds      A value one larger than the largest file
310
 *                  descriptor.
311
 * \param readfds   A set of file descriptors to select for
312
 *                  readability.
313
 * \param writefds  A set of file descriptors to select for
314
 *                  writability.
315
 * \param exceptfds A set of file descriptors to select for
316
 *                  exceptional conditions.
317
 * \param tm        The selection timeout.
318
 * \return The number of file descriptors selected, possibly zero, or
319
 *                  -1 on error (and with ERRNO set).
320
 */
321
CPNIO_EXPORT int cpnio_select (int nfds, fd_set *readfds, fd_set *writefds,
322
                               fd_set *exceptfds, struct timeval *tm);
323
 
324
/*
325
 * We include the implementation file here, because our reference
326
 * implementation is trivial, and the functions are declared extern
327
 * inline.
328
 *
329
 * Implementations that need different implementations of these functions
330
 * SHOULD remove this line, and compile javanio.c as a separate unit.
331
 */
332
#include "javanio.c"
333
 
334
#endif /* __JAVANIO_H__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.