2003-11-11 12:49:12 +01:00
|
|
|
// natSelectorImplWin32.cc
|
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 08:56:58 +01:00
|
|
|
|
2004-09-24 08:41:57 +02:00
|
|
|
/* Copyright (C) 2003, 2004 Free Software Foundation
|
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 08:56:58 +01:00
|
|
|
|
|
|
|
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>
|
|
|
|
|
2004-09-24 08:41:57 +02:00
|
|
|
#include <gnu/java/nio/VMSelector.h>
|
2003-12-16 23:54:22 +01:00
|
|
|
#include <java/lang/Thread.h>
|
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 08:56:58 +01:00
|
|
|
|
|
|
|
jint
|
2004-09-24 08:41:57 +02:00
|
|
|
gnu::java::nio::VMSelector::select (jintArray read, jintArray write,
|
|
|
|
jintArray except, jlong timeout)
|
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 08:56:58 +01:00
|
|
|
{
|
2003-12-16 23:54:22 +01:00
|
|
|
// FIXME: The API for implSelect is biased towards POSIX implementations.
|
|
|
|
jint* pReadFD = elements (read);
|
|
|
|
int nNbReadFDs = JvGetArrayLength (read);
|
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 08:56:58 +01:00
|
|
|
|
2003-12-16 23:54:22 +01:00
|
|
|
jint* pWriteFD = elements (write);
|
|
|
|
int nNbWriteFDs = JvGetArrayLength (write);
|
|
|
|
|
|
|
|
int nNbEvents = nNbReadFDs + nNbWriteFDs;
|
|
|
|
|
|
|
|
// Create and initialize our event wrapper array
|
|
|
|
|
|
|
|
// FIXME: We're creating fresh WSAEVENTs for each call.
|
|
|
|
// This is inefficient. It would probably be better to cache these
|
|
|
|
// in the Win32 socket implementation class.
|
|
|
|
WSAEventWrapper aArray[nNbEvents];
|
|
|
|
|
|
|
|
int nCurIndex = 0;
|
|
|
|
for (int i=0; i < nNbReadFDs; ++i)
|
|
|
|
aArray[nCurIndex++].init(pReadFD[i], FD_ACCEPT | FD_READ);
|
|
|
|
|
|
|
|
for (int i=0; i < nNbWriteFDs; ++i)
|
|
|
|
aArray[nCurIndex++].init(pWriteFD[i], FD_WRITE);
|
|
|
|
|
|
|
|
// Build our array of WSAEVENTs to wait on. Also throw in our thread's
|
|
|
|
// interrupt event in order to detect thread interruption.
|
|
|
|
HANDLE arh[nNbEvents + 1];
|
|
|
|
for (int i=0; i < nNbEvents; ++i)
|
|
|
|
arh[i] = aArray[i].getEventHandle();
|
|
|
|
arh[nNbEvents] = _Jv_Win32GetInterruptEvent ();
|
|
|
|
|
|
|
|
// A timeout value of 0 needs to be treated as infinite.
|
|
|
|
if (timeout <= 0)
|
|
|
|
timeout = WSA_INFINITE;
|
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 08:56:58 +01:00
|
|
|
|
2003-12-16 23:54:22 +01:00
|
|
|
// Do the select.
|
|
|
|
DWORD dwRet = WSAWaitForMultipleEvents (nNbEvents+1, arh, 0, timeout, false);
|
|
|
|
|
|
|
|
if (dwRet == WSA_WAIT_FAILED)
|
|
|
|
_Jv_ThrowIOException ();
|
|
|
|
|
|
|
|
// Before we do anything else, clear output file descriptor arrays.
|
|
|
|
memset(pReadFD, 0, sizeof(jint) * nNbReadFDs);
|
|
|
|
memset(pWriteFD, 0, sizeof(jint) * nNbWriteFDs);
|
|
|
|
memset(elements (except), 0, sizeof(jint) * JvGetArrayLength (except));
|
|
|
|
|
|
|
|
if (dwRet == DWORD(WSA_WAIT_EVENT_0 + nNbEvents))
|
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 08:56:58 +01:00
|
|
|
{
|
2003-12-16 23:54:22 +01:00
|
|
|
// We were interrupted. Set the current thread's interrupt
|
|
|
|
// status and get out of here, with nothing selected..
|
|
|
|
::java::lang::Thread::currentThread ()->interrupt ();
|
|
|
|
return 0;
|
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 08:56:58 +01:00
|
|
|
}
|
2003-12-16 23:54:22 +01:00
|
|
|
else if (dwRet < DWORD(WSA_WAIT_EVENT_0 + nNbEvents))
|
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 08:56:58 +01:00
|
|
|
{
|
2003-12-16 23:54:22 +01:00
|
|
|
int nSelectedEventIndex = dwRet - WSA_WAIT_EVENT_0;
|
|
|
|
|
|
|
|
// Record the selected file descriptor.
|
|
|
|
// FIXME: This implementation only allows one file descriptor
|
|
|
|
// to be selected at a time. Remedy this by looping on
|
|
|
|
// WSAWaitForMultipleEvents 'til nothing more is selected.
|
|
|
|
jint fd = aArray[nSelectedEventIndex].getFD();
|
|
|
|
if (nSelectedEventIndex < nNbReadFDs)
|
|
|
|
pReadFD[0] = fd;
|
|
|
|
else
|
|
|
|
pWriteFD[0] = fd;
|
|
|
|
|
|
|
|
return 1;
|
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 08:56:58 +01:00
|
|
|
}
|
2003-12-16 23:54:22 +01:00
|
|
|
else
|
|
|
|
// None of the event objects was signalled, so nothing was
|
|
|
|
// selected.
|
|
|
|
return 0;
|
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 08:56:58 +01:00
|
|
|
}
|