| 1 |
774 |
jeremybenn |
/* javanio.c -- implementations of functions in javanio.h.
|
| 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 |
|
|
/*
|
| 40 |
|
|
* Note, because these functions are trivial, and should be inlined,
|
| 41 |
|
|
* we include this file in the header, and do not compile it.
|
| 42 |
|
|
*/
|
| 43 |
|
|
|
| 44 |
|
|
#include <fcntl.h>
|
| 45 |
|
|
#include <unistd.h>
|
| 46 |
|
|
#include <sys/types.h>
|
| 47 |
|
|
#include <sys/socket.h>
|
| 48 |
|
|
#ifdef HAVE_SYS_SELECT_H
|
| 49 |
|
|
#include <sys/select.h>
|
| 50 |
|
|
#endif
|
| 51 |
|
|
#include <sys/uio.h>
|
| 52 |
|
|
|
| 53 |
|
|
CPNIO_EXPORT ssize_t
|
| 54 |
|
|
cpnio_read (int fd, void *buf, size_t nbytes)
|
| 55 |
|
|
{
|
| 56 |
|
|
return read (fd, buf, nbytes);
|
| 57 |
|
|
}
|
| 58 |
|
|
|
| 59 |
|
|
CPNIO_EXPORT ssize_t
|
| 60 |
|
|
cpnio_readv (int fd, const struct iovec *iov, int iovcnt)
|
| 61 |
|
|
{
|
| 62 |
|
|
return readv (fd, iov, iovcnt);
|
| 63 |
|
|
}
|
| 64 |
|
|
|
| 65 |
|
|
CPNIO_EXPORT ssize_t
|
| 66 |
|
|
cpnio_write (int fd, const void *buf, size_t nbytes)
|
| 67 |
|
|
{
|
| 68 |
|
|
return write (fd, buf, nbytes);
|
| 69 |
|
|
}
|
| 70 |
|
|
|
| 71 |
|
|
CPNIO_EXPORT ssize_t
|
| 72 |
|
|
cpnio_writev (int fd, const struct iovec *iov, size_t iovcnt)
|
| 73 |
|
|
{
|
| 74 |
|
|
return writev (fd, iov, iovcnt);
|
| 75 |
|
|
}
|
| 76 |
|
|
|
| 77 |
|
|
CPNIO_EXPORT int
|
| 78 |
|
|
cpnio_socket (int domain, int type, int protocol)
|
| 79 |
|
|
{
|
| 80 |
|
|
return socket (domain, type, protocol);
|
| 81 |
|
|
}
|
| 82 |
|
|
|
| 83 |
|
|
CPNIO_EXPORT int
|
| 84 |
|
|
cpnio_connect (int fd, const struct sockaddr *addr, socklen_t addrlen)
|
| 85 |
|
|
{
|
| 86 |
|
|
return connect (fd, addr, addrlen);
|
| 87 |
|
|
}
|
| 88 |
|
|
|
| 89 |
|
|
CPNIO_EXPORT int
|
| 90 |
|
|
cpnio_accept (int fd, struct sockaddr *addr, socklen_t *addrlen)
|
| 91 |
|
|
{
|
| 92 |
|
|
fd_set rset;
|
| 93 |
|
|
struct timeval tv;
|
| 94 |
|
|
socklen_t tvlen = sizeof(tv);
|
| 95 |
|
|
int ret;
|
| 96 |
|
|
|
| 97 |
|
|
tv.tv_sec = 0;
|
| 98 |
|
|
tv.tv_usec = 0;
|
| 99 |
|
|
getsockopt (fd, SOL_SOCKET, SO_RCVTIMEO, &tv, &tvlen);
|
| 100 |
|
|
if (tv.tv_sec > 0 || tv.tv_usec > 0)
|
| 101 |
|
|
{
|
| 102 |
|
|
FD_ZERO(&rset);
|
| 103 |
|
|
FD_SET(fd,&rset);
|
| 104 |
|
|
ret = select (fd+1,&rset,NULL,NULL,&tv);
|
| 105 |
|
|
if (ret == 0)
|
| 106 |
|
|
{
|
| 107 |
|
|
errno = EAGAIN;
|
| 108 |
|
|
return -1;
|
| 109 |
|
|
}
|
| 110 |
|
|
}
|
| 111 |
|
|
return accept (fd, addr, addrlen);
|
| 112 |
|
|
}
|
| 113 |
|
|
|
| 114 |
|
|
CPNIO_EXPORT ssize_t
|
| 115 |
|
|
cpnio_sendto (int fd, const void *msg, size_t len, int flags,
|
| 116 |
|
|
const struct sockaddr *to, socklen_t tolen)
|
| 117 |
|
|
{
|
| 118 |
|
|
return sendto (fd, msg, len, flags, to, tolen);
|
| 119 |
|
|
}
|
| 120 |
|
|
|
| 121 |
|
|
CPNIO_EXPORT ssize_t
|
| 122 |
|
|
cpnio_recvfrom (int fd, void *buf, size_t len, int flags,
|
| 123 |
|
|
struct sockaddr *from, socklen_t *fromlen)
|
| 124 |
|
|
{
|
| 125 |
|
|
return recvfrom (fd, buf, len, flags, from, fromlen);
|
| 126 |
|
|
}
|
| 127 |
|
|
|
| 128 |
|
|
CPNIO_EXPORT int
|
| 129 |
|
|
cpnio_fcntl (int fd, int cmd, long arg)
|
| 130 |
|
|
{
|
| 131 |
|
|
#ifdef HAVE_FCNTL
|
| 132 |
|
|
return fcntl (fd, cmd, arg);
|
| 133 |
|
|
#else
|
| 134 |
|
|
errno = ENOSUP;
|
| 135 |
|
|
return -1;
|
| 136 |
|
|
#endif /* HAVE_FCNTL */
|
| 137 |
|
|
}
|
| 138 |
|
|
|
| 139 |
|
|
CPNIO_EXPORT int
|
| 140 |
|
|
cpnio_select (int nfds, fd_set *readfds, fd_set *writefds,
|
| 141 |
|
|
fd_set *excepfds, struct timeval *timeo)
|
| 142 |
|
|
{
|
| 143 |
|
|
return select (nfds, readfds, writefds, excepfds, timeo);
|
| 144 |
|
|
}
|