/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* An implementation of SctpMultiChannel
*/
implements SelChImpl
{
private final int fdVal;
/* IDs of native threads doing send and receives, for signalling */
/* Lock held by current receiving thread */
/* Lock held by current sending thread */
/* Lock held by any thread that modifies the state fields declared below
* DO NOT invoke a blocking I/O operation while holding this lock! */
private enum ChannelState {
}
/* -- The following fields are protected by stateLock -- */
/* Binding: Once bound the port will remain constant. */
/* Has the channel been bound to the wildcard address */
/* Keeps a map of addresses to association, and visa versa */
/* -- End of fields protected by stateLock -- */
/* If an association has been shutdown mark it for removal after
* the user handler has been invoked */
new ThreadLocal<Association>() {
return null;
}
};
/* A notification handler cannot invoke receive */
new ThreadLocal<Boolean>() {
}
};
throws IOException {
//TODO: update provider, remove public modifier
super(provider);
}
throws IOException {
synchronized (receiveLock) {
synchronized (sendLock) {
synchronized (stateLock) {
ensureOpen();
if (isBound())
wildcard = true;
}
}
}
return this;
}
throws IOException {
return bindUnbindAddress(address, true);
}
throws IOException {
return bindUnbindAddress(address, false);
}
boolean add)
throws IOException {
throw new IllegalArgumentException();
synchronized (receiveLock) {
synchronized (sendLock) {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isBound())
throw new NotYetBoundException();
if (wildcard)
throw new IllegalStateException(
"Cannot add or remove addresses from a channel that is bound to the wildcard address");
if (address.isAnyLocalAddress())
throw new IllegalArgumentException(
"Cannot add or remove the wildcard address");
if (add) {
}
}
} else { /*removing */
/* Verify that there is more than one address
* and that address is already bound */
throw new IllegalUnbindException("Cannot remove address from a channel with only one address bound");
boolean foundAddress = false;
foundAddress = true;
break;
}
}
if (!foundAddress )
throw new IllegalUnbindException("Cannot remove address from a channel that is not bound to that address");
}
if (add)
else {
break;
}
}
}
}
}
}
return this;
}
throws ClosedChannelException, NotYetBoundException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isBound())
throw new NotYetBoundException();
}
}
private boolean isBound() {
synchronized (stateLock) {
return port == -1 ? false : true;
}
}
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
}
}
synchronized (stateLock) {
receiverThread = 0;
kill();
}
}
synchronized (stateLock) {
senderThread = 0;
kill();
}
}
}
synchronized (stateLock) {
if (receiverThread != 0)
if (senderThread != 0)
if (!isRegistered())
kill();
}
}
return fd;
}
public int getFDVal() {
return fdVal;
}
/**
* Translates native poll revent ops into a ready operation ops
*/
int newOps = initialOps;
/* This should only happen if this channel is pre-closed while a
* selection operation is in progress
* ## Throw an error if this channel has not been pre-closed */
return false;
}
}
}
}
}
int newOps = 0;
}
synchronized (stateLock) {
return;
return;
}
assert !isOpen() && !isRegistered();
/* Postpone the kill if there is a thread sending or receiving. */
} else {
}
}
}
T value,
throws IOException {
throw new NullPointerException();
synchronized (stateLock) {
}
if (!isOpen())
throw new ClosedChannelException();
}
return this;
}
@SuppressWarnings("unchecked")
throws IOException {
throw new NullPointerException();
synchronized (stateLock) {
}
if (!isOpen())
throw new ClosedChannelException();
}
}
private static class DefaultOptionsHolder {
}
}
return DefaultOptionsHolder.defaultOptions;
}
T attachment,
throws IOException {
throw new IllegalArgumentException("buffer cannot be null");
if (buffer.isReadOnly())
throw new IllegalArgumentException("Read-only buffer");
if (receiveInvoked.get())
throw new IllegalReceiveException(
"cannot invoke receive from handler");
try {
do {
synchronized (receiveLock) {
ensureOpen();
if (!isBound())
throw new NotYetBoundException();
int n = 0;
try {
begin();
synchronized (stateLock) {
if(!isOpen())
return null;
}
do {
} finally {
}
if (!resultContainer.isNotification()) {
/* message or nothing */
if (resultContainer.hasSomething()) {
/* Set the association before returning */
associationID()));
/* must be a new association */
try {
} catch (SecurityException se) {
throw se;
}
}
}
return info;
} else {
/* Non-blocking may return null if nothing available*/
return null;
}
} else { /* notification */
synchronized (stateLock) {
}
}
} /* receiveLock */
== HandlerResult.CONTINUE));
} finally {
}
return null;
}
throws IOException {
/* Substitute a native buffer. */
try {
return n;
} finally {
}
}
int rem,
int pos)
throws IOException {
if (n > 0)
return n;
}
new InternalNotificationHandler();
{
}
private class InternalNotificationHandler<T>
extends AbstractNotificationHandler<T>
{
/* Update map to reflect change in association */
case COMM_UP :
break;
case SHUTDOWN :
case COMM_LOST :
//case RESTART: ???
/* mark association for removal after user handler invoked*/
}
return HandlerResult.CONTINUE;
}
}
T attachment) {
if (!(handler instanceof AbstractNotificationHandler)) {
} else { /* AbstractNotificationHandler */
switch(resultContainer.type()) {
case ASSOCIATION_CHANGED :
break;
case PEER_ADDRESS_CHANGED :
break;
case SEND_FAILED :
break;
case SHUTDOWN :
break;
default :
/* implementation specific handlers */
}
}
if (!(handler instanceof InternalNotificationHandler)) {
/* Only remove associations after user handler
* has finished with them */
}
}
return result;
}
/* Lookup the association in our internal map */
synchronized (stateLock) {
for (Association a : assocs) {
if (a.associationID() == assocId) {
return a;
}
}
}
return null;
}
synchronized (stateLock) {
try {
} catch (IOException unused) {
/* OK, determining connected addresses may not be possible
* shutdown, connection lost, etc */
}
}
}
}
synchronized (stateLock) {
try {
} catch (IOException unused) {
/* OK, determining connected addresses may not be possible
* shutdown, connection lost, etc */
}
for (Association a : assocs) {
if (a.associationID() == assocId) {
associationMap.remove(a);
break;
}
}
} else {
/* We cannot determine the connected addresses */
}
}
}
}
}
/**
* @throws IllegalArgumentException
* If the given association is not controlled by this channel
*
* @return {@code true} if, and only if, the given association is one
* of the current associations controlled by this channel
*/
synchronized (stateLock) {
return true;
}
}
}
throw new IllegalArgumentException(
"Given Association is not controlled by this channel");
}
synchronized (stateLock) {
throw new InvalidStreamException();
}
}
/* TODO: Add support for ttl and isComplete to both 121 12M
* SCTP_EOR not yet supported on reference platforms
* TTL support limited...
*/
throws IOException {
throw new IllegalArgumentException("buffer cannot be null");
if (messageInfo == null)
throw new IllegalArgumentException("messageInfo cannot be null");
synchronized (sendLock) {
ensureOpen();
if (!isBound())
int n = 0;
try {
int assocId = -1;
begin();
synchronized (stateLock) {
if(!isOpen())
return 0;
/* Determine what address or association to send to */
/* have we also got a preferred address */
throw new IllegalArgumentException("given preferred address is not part of this association");
}
if (association != null) {
} else { /* must be new association */
}
} else {
throw new AssertionError(
"Both association and address cannot be null");
}
}
do {
} finally {
}
}
}
int assocId,
throws IOException {
if (src instanceof DirectBuffer)
/* Substitute a native buffer */
try {
/* Do not update src until we see how many bytes were written */
if (n > 0) {
/* now update src */
}
return n;
} finally {
}
}
int assocId,
int streamNumber,
boolean unordered,
int ppid)
throws IOException {
int port = 0;
}
if (written > 0)
return written;
}
throws IOException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
}
return this;
}
throws IOException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isBound())
return Collections.EMPTY_SET;
}
}
throws IOException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
try {
} catch (SocketException se) {
/* a valid association should always have remote addresses */
}
}
}
throws IOException {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
/* successfully branched, we can now remove it from assoc list */
}
}
/* Use common native implementation shared between
* one-to-one and one-to-many */
long address,
int length)
throws IOException{
length, false /*peek */);
}
long address,
int length,
int port,
int assocId,
int streamNumber,
boolean unordered,
int ppid)
throws IOException {
}
static {
}
}