gcc/libjava/gnu/java/nio/natServerSocketChannelImpl.cc
Michael Koch 38a21d46b0 natByteBufferImpl.cc, [...]: New files that implement native functionalities.
2002-11-29  Michael Koch <konqueror@gmx.de>

	* gnu/java/nio/natByteBufferImpl.cc,
	gnu/java/nio/natCharBufferImpl.cc,
	gnu/java/nio/natDoubleBufferImpl.cc,
	gnu/java/nio/natFloatBufferImpl.cc,
	gnu/java/nio/natIntBufferImpl.cc,
	gnu/java/nio/natLongBufferImpl.cc,
	gnu/java/nio/natSelectorImpl.cc,
	gnu/java/nio/natServerSocketChannelImpl.cc,
	gnu/java/nio/natShortBufferImpl.cc,
	gnu/java/nio/natSocketChannelImpl.cc:
	New files that implement native functionalities.

From-SVN: r59625
2002-11-29 07:56:58 +00:00

78 lines
1.9 KiB
C++

// natSelectorImpl.cc
/* Copyright (C) 2002 Free Software Foundation
This file is part of libgcj.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
#include <config.h>
#include <platform.h>
#include <errno.h>
#include <netinet/in.h>
#include <gcj/cni.h>
#include <gnu/java/nio/ServerSocketChannelImpl.h>
#include <gnu/java/nio/SocketChannelImpl.h>
#include <java/io/IOException.h>
#include <java/net/InetSocketAddress.h>
#include <java/net/SocketException.h>
union SockAddr
{
struct sockaddr_in address;
#ifdef HAVE_INET6
struct sockaddr_in6 address6;
#endif
};
jint
gnu::java::nio::ServerSocketChannelImpl::SocketAccept (
ServerSocketChannelImpl* socket,
SocketChannelImpl* s)
{
union SockAddr u;
struct sockaddr *ptr = (struct sockaddr *) &u.address;
socklen_t addrlen = sizeof(struct sockaddr);
/*
jbyteArray haddress = socket->sa->getAddress ()->addr;
jbyte *bytes = elements (haddress);
int len = haddress->length;
if (len == 4)
{
u.address.sin_family = AF_INET;
memcpy (&u.address.sin_addr, bytes, len);
len = sizeof (struct sockaddr_in);
u.address.sin_port = htons ( socket->sa->getPort ());
}
#ifdef HAVE_INET6
else if (len == 16)
{
u.address6.sin6_family = AF_INET6;
memcpy (&u.address6.sin6_addr, bytes, len);
len = sizeof (struct sockaddr_in6);
u.address6.sin6_port = htons (socket->sa->getPort ());
}
#endif
else
throw new ::java::net::SocketException (JvNewStringUTF ("invalid length"));
*/
int sock = _Jv_accept (socket->fd, ptr, &addrlen);
// FIXME: write address/port in ptr into java variables
if (sock < 0)
{
char* strerr = strerror (errno);
throw new ::java::io::IOException (JvNewStringUTF (strerr));
}
s->fd = sock;
return sock;
}