/*
* 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 an SctpChannel
*/
implements SelChImpl
{
private final int fdVal;
/* IDs of native threads doing send and receivess, for signalling */
/* Lock held by current receiving or connecting thread */
/* Lock held by current sending or connecting thread */
new ThreadLocal<Boolean>() {
}
};
/* 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 */
//private InetSocketAddress remoteAddress = null;
private boolean readyToConnect;
/* Shutdown */
private boolean isShutdown;
/* -- End of fields protected by stateLock -- */
/**
* Constructor for normal connecting sockets
*/
//TODO: update provider remove public modifier
super(provider);
}
/**
* Constructor for sockets obtained from server sockets
*/
throws IOException {
}
/**
* Constructor for sockets obtained from branching
*/
throws IOException {
super(provider);
this.association = association;
} else { /* obtained from server channel */
/* Receive COMM_UP */
try {
} finally {
}
}
}
/**
* Binds the channel's socket to a local address.
*/
synchronized (receiveLock) {
synchronized (sendLock) {
synchronized (stateLock) {
if (isBound())
wildcard = true;
}
}
}
return this;
}
throws IOException {
bindUnbindAddress(address, true);
return this;
}
throws IOException {
bindUnbindAddress(address, false);
return this;
}
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;
}
private boolean isBound() {
synchronized (stateLock) {
return port == -1 ? false : true;
}
}
private boolean isConnected() {
synchronized (stateLock) {
}
}
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (isConnected())
throw new AlreadyConnectedException();
throw new ConnectionPendingException();
}
}
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isConnected())
throw new NotYetConnectedException();
else
return true;
}
}
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (isShutdown)
throw new ClosedChannelException();
if (!isConnected())
throw new NotYetConnectedException();
}
}
synchronized (stateLock) {
receiverThread = 0;
kill();
}
}
synchronized (stateLock) {
senderThread = 0;
kill();
}
}
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (!isConnected())
return null;
return association;
}
}
synchronized (receiveLock) {
synchronized (sendLock) {
synchronized (blockingLock()) {
int n = 0;
try {
try {
begin();
synchronized (stateLock) {
if (!isOpen()) {
return false;
}
}
for (;;) {
if (ia.isAnyLocalAddress())
if ( (n == IOStatus.INTERRUPTED)
&& isOpen())
continue;
break;
}
} finally {
}
} catch (IOException x) {
/* If an exception was thrown, close the channel after
* invoking end() so as to avoid bogus
* AsynchronousCloseExceptions */
close();
throw x;
}
if (n > 0) {
synchronized (stateLock) {
/* Connection succeeded */
if (!isBound()) {
}
/* Receive COMM_UP */
try {
} finally {
}
/* cache remote addresses */
try {
return true;
}
} else {
synchronized (stateLock) {
/* If nonblocking and no exception then connection
* pending; disallow another invocation */
if (!isBlocking())
else
assert false;
}
}
}
return false;
}
}
}
int maxOutStreams,
int maxInStreams)
throws IOException {
}
public boolean isConnectionPending() {
synchronized (stateLock) {
}
}
synchronized (receiveLock) {
synchronized (sendLock) {
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
if (isConnected())
return true;
throw new NoConnectionPendingException();
}
int n = 0;
try {
try {
begin();
synchronized (blockingLock()) {
synchronized (stateLock) {
if (!isOpen()) {
return false;
}
}
if (!isBlocking()) {
for (;;) {
if ( (n == IOStatus.INTERRUPTED)
&& isOpen())
continue;
break;
}
} else {
for (;;) {
if (n == 0) {
// Loop in case of
// spurious notifications
continue;
}
if ( (n == IOStatus.INTERRUPTED)
&& isOpen())
continue;
break;
}
}
}
} finally {
synchronized (stateLock) {
receiverThread = 0;
kill();
/* poll()/getsockopt() does not report
* error (throws exception, with n = 0)
* on Linux platform after dup2 and
* signal-wakeup. Force n to 0 so the
* end() can throw appropriate exception */
n = 0;
}
}
}
} catch (IOException x) {
/* If an exception was thrown, close the channel after
* invoking end() so as to avoid bogus
* AsynchronousCloseExceptions */
close();
throw x;
}
if (n > 0) {
synchronized (stateLock) {
if (!isBound()) {
}
/* Receive COMM_UP */
try {
} finally {
}
/* cache remote addresses */
try {
return true;
}
}
}
}
return false;
}
}
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;
}
/* No need to poll again in checkConnect,
* the error will be detected there */
readyToConnect = true;
}
isConnected())
readyToConnect = true;
}
isConnected())
}
}
@SuppressWarnings("all")
}
int newOps = 0;
}
synchronized (stateLock) {
return;
return;
}
assert !isOpen() && !isRegistered();
/* Postpone the kill if there is a waiting reader
* or writer thread. */
} else {
}
}
}
throws IOException {
throw new NullPointerException();
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
}
return this;
}
@SuppressWarnings("unchecked")
throw new NullPointerException();
synchronized (stateLock) {
if (!isOpen())
throw new ClosedChannelException();
}
}
private static class DefaultOptionsHolder {
}
}
return DefaultOptionsHolder.defaultOptions;
}
T attachment,
throws IOException {
}
T attachment,
boolean fromConnect)
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) {
if (!ensureReceiveOpen())
return null;
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 */
synchronized (stateLock) {
assert association != null;
}
return info;
} else
/* Non-blocking may return null if nothing available*/
return null;
} else { /* notification */
synchronized (stateLock) {
}
}
if (fromConnect) {
/* If we reach here, then it was connect that invoked
* receive and received the COMM_UP. We have already
* handled the COMM_UP with the internal notification
* handler. Simply return. */
return null;
}
} /* receiveLock */
== HandlerResult.CONTINUE));
return null;
} finally {
}
}
boolean peek)
throws IOException {
/* Substitute a native buffer */
try {
return n;
} finally {
}
}
int rem,
int pos,
boolean peek)
throws IOException
{
if (n > 0)
return n;
}
new InternalNotificationHandler();
{
}
private class InternalNotificationHandler<T>
extends AbstractNotificationHandler<T>
{
association == null) {
}
return HandlerResult.CONTINUE;
}
}
T attachment) {
synchronized (stateLock) {
}
if (!(handler instanceof AbstractNotificationHandler)) {
}
/* AbstractNotificationHandler */
switch(resultContainer.type()) {
case ASSOCIATION_CHANGED :
return absHandler.handleNotification(
case PEER_ADDRESS_CHANGED :
return absHandler.handleNotification(
case SEND_FAILED :
return absHandler.handleNotification(
case SHUTDOWN :
return absHandler.handleNotification(
default :
/* implementation specific handlers */
return absHandler.handleNotification(
}
}
synchronized (stateLock) {
throw new IllegalArgumentException(
"Cannot send to another association");
}
}
}
synchronized (stateLock) {
if (association != null) {
if (streamNumber < 0 ||
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) {
int n = 0;
try {
begin();
synchronized (stateLock) {
if(!isOpen())
return 0;
}
do {
} finally {
}
}
}
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 streamNumber,
boolean unordered,
int ppid)
throws IOException {
int port = 0;
}
if (written > 0)
return written;
}
synchronized(stateLock) {
if (isShutdown)
return this;
if (senderThread != 0)
isShutdown = true;
}
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();
if (!isConnected() || isShutdown)
return Collections.EMPTY_SET;
try {
} catch (SocketException unused) {
/* an open connected channel should always have remote addresses */
return remoteAddresses;
}
}
}
/* Native */
private static native void initIDs();
boolean ready) throws IOException;
static {
initIDs();
}
}