feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
141
jdkSrc/jdk8/com/sun/nio/sctp/AbstractNotificationHandler.java
Normal file
141
jdkSrc/jdk8/com/sun/nio/sctp/AbstractNotificationHandler.java
Normal file
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* A skeletal handler that consumes notifications and continues.
|
||||
*
|
||||
* <P> This class trivially implements the {@code handleNotification} methods to
|
||||
* return {@link HandlerResult#CONTINUE CONTINUE} so that all notifications are
|
||||
* consumed and the channel continues to try and receive a message.
|
||||
*
|
||||
* <P> It also provides overloaded versions of the {@code handleNotification}
|
||||
* methods, one for each of the required supported notification types, {@link
|
||||
* AssociationChangeNotification}, {@link PeerAddressChangeNotification},
|
||||
* {@link SendFailedNotification}, and {@link ShutdownNotification}. The
|
||||
* appropriate method will be invoked when the notification is received.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class AbstractNotificationHandler<T>
|
||||
implements NotificationHandler<T>
|
||||
{
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected AbstractNotificationHandler() {}
|
||||
|
||||
/**
|
||||
* Invoked when an implementation specific notification is received from the
|
||||
* SCTP stack.
|
||||
*
|
||||
* @param notification
|
||||
* The notification
|
||||
*
|
||||
* @param attachment
|
||||
* The object attached to the {@code receive} operation when it was
|
||||
* initiated.
|
||||
*
|
||||
* @return The handler result
|
||||
*/
|
||||
@Override
|
||||
public HandlerResult handleNotification(Notification notification,
|
||||
T attachment) {
|
||||
return HandlerResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when an {@link AssociationChangeNotification} is received from
|
||||
* the SCTP stack.
|
||||
*
|
||||
* @param notification
|
||||
* The notification
|
||||
*
|
||||
* @param attachment
|
||||
* The object attached to the {@code receive} operation when it was
|
||||
* initiated.
|
||||
*
|
||||
* @return The handler result
|
||||
*/
|
||||
public HandlerResult handleNotification(AssociationChangeNotification notification,
|
||||
T attachment) {
|
||||
return HandlerResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when an {@link PeerAddressChangeNotification} is received from
|
||||
* the SCTP stack.
|
||||
*
|
||||
* @param notification
|
||||
* The notification
|
||||
*
|
||||
* @param attachment
|
||||
* The object attached to the {@code receive} operation when it was
|
||||
* initiated.
|
||||
*
|
||||
* @return The handler result
|
||||
*/
|
||||
public HandlerResult handleNotification(PeerAddressChangeNotification notification,
|
||||
T attachment) {
|
||||
return HandlerResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when an {@link SendFailedNotification} is received from
|
||||
* the SCTP stack.
|
||||
*
|
||||
* @param notification
|
||||
* The notification
|
||||
*
|
||||
* @param attachment
|
||||
* The object attached to the {@code receive} operation when it was
|
||||
* initiated.
|
||||
*
|
||||
* @return The handler result
|
||||
*/
|
||||
public HandlerResult handleNotification(SendFailedNotification notification,
|
||||
T attachment) {
|
||||
return HandlerResult.CONTINUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked when an {@link ShutdownNotification} is received from
|
||||
* the SCTP stack.
|
||||
*
|
||||
* @param notification
|
||||
* The notification
|
||||
*
|
||||
* @param attachment
|
||||
* The object attached to the {@code receive} operation when it was
|
||||
* initiated.
|
||||
*
|
||||
* @return The handler result
|
||||
*/
|
||||
public HandlerResult handleNotification(ShutdownNotification notification,
|
||||
T attachment) {
|
||||
return HandlerResult.CONTINUE;
|
||||
}
|
||||
}
|
||||
112
jdkSrc/jdk8/com/sun/nio/sctp/Association.java
Normal file
112
jdkSrc/jdk8/com/sun/nio/sctp/Association.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* A class that represents an SCTP association.
|
||||
*
|
||||
* <P> An association exists between two SCTP endpoints. Each endpoint is
|
||||
* represented by a list of transport addresses through which that endpoint can
|
||||
* be reached and from which it will originate SCTP messages. The association
|
||||
* spans over all of the possible source/destination combinations which may be
|
||||
* generated from each endpoint's lists of addresses.
|
||||
*
|
||||
* <P> Associations are identified by their Association ID.
|
||||
* Association ID's are guaranteed to be unique for the lifetime of the
|
||||
* association. An association ID may be reused after the association has been
|
||||
* shutdown. An association ID is not unique across multiple SCTP channels.
|
||||
* An Association's local and remote addresses may change if the SCTP
|
||||
* implementation supports <I>Dynamic Address Reconfiguration</I> as defined by
|
||||
* <A HREF="http://tools.ietf.org/html/rfc5061">RFC5061</A>, see the
|
||||
* {@code bindAddress} and {@code unbindAddress} methods of {@link SctpChannel},
|
||||
* {@link SctpServerChannel}, and {@link SctpMultiChannel}.
|
||||
*
|
||||
* <P> An {@code Association} is returned from an {@link
|
||||
* SctpChannel#association SctpChannel} or an {@link
|
||||
* SctpMultiChannel#associations SctpMultiChannel}, as well
|
||||
* as being given as a parameter to {@link NotificationHandler
|
||||
* NotificationHandler} methods.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class Association {
|
||||
private final int associationID;
|
||||
private final int maxInStreams;
|
||||
private final int maxOutStreams;
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*
|
||||
* @param associationID
|
||||
* The association ID
|
||||
* @param maxInStreams
|
||||
* The maximum number of inbound streams
|
||||
* @param maxOutStreams
|
||||
* The maximum number of outbound streams
|
||||
*/
|
||||
protected Association(int associationID,
|
||||
int maxInStreams,
|
||||
int maxOutStreams) {
|
||||
this.associationID = associationID;
|
||||
this.maxInStreams = maxInStreams;
|
||||
this.maxOutStreams = maxOutStreams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the associationID.
|
||||
*
|
||||
* @return The association ID
|
||||
*/
|
||||
public final int associationID() {
|
||||
return associationID;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the maximum number of inbound streams that this association
|
||||
* supports.
|
||||
*
|
||||
* <P> Data received on this association will be on stream number
|
||||
* {@code s}, where {@code 0 <= s < maxInboundStreams()}.
|
||||
*
|
||||
* @return The maximum number of inbound streams
|
||||
*/
|
||||
public final int maxInboundStreams() {
|
||||
return maxInStreams;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the maximum number of outbound streams that this association
|
||||
* supports.
|
||||
*
|
||||
* <P> Data sent on this association must be on stream number
|
||||
* {@code s}, where {@code 0 <= s < maxOutboundStreams()}.
|
||||
*
|
||||
* @return The maximum number of outbound streams
|
||||
*/
|
||||
public final int maxOutboundStreams() {
|
||||
return maxOutStreams;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* Notification emitted when an association has either opened or closed.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class AssociationChangeNotification
|
||||
implements Notification
|
||||
{
|
||||
/**
|
||||
* Defines the type of change event that happened to the association.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public enum AssocChangeEvent
|
||||
{
|
||||
/**
|
||||
* A new association is now ready and data may be exchanged with this peer.
|
||||
*/
|
||||
COMM_UP,
|
||||
|
||||
/**
|
||||
* The association has failed. A series of SCTP send failed notifications
|
||||
* will follow this notification, one for each outstanding message.
|
||||
*/
|
||||
COMM_LOST,
|
||||
|
||||
/**
|
||||
* SCTP has detected that the peer has restarted.
|
||||
*/
|
||||
RESTART,
|
||||
|
||||
/**
|
||||
* The association has gracefully closed.
|
||||
*/
|
||||
SHUTDOWN,
|
||||
|
||||
/**
|
||||
* The association failed to setup. If a message was sent on a {@link
|
||||
* SctpMultiChannel} in non-blocking mode, an
|
||||
* SCTP send failed notification will follow this notification for the
|
||||
* outstanding message.
|
||||
*/
|
||||
CANT_START
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected AssociationChangeNotification() {}
|
||||
|
||||
/**
|
||||
* Returns the association that this notification is applicable to.
|
||||
*
|
||||
* @return The association whose state has changed, or {@code null} if
|
||||
* there is no association, that is {@linkplain
|
||||
* AssocChangeEvent#CANT_START CANT_START}
|
||||
*/
|
||||
public abstract Association association();
|
||||
|
||||
/**
|
||||
* Returns the type of change event.
|
||||
*
|
||||
* @return The event
|
||||
*/
|
||||
public abstract AssocChangeEvent event();
|
||||
}
|
||||
48
jdkSrc/jdk8/com/sun/nio/sctp/HandlerResult.java
Normal file
48
jdkSrc/jdk8/com/sun/nio/sctp/HandlerResult.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* Defines notification handler results.
|
||||
*
|
||||
* <P> The {@code HandlerResult} is used to determine the behavior of the
|
||||
* channel after it handles a notification from the SCTP stack. Essentially its
|
||||
* value determines if the channel should try to receive another notificaiton or
|
||||
* a message before returning.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public enum HandlerResult {
|
||||
/**
|
||||
* Try to receieve another message or notification.
|
||||
*/
|
||||
CONTINUE,
|
||||
|
||||
/**
|
||||
* Return without trying to receive any more data.
|
||||
*/
|
||||
RETURN;
|
||||
}
|
||||
53
jdkSrc/jdk8/com/sun/nio/sctp/IllegalReceiveException.java
Normal file
53
jdkSrc/jdk8/com/sun/nio/sctp/IllegalReceiveException.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to invoke the
|
||||
* {@code receive} method of {@link SctpChannel} or {@link SctpMultiChannel}
|
||||
* from a notification handler.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class IllegalReceiveException extends IllegalStateException {
|
||||
private static final long serialVersionUID = 2296619040988576224L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public IllegalReceiveException() { }
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class with the specified message.
|
||||
*
|
||||
* @param msg
|
||||
* The String that contains a detailed message
|
||||
*/
|
||||
public IllegalReceiveException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
53
jdkSrc/jdk8/com/sun/nio/sctp/IllegalUnbindException.java
Normal file
53
jdkSrc/jdk8/com/sun/nio/sctp/IllegalUnbindException.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to remove an
|
||||
* address that is not bound to the channel, or remove an address from a
|
||||
* channel that has only one address bound to it.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class IllegalUnbindException extends IllegalStateException {
|
||||
private static final long serialVersionUID = -310540883995532224L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public IllegalUnbindException() { }
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class with the specified detailed message.
|
||||
*
|
||||
* @param msg
|
||||
* The String that contains a detailed message
|
||||
*/
|
||||
public IllegalUnbindException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
52
jdkSrc/jdk8/com/sun/nio/sctp/InvalidStreamException.java
Normal file
52
jdkSrc/jdk8/com/sun/nio/sctp/InvalidStreamException.java
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* Unchecked exception thrown when an attempt is made to send a
|
||||
* message to an invalid stream.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class InvalidStreamException extends IllegalArgumentException {
|
||||
private static final long serialVersionUID = -9172703378046665558L;
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class.
|
||||
*/
|
||||
public InvalidStreamException() { }
|
||||
|
||||
/**
|
||||
* Constructs an instance of this class with the specified detailed message.
|
||||
*
|
||||
* @param msg
|
||||
* The String that contains a detailed message
|
||||
*/
|
||||
public InvalidStreamException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
304
jdkSrc/jdk8/com/sun/nio/sctp/MessageInfo.java
Normal file
304
jdkSrc/jdk8/com/sun/nio/sctp/MessageInfo.java
Normal file
@@ -0,0 +1,304 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* The {@code MessageInfo} class provides additional ancillary information about
|
||||
* messages.
|
||||
*
|
||||
* <P> Received SCTP messages, returned by
|
||||
* {@link SctpChannel#receive SctpChannel.receive} and {@link
|
||||
* SctpMultiChannel#receive SctpMultiChannel.receive},
|
||||
* return a {@code MessageInfo} instance that can be queried to determine
|
||||
* ancillary information about the received message. Messages being sent should
|
||||
* use one of the {@link #createOutgoing(java.net.SocketAddress,int)
|
||||
* createOutgoing} methods to provide ancillary data for the message being
|
||||
* sent, and may use the appropriate setter methods to override the default
|
||||
* values provided for {@link #isUnordered() unordered}, {@link #timeToLive()
|
||||
* timeToLive}, {@link #isComplete() complete} and {@link #payloadProtocolID()
|
||||
* payloadProtocolID}, before sending the message.
|
||||
*
|
||||
* <P> For out going messages the {@code timeToLive} parameter is a time period
|
||||
* that the sending side SCTP stack may expire the message if it has not been
|
||||
* sent. This time period is an indication to the stack that the message is no
|
||||
* longer required to be sent after the time period expires. It is not a hard
|
||||
* timeout and may be influenced by whether the association supports the partial
|
||||
* reliability extension, <a href=http://www.ietf.org/rfc/rfc3758.txt>RFC 3758
|
||||
* </a>.
|
||||
*
|
||||
* <P> {@code MessageInfo} instances are not safe for use by multiple concurrent
|
||||
* threads. If a MessageInfo is to be used by more than one thread then access
|
||||
* to the MessageInfo should be controlled by appropriate synchronization.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class MessageInfo {
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected MessageInfo() {}
|
||||
|
||||
/**
|
||||
* Creates a {@code MessageInfo} instance suitable for use when
|
||||
* sending a message.
|
||||
*
|
||||
* <P> The returned instance will have its {@link #isUnordered() unordered}
|
||||
* value set to {@code false}, its {@link #timeToLive() timeToLive} value
|
||||
* set to {@code 0}, its {@link #isComplete() complete} value set
|
||||
* to {@code true}, and its {@link #payloadProtocolID() payloadProtocolID}
|
||||
* value set to {@code 0}. These values, if required, can be set through
|
||||
* the appropriate setter method before sending the message.
|
||||
*
|
||||
* @param address
|
||||
* For a connected {@code SctpChannel} the address is the
|
||||
* preferred peer address of the association to send the message
|
||||
* to, or {@code null} to use the peer primary address. For an
|
||||
* {@code SctpMultiChannel} the address is used to determine
|
||||
* the association, or if no association exists with a peer of that
|
||||
* address then one is setup.
|
||||
*
|
||||
* @param streamNumber
|
||||
* The stream number that the message will be sent on
|
||||
*
|
||||
* @return The outgoing message info
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the streamNumber is negative or greater than {@code 65536}
|
||||
*/
|
||||
public static MessageInfo createOutgoing(SocketAddress address,
|
||||
int streamNumber) {
|
||||
if (streamNumber < 0 || streamNumber > 65536)
|
||||
throw new IllegalArgumentException("Invalid stream number");
|
||||
|
||||
return new sun.nio.ch.sctp.MessageInfoImpl(null, address, streamNumber);
|
||||
}
|
||||
/**
|
||||
* Creates a {@code MessageInfo} instance suitable for use when
|
||||
* sending a message to a given association. Typically used for
|
||||
* {@code SctpMultiChannel} when an association has already been setup.
|
||||
*
|
||||
* <P> The returned instance will have its {@link #isUnordered() unordered}
|
||||
* value set to {@code false}, its {@link #timeToLive() timeToLive} value
|
||||
* set to {@code 0}, its {@link #isComplete() complete} value set
|
||||
* to {@code true}, and its {@link #payloadProtocolID() payloadProtocolID}
|
||||
* value set to {@code 0}. These values, if required, can be set through
|
||||
* the appropriate setter method before sending the message.
|
||||
*
|
||||
* @param association
|
||||
* The association to send the message on
|
||||
*
|
||||
* @param address
|
||||
* The preferred peer address of the association to send the message
|
||||
* to, or {@code null} to use the peer primary address
|
||||
*
|
||||
* @param streamNumber
|
||||
* The stream number that the message will be sent on.
|
||||
*
|
||||
* @return The outgoing message info
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If {@code association} is {@code null}, or the streamNumber is
|
||||
* negative or greater than {@code 65536}
|
||||
*/
|
||||
public static MessageInfo createOutgoing(Association association,
|
||||
SocketAddress address,
|
||||
int streamNumber) {
|
||||
if (association == null)
|
||||
throw new IllegalArgumentException("association cannot be null");
|
||||
|
||||
if (streamNumber < 0 || streamNumber > 65536)
|
||||
throw new IllegalArgumentException("Invalid stream number");
|
||||
|
||||
return new sun.nio.ch.sctp.MessageInfoImpl(association,
|
||||
address, streamNumber);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the source socket address if the message has been received,
|
||||
* otherwise the preferred destination of the message to be sent.
|
||||
*
|
||||
* @return The socket address, or {@code null} if this instance is to be
|
||||
* used for sending a message and has been construced without
|
||||
* specifying a preferred destination address
|
||||
*
|
||||
*/
|
||||
public abstract SocketAddress address();
|
||||
|
||||
/**
|
||||
* Returns the association that the message was received on, if the message
|
||||
* has been received, otherwise the association that the message is to be
|
||||
* sent on.
|
||||
*
|
||||
* @return The association, or {@code null} if this instance is to be
|
||||
* used for sending a message and has been construced using the
|
||||
* the {@link #createOutgoing(SocketAddress,int)
|
||||
* createOutgoing(SocketAddress,int)} static factory method
|
||||
*/
|
||||
public abstract Association association();
|
||||
|
||||
/**
|
||||
* Returns the number of bytes read for the received message.
|
||||
*
|
||||
* <P> This method is only appicable for received messages, it has no
|
||||
* meaning for messages being sent.
|
||||
*
|
||||
* @return The number of bytes read, {@code -1} if the channel is an {@link
|
||||
* SctpChannel} that has reached end-of-stream, otherwise
|
||||
* {@code 0}
|
||||
*/
|
||||
public abstract int bytes();
|
||||
|
||||
/**
|
||||
* Tells whether or not the message is complete.
|
||||
*
|
||||
* <P> For received messages {@code true} indicates that the message was
|
||||
* completely received. For messages being sent {@code true} indicates that
|
||||
* the message is complete, {@code false} indicates that the message is not
|
||||
* complete. How the send channel interprets this value depends on the value
|
||||
* of its {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE
|
||||
* SCTP_EXPLICIT_COMPLETE} socket option.
|
||||
*
|
||||
* @return {@code true} if, and only if, the message is complete
|
||||
*/
|
||||
public abstract boolean isComplete();
|
||||
|
||||
/**
|
||||
* Sets whether or not the message is complete.
|
||||
*
|
||||
* <P> For messages being sent {@code true} indicates that
|
||||
* the message is complete, {@code false} indicates that the message is not
|
||||
* complete. How the send channel interprets this value depends on the value
|
||||
* of its {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE
|
||||
* SCTP_EXPLICIT_COMPLETE} socket option.
|
||||
*
|
||||
* @param complete
|
||||
* {@code true} if, and only if, the message is complete
|
||||
*
|
||||
* @return This MessageInfo
|
||||
*
|
||||
* @see MessageInfo#isComplete()
|
||||
*/
|
||||
public abstract MessageInfo complete(boolean complete);
|
||||
|
||||
/**
|
||||
* Tells whether or not the message is unordered. For received messages
|
||||
* {@code true} indicates that the message was sent non-ordered. For
|
||||
* messages being sent {@code true} requests the un-ordered delivery of the
|
||||
* message, {@code false} indicates that the message is ordered.
|
||||
*
|
||||
* @return {@code true} if the message is unordered, otherwise
|
||||
* {@code false}
|
||||
*/
|
||||
public abstract boolean isUnordered();
|
||||
|
||||
/**
|
||||
* Sets whether or not the message is unordered.
|
||||
*
|
||||
* @param unordered
|
||||
* {@code true} requests the un-ordered delivery of the message,
|
||||
* {@code false} indicates that the message is ordered.
|
||||
*
|
||||
* @return This MessageInfo
|
||||
*
|
||||
* @see MessageInfo#isUnordered()
|
||||
*/
|
||||
public abstract MessageInfo unordered(boolean unordered);
|
||||
|
||||
/**
|
||||
* Returns the payload protocol Identifier.
|
||||
*
|
||||
* <P> A value indicating the type of payload protocol data being
|
||||
* transmitted/received. This value is passed as opaque data by SCTP.
|
||||
* {@code 0} indicates an unspecified payload protocol identifier.
|
||||
*
|
||||
* @return The Payload Protocol Identifier
|
||||
*/
|
||||
public abstract int payloadProtocolID();
|
||||
|
||||
/**
|
||||
* Sets the payload protocol Identifier.
|
||||
*
|
||||
* <P> A value indicating the type of payload protocol data being
|
||||
* transmitted. This value is passed as opaque data by SCTP.
|
||||
*
|
||||
* @param ppid
|
||||
* The Payload Protocol Identifier, or {@code 0} indicate an
|
||||
* unspecified payload protocol identifier.
|
||||
*
|
||||
* @return This MessageInfo
|
||||
*
|
||||
* @see MessageInfo#payloadProtocolID()
|
||||
*/
|
||||
public abstract MessageInfo payloadProtocolID(int ppid);
|
||||
|
||||
/**
|
||||
* Returns the stream number that the message was received on, if the
|
||||
* message has been received, otherwise the stream number that the message
|
||||
* is to be sent on.
|
||||
*
|
||||
* @return The stream number
|
||||
*/
|
||||
public abstract int streamNumber();
|
||||
|
||||
/**
|
||||
* Sets the stream number that the message is to be sent on.
|
||||
*
|
||||
* @param streamNumber
|
||||
* The stream number
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the streamNumber is negative or greater than {@code 65536}
|
||||
*
|
||||
* @return This MessageInfo
|
||||
*/
|
||||
public abstract MessageInfo streamNumber(int streamNumber);
|
||||
|
||||
/**
|
||||
* The time period that the sending side may expire the message if it has
|
||||
* not been sent, or {@code 0} to indicate that no timeout should occur. This
|
||||
* value is only applicable for messages being sent, it has no meaning for
|
||||
* received messages.
|
||||
*
|
||||
* @return The time period in milliseconds, or {@code 0}
|
||||
*/
|
||||
public abstract long timeToLive();
|
||||
|
||||
/**
|
||||
* Sets the time period that the sending side may expire the message if it
|
||||
* has not been sent.
|
||||
*
|
||||
* @param millis
|
||||
* The time period in milliseconds, or {@code 0} to indicate that no
|
||||
* timeout should occur
|
||||
*
|
||||
* @return This MessageInfo
|
||||
*
|
||||
* @see MessageInfo#timeToLive()
|
||||
*/
|
||||
public abstract MessageInfo timeToLive(long millis);
|
||||
}
|
||||
48
jdkSrc/jdk8/com/sun/nio/sctp/Notification.java
Normal file
48
jdkSrc/jdk8/com/sun/nio/sctp/Notification.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* A notification from the SCTP stack.
|
||||
*
|
||||
* <P> Objects of this type are passed to the {@link NotificationHandler} when
|
||||
* a notification is received.
|
||||
*
|
||||
* <P> An SCTP channel supports the following notifications: {@link
|
||||
* AssociationChangeNotification}, {@link PeerAddressChangeNotification},
|
||||
* {@link SendFailedNotification}, {@link ShutdownNotification}, and may support
|
||||
* additional implementation specific notifications.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface Notification {
|
||||
/**
|
||||
* Returns the association that this notification is applicable to.
|
||||
*
|
||||
* @return The association
|
||||
*/
|
||||
public Association association();
|
||||
}
|
||||
66
jdkSrc/jdk8/com/sun/nio/sctp/NotificationHandler.java
Normal file
66
jdkSrc/jdk8/com/sun/nio/sctp/NotificationHandler.java
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* A handler for consuming notifications from the SCTP stack.
|
||||
*
|
||||
* <P> The SCTP channels defined in this package allow a notification handler to
|
||||
* be specified to consume notifications from the SCTP stack. When a
|
||||
* notification is received the {@linkplain #handleNotification
|
||||
* handleNotification} method of the handler is invoked to handle that
|
||||
* notification.
|
||||
*
|
||||
* <P> Additionally, an attachment object can be attached to the {@code receive}
|
||||
* operation to provide context when consuming the notification. The
|
||||
* attachment is important for cases where a <i>state-less</i> {@code
|
||||
* NotificationHandler} is used to consume the result of many {@code receive}
|
||||
* operations.
|
||||
*
|
||||
* <P> Handler implementations are encouraged to extend the {@link
|
||||
* AbstractNotificationHandler} class which implements this interface and
|
||||
* provide notification specific methods. However, an API should generally use
|
||||
* this handler interface as the type for parameters, return type, etc. rather
|
||||
* than the abstract class.
|
||||
*
|
||||
* @param T The type of the object attached to the receive operation
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface NotificationHandler<T> {
|
||||
/**
|
||||
* Invoked when a notification is received from the SCTP stack.
|
||||
*
|
||||
* @param notification
|
||||
* The notification
|
||||
*
|
||||
* @param attachment
|
||||
* The object attached to the receive operation when it was initiated.
|
||||
*
|
||||
* @return The handler result
|
||||
*/
|
||||
HandlerResult handleNotification(Notification notification, T attachment);
|
||||
}
|
||||
109
jdkSrc/jdk8/com/sun/nio/sctp/PeerAddressChangeNotification.java
Normal file
109
jdkSrc/jdk8/com/sun/nio/sctp/PeerAddressChangeNotification.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* Notification emitted when a destination address on a multi-homed peer
|
||||
* encounters a change.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class PeerAddressChangeNotification
|
||||
implements Notification
|
||||
{
|
||||
/**
|
||||
* Defines the type of address change event that occurred to the destination
|
||||
* address on a multi-homed peer when it encounters a change of interface
|
||||
* details.
|
||||
*
|
||||
* <P> Some of these events types are only generated when the association
|
||||
* supports dynamic address reconfiguration, e.g. {@code SCTP_ADDR_ADDED},
|
||||
* {@code SCTP_ADDR_REMOVED}, etc.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public enum AddressChangeEvent {
|
||||
/**
|
||||
* This address is now reachable.
|
||||
*/
|
||||
ADDR_AVAILABLE,
|
||||
|
||||
/**
|
||||
* The address specified can no longer be reached. Any data sent to this
|
||||
* address is rerouted to an alternate until this address becomes reachable.
|
||||
*/
|
||||
ADDR_UNREACHABLE,
|
||||
|
||||
/**
|
||||
* The address is no longer part of the association.
|
||||
*/
|
||||
ADDR_REMOVED,
|
||||
|
||||
/**
|
||||
* The address is now part of the association.
|
||||
*/
|
||||
ADDR_ADDED,
|
||||
|
||||
/**
|
||||
* This address has now been made to be the primary destination address.
|
||||
*/
|
||||
ADDR_MADE_PRIMARY,
|
||||
|
||||
/**
|
||||
* This address has now been confirmed as a valid address.
|
||||
*/
|
||||
ADDR_CONFIRMED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected PeerAddressChangeNotification() {}
|
||||
|
||||
/**
|
||||
* Returns the peer address.
|
||||
*
|
||||
* @return The peer address
|
||||
*/
|
||||
public abstract SocketAddress address();
|
||||
|
||||
/**
|
||||
* Returns the association that this notification is applicable to.
|
||||
*
|
||||
* @return The association whose peer address changed
|
||||
*/
|
||||
public abstract Association association();
|
||||
|
||||
/**
|
||||
* Returns the type of change event.
|
||||
*
|
||||
* @return The event
|
||||
*/
|
||||
public abstract AddressChangeEvent event();
|
||||
}
|
||||
874
jdkSrc/jdk8/com/sun/nio/sctp/SctpChannel.java
Normal file
874
jdkSrc/jdk8/com/sun/nio/sctp/SctpChannel.java
Normal file
@@ -0,0 +1,874 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.InetAddress;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
/**
|
||||
* A selectable channel for message-oriented connected SCTP sockets.
|
||||
*
|
||||
* <P> An SCTP channel can only control one SCTP association.
|
||||
* An {@code SCTPChannel} is created by invoking one of the
|
||||
* {@link #open open} methods of this class. A newly-created channel is open but
|
||||
* not yet connected, that is, there is no association setup with a remote peer.
|
||||
* An attempt to invoke an I/O operation upon an unconnected
|
||||
* channel will cause a {@link java.nio.channels.NotYetConnectedException} to be
|
||||
* thrown. An association can be setup by connecting the channel using one of
|
||||
* its {@link #connect connect} methods. Once connected, the channel remains
|
||||
* connected until it is closed. Whether or not a channel is connected may be
|
||||
* determined by invoking {@link #getRemoteAddresses getRemoteAddresses}.
|
||||
*
|
||||
* <p> SCTP channels support <i>non-blocking connection:</i> A
|
||||
* channel may be created and the process of establishing the link to
|
||||
* the remote socket may be initiated via the {@link #connect connect} method
|
||||
* for later completion by the {@link #finishConnect finishConnect} method.
|
||||
* Whether or not a connection operation is in progress may be determined by
|
||||
* invoking the {@link #isConnectionPending isConnectionPending} method.
|
||||
*
|
||||
* <p> Socket options are configured using the
|
||||
* {@link #setOption(SctpSocketOption,Object) setOption} method. An SCTP
|
||||
* channel support the following options:
|
||||
* <blockquote>
|
||||
* <table border summary="Socket options">
|
||||
* <tr>
|
||||
* <th>Option Name</th>
|
||||
* <th>Description</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_DISABLE_FRAGMENTS
|
||||
* SCTP_DISABLE_FRAGMENTS} </td>
|
||||
* <td> Enables or disables message fragmentation </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE
|
||||
* SCTP_EXPLICIT_COMPLETE} </td>
|
||||
* <td> Enables or disables explicit message completion </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE
|
||||
* SCTP_FRAGMENT_INTERLEAVE} </td>
|
||||
* <td> Controls how the presentation of messages occur for the message
|
||||
* receiver </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS
|
||||
* SCTP_INIT_MAXSTREAMS} </td>
|
||||
* <td> The maximum number of streams requested by the local endpoint during
|
||||
* association initialization </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_NODELAY SCTP_NODELAY} </td>
|
||||
* <td> Enables or disable a Nagle-like algorithm </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_PRIMARY_ADDR
|
||||
* SCTP_PRIMARY_ADDR} </td>
|
||||
* <td> Requests that the local SCTP stack use the given peer address as the
|
||||
* association primary </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_SET_PEER_PRIMARY_ADDR
|
||||
* SCTP_SET_PEER_PRIMARY_ADDR} </td>
|
||||
* <td> Requests that the peer mark the enclosed address as the association
|
||||
* primary </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SO_SNDBUF
|
||||
* SO_SNDBUF} </td>
|
||||
* <td> The size of the socket send buffer </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SO_RCVBUF
|
||||
* SO_RCVBUF} </td>
|
||||
* <td> The size of the socket receive buffer </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SO_LINGER
|
||||
* SO_LINGER} </td>
|
||||
* <td> Linger on close if data is present (when configured in blocking mode
|
||||
* only) </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
* Additional (implementation specific) options may also be supported. The list
|
||||
* of options supported is obtained by invoking the {@link #supportedOptions()
|
||||
* supportedOptions} method.
|
||||
*
|
||||
* <p> SCTP channels are safe for use by multiple concurrent threads.
|
||||
* They support concurrent reading and writing, though at most one thread may be
|
||||
* reading and at most one thread may be writing at any given time. The
|
||||
* {@link #connect connect} and {@link #finishConnect
|
||||
* finishConnect} methods are mutually synchronized against each other, and
|
||||
* an attempt to initiate a send or receive operation while an invocation of one
|
||||
* of these methods is in progress will block until that invocation is complete.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class SctpChannel
|
||||
extends AbstractSelectableChannel
|
||||
{
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*
|
||||
* @param provider
|
||||
* The selector provider for this channel
|
||||
*/
|
||||
protected SctpChannel(SelectorProvider provider) {
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an SCTP channel.
|
||||
*
|
||||
* <P> The new channel is unbound and unconnected.
|
||||
*
|
||||
* @return A new SCTP channel
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the SCTP protocol is not supported
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static SctpChannel open() throws
|
||||
IOException {
|
||||
return new sun.nio.ch.sctp.SctpChannelImpl((SelectorProvider)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an SCTP channel and connects it to a remote address.
|
||||
*
|
||||
* <P> This is a convenience method and is equivalent to evaluating the
|
||||
* following expression:
|
||||
* <blockquote><pre>
|
||||
* open().connect(remote, maxOutStreams, maxInStreams);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param remote
|
||||
* The remote address to which the new channel is to be connected
|
||||
*
|
||||
* @param maxOutStreams
|
||||
* The number of streams that the application wishes to be able
|
||||
* to send to. Must be non negative and no larger than {@code 65536}.
|
||||
* {@code 0} to use the endpoints default value.
|
||||
*
|
||||
* @param maxInStreams
|
||||
* The maximum number of inbound streams the application is prepared
|
||||
* to support. Must be non negative and no larger than {@code 65536}.
|
||||
* {@code 0} to use the endpoints default value.
|
||||
*
|
||||
* @return A new SCTP channel connected to the given address
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the connect operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the connect operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws java.nio.channels.UnresolvedAddressException
|
||||
* If the given remote address is not fully resolved
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given remote address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed
|
||||
* and it does not permit access to the given remote peer
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the SCTP protocol is not supported
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public static SctpChannel open(SocketAddress remote, int maxOutStreams,
|
||||
int maxInStreams) throws IOException {
|
||||
SctpChannel ssc = SctpChannel.open();
|
||||
ssc.connect(remote, maxOutStreams, maxInStreams);
|
||||
return ssc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the association on this channel's socket.
|
||||
*
|
||||
* @return the association, or {@code null} if the channel's socket is not
|
||||
* connected.
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If the channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract Association association() throws IOException;
|
||||
|
||||
/**
|
||||
* Binds the channel's socket to a local address.
|
||||
*
|
||||
* <P> This method is used to establish a relationship between the socket
|
||||
* and the local addresses. Once a relationship is established then
|
||||
* the socket remains bound until the channel is closed. This relationship
|
||||
* may not necesssarily be with the address {@code local} as it may be removed
|
||||
* by {@link #unbindAddress unbindAddress}, but there will always be at least
|
||||
* one local address bound to the channel's socket once an invocation of
|
||||
* this method successfully completes.
|
||||
*
|
||||
* <P> Once the channel's socket has been successfully bound to a specific
|
||||
* address, that is not automatically assigned, more addresses
|
||||
* may be bound to it using {@link #bindAddress bindAddress}, or removed
|
||||
* using {@link #unbindAddress unbindAddress}.
|
||||
*
|
||||
* @param local
|
||||
* The local address to bind the socket, or {@code null} to
|
||||
* bind the socket to an automatically assigned socket address
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyConnectedException
|
||||
* If this channel is already connected
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.ConnectionPendingException
|
||||
* If a non-blocking connection operation is already in progress on this channel
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given address is not supported
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and its
|
||||
* {@link SecurityManager#checkListen checkListen} method denies
|
||||
* the operation
|
||||
*/
|
||||
public abstract SctpChannel bind(SocketAddress local)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Adds the given address to the bound addresses for the channel's
|
||||
* socket.
|
||||
*
|
||||
* <P> The given address must not be the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address.
|
||||
* The channel must be first bound using {@link #bind bind} before
|
||||
* invoking this method, otherwise {@link
|
||||
* java.nio.channels.NotYetBoundException} is thrown. The {@link #bind bind}
|
||||
* method takes a {@code SocketAddress} as its argument which typically
|
||||
* contains a port number as well as an address. Addresses subquently bound
|
||||
* using this method are simply addresses as the SCTP port number remains
|
||||
* the same for the lifetime of the channel.
|
||||
*
|
||||
* <P> Adding addresses to a connected association is optional functionality.
|
||||
* If the endpoint supports dynamic address reconfiguration then it may
|
||||
* send the appropriate message to the peer to change the peers address
|
||||
* lists.
|
||||
*
|
||||
* @param address
|
||||
* The address to add to the bound addresses for the socket
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.ConnectionPendingException
|
||||
* If a non-blocking connection operation is already in progress on
|
||||
* this channel
|
||||
*
|
||||
* @throws java.nio.channels.NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound to the given address
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If address is {@code null} or the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpChannel bindAddress(InetAddress address)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Removes the given address from the bound addresses for the channel's
|
||||
* socket.
|
||||
*
|
||||
* <P> The given address must not be the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address.
|
||||
* The channel must be first bound using {@link #bind bind} before
|
||||
* invoking this method, otherwise {@link java.nio.channels.NotYetBoundException}
|
||||
* is thrown. If this method is invoked on a channel that does not have
|
||||
* {@code address} as one of its bound addresses or that has only one
|
||||
* local address bound to it, then this method throws
|
||||
* {@link IllegalUnbindException}.
|
||||
* The initial address that the channel's socket is bound to using {@link
|
||||
* #bind bind} may be removed from the bound addresses for the channel's socket.
|
||||
*
|
||||
* <P> Removing addresses from a connected association is optional
|
||||
* functionality. If the endpoint supports dynamic address reconfiguration
|
||||
* then it may send the appropriate message to the peer to change the peers
|
||||
* address lists.
|
||||
*
|
||||
* @param address
|
||||
* The address to remove from the bound addresses for the socket
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.ConnectionPendingException
|
||||
* If a non-blocking connection operation is already in progress on
|
||||
* this channel
|
||||
*
|
||||
* @throws java.nio.channels.NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If address is {@code null} or the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address
|
||||
*
|
||||
* @throws IllegalUnbindException
|
||||
* If {@code address} is not bound to the channel's socket. or
|
||||
* the channel has only one address bound to it
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpChannel unbindAddress(InetAddress address)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Connects this channel's socket.
|
||||
*
|
||||
* <P> If this channel is in non-blocking mode then an invocation of this
|
||||
* method initiates a non-blocking connection operation. If the connection
|
||||
* is established immediately, as can happen with a local connection, then
|
||||
* this method returns {@code true}. Otherwise this method returns
|
||||
* {@code false} and the connection operation must later be completed by
|
||||
* invoking the {@link #finishConnect finishConnect} method.
|
||||
*
|
||||
* <P> If this channel is in blocking mode then an invocation of this
|
||||
* method will block until the connection is established or an I/O error
|
||||
* occurs.
|
||||
*
|
||||
* <P> If a security manager has been installed then this method verifies
|
||||
* that its {@link java.lang.SecurityManager#checkConnect checkConnect}
|
||||
* method permits connecting to the address and port number of the given
|
||||
* remote peer.
|
||||
*
|
||||
* <p> This method may be invoked at any time. If a {@link #send send} or
|
||||
* {@link #receive receive} operation upon this channel is invoked while an
|
||||
* invocation of this method is in progress then that operation will first
|
||||
* block until this invocation is complete. If a connection attempt is
|
||||
* initiated but fails, that is, if an invocation of this method throws a
|
||||
* checked exception, then the channel will be closed.
|
||||
*
|
||||
* @param remote
|
||||
* The remote peer to which this channel is to be connected
|
||||
*
|
||||
* @return {@code true} if a connection was established, {@code false} if
|
||||
* this channel is in non-blocking mode and the connection
|
||||
* operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyConnectedException
|
||||
* If this channel is already connected
|
||||
*
|
||||
* @throws java.nio.channels.ConnectionPendingException
|
||||
* If a non-blocking connection operation is already in progress on
|
||||
* this channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the connect operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the connect operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws java.nio.channels.UnresolvedAddressException
|
||||
* If the given remote address is not fully resolved
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given remote address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed
|
||||
* and it does not permit access to the given remote peer
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract boolean connect(SocketAddress remote) throws IOException;
|
||||
|
||||
/**
|
||||
* Connects this channel's socket.
|
||||
*
|
||||
* <P> This is a convience method and is equivalent to evaluating the
|
||||
* following expression:
|
||||
* <blockquote><pre>
|
||||
* setOption(SctpStandardSocketOptions.SCTP_INIT_MAXSTREAMS, SctpStandardSocketOption.InitMaxStreams.create(maxInStreams, maxOutStreams))
|
||||
* .connect(remote);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* <P> The {@code maxOutStreams} and {@code maxInStreams} parameters
|
||||
* represent the maximum number of streams that the application wishes to be
|
||||
* able to send to and receive from. They are negotiated with the remote
|
||||
* peer and may be limited by the operating system.
|
||||
*
|
||||
* @param remote
|
||||
* The remote peer to which this channel is to be connected
|
||||
*
|
||||
* @param maxOutStreams
|
||||
* Must be non negative and no larger than {@code 65536}.
|
||||
* {@code 0} to use the endpoints default value.
|
||||
*
|
||||
* @param maxInStreams
|
||||
* Must be non negative and no larger than {@code 65536}.
|
||||
* {@code 0} to use the endpoints default value.
|
||||
*
|
||||
* @return {@code true} if a connection was established, {@code false} if
|
||||
* this channel is in non-blocking mode and the connection operation
|
||||
* is in progress
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyConnectedException
|
||||
* If this channel is already connected
|
||||
*
|
||||
* @throws java.nio.channels.ConnectionPendingException
|
||||
* If a non-blocking connection operation is already in progress on
|
||||
* this channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the connect operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the connect operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws java.nio.channels.UnresolvedAddressException
|
||||
* If the given remote address is not fully resolved
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given remote address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed
|
||||
* and it does not permit access to the given remote peer
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract boolean connect(SocketAddress remote,
|
||||
int maxOutStreams,
|
||||
int maxInStreams)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Tells whether or not a connection operation is in progress on this channel.
|
||||
*
|
||||
* @return {@code true} if, and only if, a connection operation has been initiated
|
||||
* on this channel but not yet completed by invoking the
|
||||
* {@link #finishConnect} method
|
||||
*/
|
||||
public abstract boolean isConnectionPending();
|
||||
|
||||
/**
|
||||
* Finishes the process of connecting an SCTP channel.
|
||||
*
|
||||
* <P> A non-blocking connection operation is initiated by placing a socket
|
||||
* channel in non-blocking mode and then invoking one of its {@link #connect
|
||||
* connect} methods. Once the connection is established, or the attempt has
|
||||
* failed, the channel will become connectable and this method may
|
||||
* be invoked to complete the connection sequence. If the connection
|
||||
* operation failed then invoking this method will cause an appropriate
|
||||
* {@link java.io.IOException} to be thrown.
|
||||
*
|
||||
* <P> If this channel is already connected then this method will not block
|
||||
* and will immediately return <tt>true</tt>. If this channel is in
|
||||
* non-blocking mode then this method will return <tt>false</tt> if the
|
||||
* connection process is not yet complete. If this channel is in blocking
|
||||
* mode then this method will block until the connection either completes
|
||||
* or fails, and will always either return <tt>true</tt> or throw a checked
|
||||
* exception describing the failure.
|
||||
*
|
||||
* <P> This method may be invoked at any time. If a {@link #send send} or {@link #receive receive}
|
||||
* operation upon this channel is invoked while an invocation of this
|
||||
* method is in progress then that operation will first block until this
|
||||
* invocation is complete. If a connection attempt fails, that is, if an
|
||||
* invocation of this method throws a checked exception, then the channel
|
||||
* will be closed.
|
||||
*
|
||||
* @return {@code true} if, and only if, this channel's socket is now
|
||||
* connected
|
||||
*
|
||||
* @throws java.nio.channels.NoConnectionPendingException
|
||||
* If this channel is not connected and a connection operation
|
||||
* has not been initiated
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the connect operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the connect operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract boolean finishConnect() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns all of the socket addresses to which this channel's socket is
|
||||
* bound.
|
||||
*
|
||||
* @return All the socket addresses that this channel's socket is
|
||||
* bound to, or an empty {@code Set} if the channel's socket is not
|
||||
* bound
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If the channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public abstract Set<SocketAddress> getAllLocalAddresses()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns all of the remote addresses to which this channel's socket
|
||||
* is connected.
|
||||
*
|
||||
* <P> If the channel is connected to a remote peer that is bound to
|
||||
* multiple addresses then it is these addresses that the channel's socket
|
||||
* is connected.
|
||||
*
|
||||
* @return All of the remote addresses to which this channel's socket
|
||||
* is connected, or an empty {@code Set} if the channel's socket is
|
||||
* not connected
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If the channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public abstract Set<SocketAddress> getRemoteAddresses()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Shutdown a connection without closing the channel.
|
||||
*
|
||||
* <P> Sends a shutdown command to the remote peer, effectively preventing
|
||||
* any new data from being written to the socket by either peer. Further
|
||||
* sends will throw {@link java.nio.channels.ClosedChannelException}. The
|
||||
* channel remains open to allow the for any data (and notifications) to be
|
||||
* received that may have been sent by the peer before it received the
|
||||
* shutdown command. If the channel is already shutdown then invoking this
|
||||
* method has no effect.
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.NotYetConnectedException
|
||||
* If this channel is not yet connected
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpChannel shutdown() throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the value of a socket option.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the socket option value
|
||||
*
|
||||
* @param name
|
||||
* The socket option
|
||||
*
|
||||
* @return The value of the socket option. A value of {@code null} may be
|
||||
* a valid value for some socket options.
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the socket option is not supported by this channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
public abstract <T> T getOption(SctpSocketOption<T> name)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the value of a socket option.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the socket option value
|
||||
*
|
||||
* @param name
|
||||
* The socket option
|
||||
*
|
||||
* @param value
|
||||
* The value of the socket option. A value of {@code null} may be
|
||||
* a valid value for some socket options.
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the socket option is not supported by this channel
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the value is not a valid value for this socket option
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
public abstract <T> SctpChannel setOption(SctpSocketOption<T> name, T value)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a set of the socket options supported by this channel.
|
||||
*
|
||||
* <P> This method will continue to return the set of options even after the
|
||||
* channel has been closed.
|
||||
*
|
||||
* @return A set of the socket options supported by this channel
|
||||
*/
|
||||
public abstract Set<SctpSocketOption<?>> supportedOptions();
|
||||
|
||||
/**
|
||||
* Returns an operation set identifying this channel's supported operations.
|
||||
*
|
||||
* <P> SCTP channels support connecting, reading, and writing, so this
|
||||
* method returns <tt>(</tt>{@link SelectionKey#OP_CONNECT}
|
||||
* <tt>|</tt> {@link SelectionKey#OP_READ} <tt>|</tt> {@link
|
||||
* SelectionKey#OP_WRITE}<tt>)</tt>. </p>
|
||||
*
|
||||
* @return The valid-operation set
|
||||
*/
|
||||
@Override
|
||||
public final int validOps() {
|
||||
return (SelectionKey.OP_READ |
|
||||
SelectionKey.OP_WRITE |
|
||||
SelectionKey.OP_CONNECT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a message into the given buffer and/or handles a notification.
|
||||
*
|
||||
* <P> If a message or notification is immediately available, or if this
|
||||
* channel is in blocking mode and one eventually becomes available, then
|
||||
* the message or notification is returned or handled, respectively. If this
|
||||
* channel is in non-blocking mode and a message or notification is not
|
||||
* immediately available then this method immediately returns {@code null}.
|
||||
*
|
||||
* <P> If this method receives a message it is copied into the given byte
|
||||
* buffer. The message is transferred into the given byte buffer starting at
|
||||
* its current position and the buffers position is incremented by the
|
||||
* number of bytes read. If there are fewer bytes remaining in the buffer
|
||||
* than are required to hold the message, or the underlying input buffer
|
||||
* does not contain the complete message, then an invocation of {@link
|
||||
* MessageInfo#isComplete isComplete} on the returned {@code
|
||||
* MessageInfo} will return {@code false}, and more invocations of this
|
||||
* method will be necessary to completely consume the messgae. Only
|
||||
* one message at a time will be partially delivered in any stream. The
|
||||
* socket option {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE
|
||||
* SCTP_FRAGMENT_INTERLEAVE} controls various aspects of what interlacing of
|
||||
* messages occurs.
|
||||
*
|
||||
* <P> If this method receives a notification then the appropriate method of
|
||||
* the given handler, if there is one, is invoked. If the handler returns
|
||||
* {@link HandlerResult#CONTINUE CONTINUE} then this method will try to
|
||||
* receive another message/notification, otherwise, if {@link
|
||||
* HandlerResult#RETURN RETURN} is returned this method will return {@code
|
||||
* null}. If an uncaught exception is thrown by the handler it will be
|
||||
* propagated up the stack through this method.
|
||||
*
|
||||
* <P> This method may be invoked at any time. If another thread has
|
||||
* already initiated a receive operation upon this channel, then an
|
||||
* invocation of this method will block until the first operation is
|
||||
* complete. The given handler is invoked without holding any locks used
|
||||
* to enforce the above synchronization policy, that way handlers
|
||||
* will not stall other threads from receiving. A handler should not invoke
|
||||
* the {@code receive} method of this channel, if it does an
|
||||
* {@link IllegalReceiveException} will be thrown.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the attachment
|
||||
*
|
||||
* @param dst
|
||||
* The buffer into which message bytes are to be transferred
|
||||
*
|
||||
* @param attachment
|
||||
* The object to attach to the receive operation; can be
|
||||
* {@code null}
|
||||
*
|
||||
* @param handler
|
||||
* A handler to handle notifications from the SCTP stack, or {@code
|
||||
* null} to ignore any notifications.
|
||||
*
|
||||
* @return The {@code MessageInfo}, {@code null} if this channel is in
|
||||
* non-blocking mode and no messages are immediately available or
|
||||
* the notification handler returns {@link HandlerResult#RETURN
|
||||
* RETURN} after handling a notification
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the read operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the read operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws java.nio.channels.NotYetConnectedException
|
||||
* If this channel is not yet connected
|
||||
*
|
||||
* @throws IllegalReceiveException
|
||||
* If the given handler invokes the {@code receive} method of this
|
||||
* channel
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract <T> MessageInfo receive(ByteBuffer dst,
|
||||
T attachment,
|
||||
NotificationHandler<T> handler)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Sends a message via this channel.
|
||||
*
|
||||
* <P> If this channel is in non-blocking mode and there is sufficient room
|
||||
* in the underlying output buffer, or if this channel is in blocking mode
|
||||
* and sufficient room becomes available, then the remaining bytes in the
|
||||
* given byte buffer are transmitted as a single message. Sending a message
|
||||
* is atomic unless explicit message completion {@link
|
||||
* SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE SCTP_EXPLICIT_COMPLETE}
|
||||
* socket option is enabled on this channel's socket.
|
||||
*
|
||||
* <P> The message is transferred from the byte buffer as if by a regular
|
||||
* {@link java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)
|
||||
* write} operation.
|
||||
*
|
||||
* <P> The bytes will be written to the stream number that is specified by
|
||||
* {@link MessageInfo#streamNumber streamNumber} in the given {@code
|
||||
* messageInfo}.
|
||||
*
|
||||
* <P> This method may be invoked at any time. If another thread has already
|
||||
* initiated a send operation upon this channel, then an invocation of
|
||||
* this method will block until the first operation is complete.
|
||||
*
|
||||
* @param src
|
||||
* The buffer containing the message to be sent
|
||||
*
|
||||
* @param messageInfo
|
||||
* Ancillary data about the message to be sent
|
||||
*
|
||||
* @return The number of bytes sent, which will be either the number of
|
||||
* bytes that were remaining in the messages buffer when this method
|
||||
* was invoked or, if this channel is non-blocking, may be zero if
|
||||
* there was insufficient room for the message in the underlying
|
||||
* output buffer
|
||||
*
|
||||
* @throws InvalidStreamException
|
||||
* If {@code streamNumner} is negative or greater than or equal to
|
||||
* the maximum number of outgoing streams
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the read operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the read operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws java.nio.channels.NotYetConnectedException
|
||||
* If this channel is not yet connected
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract int send(ByteBuffer src, MessageInfo messageInfo)
|
||||
throws IOException;
|
||||
}
|
||||
744
jdkSrc/jdk8/com/sun/nio/sctp/SctpMultiChannel.java
Normal file
744
jdkSrc/jdk8/com/sun/nio/sctp/SctpMultiChannel.java
Normal file
@@ -0,0 +1,744 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.InetAddress;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.nio.channels.ClosedChannelException;
|
||||
import java.nio.channels.NotYetBoundException;
|
||||
import java.nio.channels.SelectionKey;
|
||||
|
||||
/**
|
||||
* A selectable channel for message-oriented SCTP sockets.
|
||||
*
|
||||
* <P> An SCTP multi channel supports many associations on a single socket.
|
||||
* An {@code SctpMultiChannel} is created by invoking the
|
||||
* {@link #open open} method of this class. A newly-created channel is open but
|
||||
* not yet bound. An attempt to invoke the {@link #receive receive} method of an
|
||||
* unbound channel will cause the {@link NotYetBoundException}
|
||||
* to be thrown. An attempt to invoke the {@link #send send} method of an
|
||||
* unbound channel will cause it to first invoke the {@link #bind bind} method.
|
||||
* The address(es) that the channel's socket is bound to can be retrieved by
|
||||
* calling {@link #getAllLocalAddresses getAllLocalAddresses}.
|
||||
*
|
||||
* <P> Messages may be sent and received without explicitly setting up an
|
||||
* association with the remote peer. The channel will implicitly setup
|
||||
* a new association whenever it sends or receives a message from a remote
|
||||
* peer if there is not already an association with that peer. Upon successful
|
||||
* association setup, an {@link AssociationChangeNotification
|
||||
* association changed} notification will be put to the SCTP stack with its
|
||||
* {@code event} parameter set to {@link
|
||||
* AssociationChangeNotification.AssocChangeEvent#COMM_UP
|
||||
* COMM_UP}. This notification can be received by invoking {@link #receive
|
||||
* receive}.
|
||||
*
|
||||
* <P> Socket options are configured using the
|
||||
* {@link #setOption(SctpSocketOption,Object,Association) setOption} method. An
|
||||
* {@code SctpMultiChannel} supports the following options:
|
||||
* <blockquote>
|
||||
* <table border summary="Socket options">
|
||||
* <tr>
|
||||
* <th>Option Name</th>
|
||||
* <th>Description</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_DISABLE_FRAGMENTS
|
||||
* SCTP_DISABLE_FRAGMENTS} </td>
|
||||
* <td> Enables or disables message fragmentation </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE
|
||||
* SCTP_EXPLICIT_COMPLETE} </td>
|
||||
* <td> Enables or disables explicit message completion </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE
|
||||
* SCTP_FRAGMENT_INTERLEAVE} </td>
|
||||
* <td> Controls how the presentation of messages occur for the message
|
||||
* receiver </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS
|
||||
* SCTP_INIT_MAXSTREAMS} </td>
|
||||
* <td> The maximum number of streams requested by the local endpoint during
|
||||
* association initialization </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_NODELAY SCTP_NODELAY} </td>
|
||||
* <td> Enables or disable a Nagle-like algorithm </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_PRIMARY_ADDR
|
||||
* SCTP_PRIMARY_ADDR} </td>
|
||||
* <td> Requests that the local SCTP stack use the given peer address as the
|
||||
* association primary </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_SET_PEER_PRIMARY_ADDR
|
||||
* SCTP_SET_PEER_PRIMARY_ADDR} </td>
|
||||
* <td> Requests that the peer mark the enclosed address as the association
|
||||
* primary </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SO_SNDBUF
|
||||
* SO_SNDBUF} </td>
|
||||
* <td> The size of the socket send buffer </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SO_RCVBUF
|
||||
* SO_RCVBUF} </td>
|
||||
* <td> The size of the socket receive buffer </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SO_LINGER
|
||||
* SO_LINGER} </td>
|
||||
* <td> Linger on close if data is present (when configured in blocking mode
|
||||
* only) </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
* Additional (implementation specific) options may also be supported. The list
|
||||
* of options supported is obtained by invoking the {@link #supportedOptions()
|
||||
* supportedOptions} method.
|
||||
*
|
||||
* <p> SCTP multi channels are safe for use by multiple concurrent threads.
|
||||
* They support concurrent sending and receiving, though at most one thread may be
|
||||
* sending and at most one thread may be receiving at any given time.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class SctpMultiChannel
|
||||
extends AbstractSelectableChannel
|
||||
{
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*
|
||||
* @param provider
|
||||
* The selector provider for this channel
|
||||
*/
|
||||
protected SctpMultiChannel(SelectorProvider provider) {
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an SCTP multi channel.
|
||||
*
|
||||
* <P> The new channel is unbound.
|
||||
*
|
||||
* @return A new SCTP multi channel
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the SCTP protocol is not supported
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static SctpMultiChannel open() throws
|
||||
IOException {
|
||||
return new sun.nio.ch.sctp.SctpMultiChannelImpl((SelectorProvider)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the open associations on this channel's socket.
|
||||
*
|
||||
* <P> Only associations whose {@link AssociationChangeNotification.AssocChangeEvent#COMM_UP
|
||||
* COMM_UP} association change event has been received are included
|
||||
* in the returned set of associations. Associations for which a
|
||||
* {@link AssociationChangeNotification.AssocChangeEvent#COMM_LOST COMM_LOST} or {@link
|
||||
* AssociationChangeNotification.AssocChangeEvent#SHUTDOWN SHUTDOWN} association change
|
||||
* event have been receive are removed from the set of associations.
|
||||
*
|
||||
* <P> The returned set of associations is a snapshot of the open
|
||||
* associations at the time that this method is invoked.
|
||||
*
|
||||
* @return A {@code Set} containing the open associations, or an empty
|
||||
* {@code Set} if there are none.
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract Set<Association> associations()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Binds the channel's socket to a local address and configures the socket
|
||||
* to listen for connections.
|
||||
*
|
||||
* <P> This method is used to establish a relationship between the socket
|
||||
* and the local address. Once a relationship is established then
|
||||
* the socket remains bound until the channel is closed. This relationship
|
||||
* may not necesssarily be with the address {@code local} as it may be removed
|
||||
* by {@link #unbindAddress unbindAddress}, but there will always be at least one local
|
||||
* address bound to the channel's socket once an invocation of this method
|
||||
* successfully completes.
|
||||
*
|
||||
* <P> Once the channel's socket has been successfully bound to a specific
|
||||
* address, that is not automatically assigned, more addresses
|
||||
* may be bound to it using {@link #bindAddress bindAddress}, or removed
|
||||
* using {@link #unbindAddress unbindAddress}.
|
||||
*
|
||||
* <P> The backlog parameter is the maximum number of pending connections on
|
||||
* the socket. Its exact semantics are implementation specific. An implementation
|
||||
* may impose an implementation specific maximum length or may choose to ignore
|
||||
* the parameter. If the backlog parameter has the value {@code 0}, or a negative
|
||||
* value, then an implementation specific default is used.
|
||||
*
|
||||
* @param local
|
||||
* The local address to bind the socket, or {@code null} to
|
||||
* bind the socket to an automatically assigned socket address
|
||||
*
|
||||
* @param backlog
|
||||
* The maximum number number of pending connections
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and its {@link
|
||||
* java.lang.SecurityManager#checkListen(int) checkListen} method
|
||||
* denies the operation
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpMultiChannel bind(SocketAddress local,
|
||||
int backlog)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Binds the channel's socket to a local address and configures the socket
|
||||
* to listen for connections.
|
||||
*
|
||||
* <P> This method works as if invoking it were equivalent to evaluating the
|
||||
* expression:
|
||||
* <blockquote><pre>
|
||||
* bind(local, 0);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param local
|
||||
* The local address to bind the socket, or {@code null} to
|
||||
* bind the socket to an automatically assigned socket address
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and its {@link
|
||||
* java.lang.SecurityManager#checkListen(int) checkListen} method
|
||||
* denies the operation
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public final SctpMultiChannel bind(SocketAddress local)
|
||||
throws IOException {
|
||||
return bind(local, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given address to the bound addresses for the channel's
|
||||
* socket.
|
||||
*
|
||||
* <P> The given address must not be the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address.
|
||||
* The channel must be first bound using {@link #bind bind} before
|
||||
* invoking this method, otherwise {@link NotYetBoundException} is thrown.
|
||||
* The {@link #bind bind} method takes a {@code SocketAddress} as its
|
||||
* argument which typically contains a port number as well as an address.
|
||||
* Addresses subquently bound using this method are simply addresses as the
|
||||
* SCTP port number remains the same for the lifetime of the channel.
|
||||
*
|
||||
* <P> New associations setup after this method successfully completes
|
||||
* will be associated with the given address. Adding addresses to existing
|
||||
* associations is optional functionality. If the endpoint supports
|
||||
* dynamic address reconfiguration then it may send the appropriate message
|
||||
* to the peer to change the peers address lists.
|
||||
*
|
||||
* @param address
|
||||
* The address to add to the bound addresses for the socket
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound to the given address
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If address is {@code null} or the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpMultiChannel bindAddress(InetAddress address)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Removes the given address from the bound addresses for the channel's
|
||||
* socket.
|
||||
*
|
||||
* <P> The given address must not be the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address.
|
||||
* The channel must be first bound using {@link #bind bind} before
|
||||
* invoking this method, otherwise {@link NotYetBoundException} is thrown.
|
||||
*
|
||||
* <P> If this method is invoked on a channel that does
|
||||
* not have {@code address} as one of its bound addresses, or that has only
|
||||
* one local address bound to it, then this method throws
|
||||
* {@link IllegalUnbindException}.
|
||||
*
|
||||
* <P> The initial address that the channel's socket is bound to using
|
||||
* {@link #bind bind} may be removed from the bound addresses for the
|
||||
* channel's socket.
|
||||
*
|
||||
* <P> New associations setup after this method successfully completes
|
||||
* will not be associated with the given address. Removing addresses from
|
||||
* existing associations is optional functionality. If the endpoint supports
|
||||
* dynamic address reconfiguration then it may send the appropriate message
|
||||
* to the peer to change the peers address lists.
|
||||
*
|
||||
* @param address
|
||||
* The address to remove from the bound addresses for the socket
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws IllegalUnbindException
|
||||
* {@code address} is not bound to the channel's socket, or the
|
||||
* channel has only one address bound to it
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If address is {@code null} or the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpMultiChannel unbindAddress(InetAddress address)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns all of the socket addresses to which this channel's socket is
|
||||
* bound.
|
||||
*
|
||||
* @return All the socket addresses that this channel's socket is
|
||||
* bound to, or an empty {@code Set} if the channel's socket is not
|
||||
* bound
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If the channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public abstract Set<SocketAddress> getAllLocalAddresses()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns all of the remote addresses to which the given association on
|
||||
* this channel's socket is connected.
|
||||
*
|
||||
* @param association
|
||||
* The association
|
||||
*
|
||||
* @return All of the remote addresses for the given association, or
|
||||
* an empty {@code Set} if the association has been shutdown
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If the channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public abstract Set<SocketAddress> getRemoteAddresses(Association association)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Shutdown an association without closing the channel.
|
||||
*
|
||||
* @param association
|
||||
* The association to shutdown
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpMultiChannel shutdown(Association association)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the value of a socket option.
|
||||
*
|
||||
* <P> Note that some options are retrieved on the channel's socket,
|
||||
* therefore the {@code association} parameter is not applicable and will be
|
||||
* ignored if given. However, if the option is association specific then the
|
||||
* association must be given.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the socket option value
|
||||
*
|
||||
* @param name
|
||||
* The socket option
|
||||
*
|
||||
* @param association
|
||||
* The association whose option should be retrieved, or {@code null}
|
||||
* if this option should be retrieved at the channel's socket level.
|
||||
*
|
||||
* @return The value of the socket option. A value of {@code null} may be
|
||||
* a valid value for some socket options.
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the socket option is not supported by this channel
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
public abstract <T> T getOption(SctpSocketOption<T> name,
|
||||
Association association)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the value of a socket option.
|
||||
*
|
||||
* <P> Note that some options are retrieved on the channel's socket,
|
||||
* therefore the {@code association} parameter is not applicable and will be
|
||||
* ignored if given. However, if the option is association specific then the
|
||||
* association must be given.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the socket option value
|
||||
*
|
||||
* @param name
|
||||
* The socket option
|
||||
*
|
||||
* @param association
|
||||
* The association whose option should be set, or {@code null}
|
||||
* if this option should be set at the channel's socket level.
|
||||
*
|
||||
* @param value
|
||||
* The value of the socket option. A value of {@code null} may be
|
||||
* a valid value for some socket options.
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the socket option is not supported by this channel
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the value is not a valid value for this socket option
|
||||
*
|
||||
* @throws ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
public abstract <T> SctpMultiChannel setOption(SctpSocketOption<T> name,
|
||||
T value,
|
||||
Association association)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a set of the socket options supported by this channel.
|
||||
*
|
||||
* <P> This method will continue to return the set of options even after the
|
||||
* channel has been closed.
|
||||
*
|
||||
* @return A set of the socket options supported by this channel
|
||||
*/
|
||||
public abstract Set<SctpSocketOption<?>> supportedOptions();
|
||||
|
||||
/**
|
||||
* Returns an operation set identifying this channel's supported operations.
|
||||
*
|
||||
* <P> SCTP multi channels support reading, and writing, so this
|
||||
* method returns
|
||||
* {@code (}{@link SelectionKey#OP_READ} {@code |} {@link
|
||||
* SelectionKey#OP_WRITE}{@code )}. </p>
|
||||
*
|
||||
* @return The valid-operation set
|
||||
*/
|
||||
@Override
|
||||
public final int validOps() {
|
||||
return (SelectionKey.OP_READ |
|
||||
SelectionKey.OP_WRITE );
|
||||
}
|
||||
|
||||
/**
|
||||
* Receives a message and/or handles a notification via this channel.
|
||||
*
|
||||
* <P> If a message or notification is immediately available, or if this
|
||||
* channel is in blocking mode and one eventually becomes available, then
|
||||
* the message or notification is returned or handled, respectively. If this
|
||||
* channel is in non-blocking mode and a message or notification is not
|
||||
* immediately available then this method immediately returns {@code null}.
|
||||
*
|
||||
* <P> If this method receives a message it is copied into the given byte
|
||||
* buffer and an {@link MessageInfo} is returned.
|
||||
* The message is transferred into the given byte buffer starting at its
|
||||
* current position and the buffers position is incremented by the number of
|
||||
* bytes read. If there are fewer bytes remaining in the buffer than are
|
||||
* required to hold the message, or the underlying input buffer does not
|
||||
* contain the complete message, then an invocation of {@link
|
||||
* MessageInfo#isComplete isComplete} on the returned {@code
|
||||
* MessageInfo} will return {@code false}, and more invocations of this
|
||||
* method will be necessary to completely consume the messgae. Only
|
||||
* one message at a time will be partially delivered in any stream. The
|
||||
* socket option {@link SctpStandardSocketOptions#SCTP_FRAGMENT_INTERLEAVE
|
||||
* SCTP_FRAGMENT_INTERLEAVE} controls various aspects of what interlacing of
|
||||
* messages occurs.
|
||||
*
|
||||
* <P> If this method receives a notification then the appropriate method of
|
||||
* the given handler, if there is one, is invoked. If the handler returns {@link
|
||||
* HandlerResult#CONTINUE CONTINUE} then this method will try to receive another
|
||||
* message/notification, otherwise, if {@link HandlerResult#RETURN RETURN} is returned
|
||||
* this method will return {@code null}. If an uncaught exception is thrown by the
|
||||
* handler it will be propagated up the stack through this method.
|
||||
*
|
||||
* <P> If a security manager has been installed then for each new association
|
||||
* setup this method verifies that the associations source address and port
|
||||
* number are permitted by the security manager's {@link
|
||||
* java.lang.SecurityManager#checkAccept(String,int) checkAccept} method.
|
||||
*
|
||||
* <P> This method may be invoked at any time. If another thread has
|
||||
* already initiated a receive operation upon this channel, then an
|
||||
* invocation of this method will block until the first operation is
|
||||
* complete. The given handler is invoked without holding any locks used
|
||||
* to enforce the above synchronization policy, that way handlers
|
||||
* will not stall other threads from receiving. A handler should not invoke
|
||||
* the {@code receive} method of this channel, if it does an
|
||||
* {@link IllegalReceiveException} will be thrown.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the attachment
|
||||
*
|
||||
* @param buffer
|
||||
* The buffer into which bytes are to be transferred
|
||||
*
|
||||
* @param attachment
|
||||
* The object to attach to the receive operation; can be
|
||||
* {@code null}
|
||||
*
|
||||
* @param handler
|
||||
* A handler to handle notifications from the SCTP stack, or
|
||||
* {@code null} to ignore any notifications.
|
||||
*
|
||||
* @return The {@code MessageInfo}, {@code null} if this channel is in
|
||||
* non-blocking mode and no messages are immediately available or
|
||||
* the notification handler returns {@code RETURN} after handling
|
||||
* a notification
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the read operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the read operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws IllegalReceiveException
|
||||
* If the given handler invokes the {@code receive} method of this
|
||||
* channel
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and it does not permit
|
||||
* new associations to be accepted from the message's sender
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract <T> MessageInfo receive(ByteBuffer buffer,
|
||||
T attachment,
|
||||
NotificationHandler<T> handler)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Sends a message via this channel.
|
||||
*
|
||||
* <P> If this channel is unbound then this method will invoke {@link
|
||||
* #bind(SocketAddress, int) bind(null, 0)} before sending any data.
|
||||
*
|
||||
* <P> If there is no association existing between this channel's socket
|
||||
* and the intended receiver, identified by the address in the given messageInfo, then one
|
||||
* will be automatically setup to the intended receiver. This is considered
|
||||
* to be Implicit Association Setup. Upon successful association setup, an
|
||||
* {@link AssociationChangeNotification association changed}
|
||||
* notification will be put to the SCTP stack with its {@code event} parameter set
|
||||
* to {@link AssociationChangeNotification.AssocChangeEvent#COMM_UP COMM_UP}
|
||||
* . This notification can be received by invoking {@link #receive
|
||||
* receive}.
|
||||
*
|
||||
* <P> If this channel is in blocking mode, there is sufficient room in the
|
||||
* underlying output buffer, then the remaining bytes in the given byte
|
||||
* buffer are transmitted as a single message. Sending a message
|
||||
* is atomic unless explicit message completion {@link
|
||||
* SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE SCTP_EXPLICIT_COMPLETE}
|
||||
* socket option is enabled on this channel's socket.
|
||||
*
|
||||
* <P> If this channel is in non-blocking mode, there is sufficient room
|
||||
* in the underlying output buffer, and an implicit association setup is
|
||||
* required, then the remaining bytes in the given byte buffer are
|
||||
* transmitted as a single message, subject to {@link
|
||||
* SctpStandardSocketOptions#SCTP_EXPLICIT_COMPLETE SCTP_EXPLICIT_COMPLETE}.
|
||||
* If for any reason the message cannot
|
||||
* be delivered an {@link AssociationChangeNotification association
|
||||
* changed} notification is put on the SCTP stack with its {@code event} parameter set
|
||||
* to {@link AssociationChangeNotification.AssocChangeEvent#CANT_START CANT_START}.
|
||||
*
|
||||
* <P> The message is transferred from the byte buffer as if by a regular
|
||||
* {@link java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)
|
||||
* write} operation.
|
||||
*
|
||||
* <P> If a security manager has been installed then for each new association
|
||||
* setup this method verifies that the given remote peers address and port
|
||||
* number are permitted by the security manager's {@link
|
||||
* java.lang.SecurityManager#checkConnect(String,int) checkConnect} method.
|
||||
*
|
||||
* <P> This method may be invoked at any time. If another thread has already
|
||||
* initiated a send operation upon this channel, then an invocation of
|
||||
* this method will block until the first operation is complete.
|
||||
*
|
||||
* @param buffer
|
||||
* The buffer containing the message to be sent
|
||||
*
|
||||
* @param messageInfo
|
||||
* Ancillary data about the message to be sent
|
||||
*
|
||||
* @return The number of bytes sent, which will be either the number of
|
||||
* bytes that were remaining in the messages buffer when this method
|
||||
* was invoked or, if this channel is non-blocking, may be zero if
|
||||
* there was insufficient room for the message in the underlying
|
||||
* output buffer
|
||||
*
|
||||
* @throws InvalidStreamException
|
||||
* If {@code streamNumber} is negative, or if an association already
|
||||
* exists and {@code streamNumber} is greater than the maximum number
|
||||
* of outgoing streams
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the read operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the read operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and it does not permit
|
||||
* new associations to be setup with the the messages's address
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract int send(ByteBuffer buffer, MessageInfo messageInfo)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Branches off an association.
|
||||
*
|
||||
* <P> An application can invoke this method to branch off an association
|
||||
* into a separate channel. The new bound and connected {@link SctpChannel}
|
||||
* will be created for the association. The branched off association will no
|
||||
* longer be part of this channel.
|
||||
*
|
||||
* <P> This is particularly useful when, for instance, the application
|
||||
* wishes to have a number of sporadic message senders/receivers remain
|
||||
* under the original SCTP multi channel but branch off those
|
||||
* associations carrying high volume data traffic into their own
|
||||
* separate SCTP channels.
|
||||
*
|
||||
* @param association
|
||||
* The association to branch off
|
||||
*
|
||||
* @return The {@code SctpChannel}
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpChannel branch(Association association)
|
||||
throws IOException;
|
||||
}
|
||||
428
jdkSrc/jdk8/com/sun/nio/sctp/SctpServerChannel.java
Normal file
428
jdkSrc/jdk8/com/sun/nio/sctp/SctpServerChannel.java
Normal file
@@ -0,0 +1,428 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.net.InetAddress;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
import java.nio.channels.spi.AbstractSelectableChannel;
|
||||
|
||||
/**
|
||||
* A selectable channel for message-oriented listening SCTP sockets.
|
||||
*
|
||||
* <p> An {@code SCTPServerChannel} is created by invoking the
|
||||
* {@link #open open} method of this class. A newly-created SCTP server
|
||||
* channel is open but not yet bound. An attempt to invoke the
|
||||
* {@link #accept accept} method of an unbound channel will cause the
|
||||
* {@link java.nio.channels.NotYetBoundException} to be thrown. An SCTP server
|
||||
* channel can be bound by invoking one of the
|
||||
* {@link #bind(java.net.SocketAddress,int) bind} methods defined by this class.
|
||||
*
|
||||
* <p> Socket options are configured using the
|
||||
* {@link #setOption(SctpSocketOption,Object) setOption} method. SCTP server socket
|
||||
* channels support the following options:
|
||||
* <blockquote>
|
||||
* <table border summary="Socket options">
|
||||
* <tr>
|
||||
* <th>Option Name</th>
|
||||
* <th>Description</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td> {@link SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS
|
||||
* SCTP_INIT_MAXSTREAMS} </td>
|
||||
* <td> The maximum number of streams requested by the local endpoint during
|
||||
* association initialization </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </blockquote>
|
||||
* Additional (implementation specific) options may also be supported. The list
|
||||
* of options supported is obtained by invoking the {@link #supportedOptions()
|
||||
* supportedOptions} method.
|
||||
*
|
||||
* <p>SCTP server channels are safe for use by multiple concurrent threads.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class SctpServerChannel
|
||||
extends AbstractSelectableChannel
|
||||
{
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*
|
||||
* @param provider
|
||||
* The selector provider for this channel
|
||||
*/
|
||||
protected SctpServerChannel(SelectorProvider provider) {
|
||||
super(provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens an SCTP server channel.
|
||||
*
|
||||
* <P> The new channel's socket is initially unbound; it must be bound
|
||||
* to a specific address via one of its socket's {@link #bind bind}
|
||||
* methods before associations can be accepted.
|
||||
*
|
||||
* @return A new SCTP server channel
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the SCTP protocol is not supported
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public static SctpServerChannel open() throws
|
||||
IOException {
|
||||
return new sun.nio.ch.sctp.SctpServerChannelImpl((SelectorProvider)null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an association on this channel's socket.
|
||||
*
|
||||
* <P> If this channel is in non-blocking mode then this method will
|
||||
* immediately return {@code null} if there are no pending associations.
|
||||
* Otherwise it will block indefinitely until a new association is
|
||||
* available or an I/O error occurs.
|
||||
*
|
||||
* <P> The {@code SCTPChannel} returned by this method, if any, will be in
|
||||
* blocking mode regardless of the blocking mode of this channel.
|
||||
*
|
||||
* <P> If a security manager has been installed then for each new
|
||||
* association this method verifies that the address and port number of the
|
||||
* assocaitions's remote peer are permitted by the security manager's {@link
|
||||
* java.lang.SecurityManager#checkAccept(String,int) checkAccept} method.
|
||||
*
|
||||
* @return The SCTP channel for the new association, or {@code null}
|
||||
* if this channel is in non-blocking mode and no association is
|
||||
* available to be accepted
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AsynchronousCloseException
|
||||
* If another thread closes this channel
|
||||
* while the accept operation is in progress
|
||||
*
|
||||
* @throws java.nio.channels.ClosedByInterruptException
|
||||
* If another thread interrupts the current thread
|
||||
* while the accept operation is in progress, thereby
|
||||
* closing the channel and setting the current thread's
|
||||
* interrupt status
|
||||
*
|
||||
* @throws java.nio.channels.NotYetBoundException
|
||||
* If this channel's socket has not yet been bound
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and it does not permit
|
||||
* access to the remote peer of the new association
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpChannel accept() throws IOException;
|
||||
|
||||
/**
|
||||
* Binds the channel's socket to a local address and configures the socket
|
||||
* to listen for associations.
|
||||
*
|
||||
* <P> This method works as if invoking it were equivalent to evaluating the
|
||||
* expression:
|
||||
* <blockquote><pre>
|
||||
* bind(local, 0);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* @param local
|
||||
* The local address to bind the socket, or {@code null} to
|
||||
* bind the socket to an automatically assigned socket address
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and its {@link
|
||||
* java.lang.SecurityManager#checkListen(int) checkListen} method
|
||||
* denies the operation
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public final SctpServerChannel bind(SocketAddress local)
|
||||
throws IOException {
|
||||
return bind(local, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds the channel's socket to a local address and configures the socket
|
||||
* to listen for associations.
|
||||
*
|
||||
* <P> This method is used to establish a relationship between the socket
|
||||
* and the local address. Once a relationship is established then
|
||||
* the socket remains bound until the channel is closed. This relationship
|
||||
* may not necesssarily be with the address {@code local} as it may be
|
||||
* removed by {@link #unbindAddress unbindAddress}, but there will always be
|
||||
* at least one local address bound to the channel's socket once an
|
||||
* invocation of this method successfully completes.
|
||||
*
|
||||
* <P> Once the channel's socket has been successfully bound to a specific
|
||||
* address, that is not automatically assigned, more addresses
|
||||
* may be bound to it using {@link #bindAddress bindAddress}, or removed
|
||||
* using {@link #unbindAddress unbindAddress}.
|
||||
*
|
||||
* <P> The backlog parameter is the maximum number of pending associations
|
||||
* on the socket. Its exact semantics are implementation specific. An
|
||||
* implementation may impose an implementation specific maximum length or
|
||||
* may choose to ignore the parameter. If the backlog parameter has the
|
||||
* value {@code 0}, or a negative value, then an implementation specific
|
||||
* default is used.
|
||||
*
|
||||
* @param local
|
||||
* The local address to bind the socket, or {@code null} to
|
||||
* bind the socket to an automatically assigned socket address
|
||||
*
|
||||
* @param backlog
|
||||
* The maximum number number of pending associations
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound
|
||||
*
|
||||
* @throws java.nio.channels.UnsupportedAddressTypeException
|
||||
* If the type of the given address is not supported
|
||||
*
|
||||
* @throws SecurityException
|
||||
* If a security manager has been installed and its {@link
|
||||
* java.lang.SecurityManager#checkListen(int) checkListen} method
|
||||
* denies the operation
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpServerChannel bind(SocketAddress local,
|
||||
int backlog)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Adds the given address to the bound addresses for the channel's
|
||||
* socket.
|
||||
*
|
||||
* <P> The given address must not be the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address.
|
||||
* The channel must be first bound using {@link #bind bind} before
|
||||
* invoking this method, otherwise {@link
|
||||
* java.nio.channels.NotYetBoundException} is thrown. The {@link #bind bind}
|
||||
* method takes a {@code SocketAddress} as its argument which typically
|
||||
* contains a port number as well as an address. Addresses subquently bound
|
||||
* using this method are simply addresses as the SCTP port number remains
|
||||
* the same for the lifetime of the channel.
|
||||
*
|
||||
* <P> New associations accepted after this method successfully completes
|
||||
* will be associated with the given address.
|
||||
*
|
||||
* @param address
|
||||
* The address to add to the bound addresses for the socket
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws java.nio.channels.AlreadyBoundException
|
||||
* If this channel is already bound to the given address
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If address is {@code null} or the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpServerChannel bindAddress(InetAddress address)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Removes the given address from the bound addresses for the channel's
|
||||
* socket.
|
||||
*
|
||||
* <P> The given address must not be the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address.
|
||||
* The channel must be first bound using {@link #bind bind} before
|
||||
* invoking this method, otherwise
|
||||
* {@link java.nio.channels.NotYetBoundException} is thrown.
|
||||
* If this method is invoked on a channel that does not have
|
||||
* {@code address} as one of its bound addresses, or that has only one
|
||||
* local address bound to it, then this method throws {@link
|
||||
* IllegalUnbindException}.
|
||||
* The initial address that the channel's socket is bound to using
|
||||
* {@link #bind bind} may be removed from the bound addresses for the
|
||||
* channel's socket.
|
||||
*
|
||||
* <P> New associations accepted after this method successfully completes
|
||||
* will not be associated with the given address.
|
||||
*
|
||||
* @param address
|
||||
* The address to remove from the bound addresses for the socket
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws java.nio.channels.NotYetBoundException
|
||||
* If this channel is not yet bound
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If address is {@code null} or the {@link
|
||||
* java.net.InetAddress#isAnyLocalAddress wildcard} address
|
||||
*
|
||||
* @throws IllegalUnbindException
|
||||
* If the implementation does not support removing addresses from a
|
||||
* listening socket, {@code address} is not bound to the channel's
|
||||
* socket, or the channel has only one address bound to it
|
||||
*
|
||||
* @throws IOException
|
||||
* If some other I/O error occurs
|
||||
*/
|
||||
public abstract SctpServerChannel unbindAddress(InetAddress address)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns all of the socket addresses to which this channel's socket is
|
||||
* bound.
|
||||
*
|
||||
* @return All the socket addresses that this channel's socket is
|
||||
* bound to, or an empty {@code Set} if the channel's socket is not
|
||||
* bound
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If the channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*/
|
||||
public abstract Set<SocketAddress> getAllLocalAddresses()
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns the value of a socket option.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the socket option value
|
||||
*
|
||||
* @param name
|
||||
* The socket option
|
||||
*
|
||||
* @return The value of the socket option. A value of {@code null} may be
|
||||
* a valid value for some socket options.
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the socket option is not supported by this channel
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
public abstract <T> T getOption(SctpSocketOption<T> name) throws IOException;
|
||||
|
||||
/**
|
||||
* Sets the value of a socket option.
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the socket option value
|
||||
*
|
||||
* @param name
|
||||
* The socket option
|
||||
*
|
||||
* @param value
|
||||
* The value of the socket option. A value of {@code null} may be
|
||||
* a valid value for some socket options.
|
||||
*
|
||||
* @return This channel
|
||||
*
|
||||
* @throws UnsupportedOperationException
|
||||
* If the socket option is not supported by this channel
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If the value is not a valid value for this socket option
|
||||
*
|
||||
* @throws java.nio.channels.ClosedChannelException
|
||||
* If this channel is closed
|
||||
*
|
||||
* @throws IOException
|
||||
* If an I/O error occurs
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
public abstract <T> SctpServerChannel setOption(SctpSocketOption<T> name,
|
||||
T value)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a set of the socket options supported by this channel.
|
||||
*
|
||||
* <P> This method will continue to return the set of options even after the
|
||||
* channel has been closed.
|
||||
*
|
||||
* @return A set of the socket options supported by this channel
|
||||
*/
|
||||
public abstract Set<SctpSocketOption<?>> supportedOptions();
|
||||
|
||||
/**
|
||||
* Returns an operation set identifying this channel's supported
|
||||
* operations.
|
||||
*
|
||||
* <P> SCTP server channels only support the accepting of new
|
||||
* associations, so this method returns
|
||||
* {@link java.nio.channels.SelectionKey#OP_ACCEPT}.
|
||||
*
|
||||
* @return The valid-operation set
|
||||
*/
|
||||
@Override
|
||||
public final int validOps() {
|
||||
return SelectionKey.OP_ACCEPT;
|
||||
}
|
||||
}
|
||||
39
jdkSrc/jdk8/com/sun/nio/sctp/SctpSocketOption.java
Normal file
39
jdkSrc/jdk8/com/sun/nio/sctp/SctpSocketOption.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketOption;
|
||||
|
||||
/**
|
||||
* A socket option associated with an SCTP channel.
|
||||
*
|
||||
* @param <T> The type of the socket option value.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @see SctpStandardSocketOptions
|
||||
*/
|
||||
@jdk.Exported
|
||||
public interface SctpSocketOption<T> extends SocketOption<T> { }
|
||||
421
jdkSrc/jdk8/com/sun/nio/sctp/SctpStandardSocketOptions.java
Normal file
421
jdkSrc/jdk8/com/sun/nio/sctp/SctpStandardSocketOptions.java
Normal file
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import sun.nio.ch.sctp.SctpStdSocketOption;
|
||||
|
||||
/**
|
||||
* SCTP channels supports the socket options defined by this class
|
||||
* (as well as those listed in the particular channel class) and may support
|
||||
* additional Implementation specific socket options.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public class SctpStandardSocketOptions {
|
||||
private SctpStandardSocketOptions() {}
|
||||
/**
|
||||
* Enables or disables message fragmentation.
|
||||
*
|
||||
* <P> The value of this socket option is a {@code Boolean} that represents
|
||||
* whether the option is enabled or disabled. If enabled no SCTP message
|
||||
* fragmentation will be performed. Instead if a message being sent
|
||||
* exceeds the current PMTU size, the message will NOT be sent and
|
||||
* an error will be indicated to the user.
|
||||
*
|
||||
* <P> It is implementation specific whether or not this option is
|
||||
* supported.
|
||||
*/
|
||||
public static final SctpSocketOption<Boolean> SCTP_DISABLE_FRAGMENTS = new
|
||||
SctpStdSocketOption<Boolean>("SCTP_DISABLE_FRAGMENTS", Boolean.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_DISABLE_FRAGMENTS);
|
||||
|
||||
/**
|
||||
* Enables or disables explicit message completion.
|
||||
*
|
||||
* <p> The value of this socket option is a {@code Boolean} that represents
|
||||
* whether the option is enabled or disabled. When this option is enabled,
|
||||
* the {@code send} method may be invoked multiple times to a send message.
|
||||
* The {@code isComplete} parameter of the {@link MessageInfo} must only
|
||||
* be set to {@code true} for the final send to indicate that the message is
|
||||
* complete. If this option is disabled then each individual {@code send}
|
||||
* invocation is considered complete.
|
||||
*
|
||||
* <P> The default value of the option is {@code false} indicating that the
|
||||
* option is disabled. It is implementation specific whether or not this
|
||||
* option is supported.
|
||||
*/
|
||||
public static final SctpSocketOption<Boolean> SCTP_EXPLICIT_COMPLETE = new
|
||||
SctpStdSocketOption<Boolean>("SCTP_EXPLICIT_COMPLETE", Boolean.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_EXPLICIT_COMPLETE);
|
||||
|
||||
/**
|
||||
* Fragmented interleave controls how the presentation of messages occur
|
||||
* for the message receiver. There are three levels of fragment interleave
|
||||
* defined. Two of the levels effect {@link SctpChannel}, while
|
||||
* {@link SctpMultiChannel} is effected by all three levels.
|
||||
*
|
||||
* <P> This option takes an {@code Integer} value. It can be set to a value
|
||||
* of {@code 0}, {@code 1} or {@code 2}.
|
||||
*
|
||||
* <P> Setting the three levels provides the following receiver
|
||||
* interactions:
|
||||
*
|
||||
* <P> {@code level 0} - Prevents the interleaving of any messages. This
|
||||
* means that when a partial delivery begins, no other messages will be
|
||||
* received except the message being partially delivered. If another message
|
||||
* arrives on a different stream (or association) that could be delivered,
|
||||
* it will be blocked waiting for the user to read all of the partially
|
||||
* delivered message.
|
||||
*
|
||||
* <P> {@code level 1} - Allows interleaving of messages that are from
|
||||
* different associations. For {@code SctpChannel}, level 0 and
|
||||
* level 1 have the same meaning since an {@code SctpChannel} always
|
||||
* receives messages from the same association. Note that setting an {@code
|
||||
* SctpMultiChannel} to this level may cause multiple partial
|
||||
* delivers from different associations but for any given association, only
|
||||
* one message will be delivered until all parts of a message have been
|
||||
* delivered. This means that one large message, being read with an
|
||||
* association identification of "X", will block other messages from
|
||||
* association "X" from being delivered.
|
||||
*
|
||||
* <P> {@code level 2} - Allows complete interleaving of messages. This
|
||||
* level requires that the sender carefully observe not only the peer
|
||||
* {@code Association} but also must pay careful attention to the stream
|
||||
* number. With this option enabled a partially delivered message may begin
|
||||
* being delivered for association "X" stream "Y" and the next subsequent
|
||||
* receive may return a message from association "X" stream "Z". Note that
|
||||
* no other messages would be delivered for association "X" stream "Y"
|
||||
* until all of stream "Y"'s partially delivered message was read.
|
||||
* Note that this option effects both channel types. Also note that
|
||||
* for an {@code SctpMultiChannel} not only may another streams
|
||||
* message from the same association be delivered from the next receive,
|
||||
* some other associations message may be delivered upon the next receive.
|
||||
*
|
||||
* <P> It is implementation specific whether or not this option is
|
||||
* supported.
|
||||
*/
|
||||
public static final SctpSocketOption<Integer> SCTP_FRAGMENT_INTERLEAVE =
|
||||
new SctpStdSocketOption<Integer>("SCTP_FRAGMENT_INTERLEAVE",
|
||||
Integer.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_FRAGMENT_INTERLEAVE);
|
||||
|
||||
/**
|
||||
* The maximum number of streams requested by the local endpoint during
|
||||
* association initialization.
|
||||
*
|
||||
* <P> The value of this socket option is an {@link
|
||||
* SctpStandardSocketOptions.InitMaxStreams InitMaxStreams}, that represents
|
||||
* the maximum number of inbound and outbound streams that an association
|
||||
* on the channel is prepared to support.
|
||||
*
|
||||
* <P> For an {@link SctpChannel} this option may only be used to
|
||||
* change the number of inbound/outbound streams prior to connecting.
|
||||
*
|
||||
* <P> For an {@link SctpMultiChannel} this option determines
|
||||
* the maximum number of inbound/outbound streams new associations setup
|
||||
* on the channel will be prepared to support.
|
||||
*
|
||||
* <P> For an {@link SctpServerChannel} this option determines the
|
||||
* maximum number of inbound/outbound streams accepted sockets will
|
||||
* negotiate with their connecting peer.
|
||||
*
|
||||
* <P> In all cases the value set by this option is used in the negotiation
|
||||
* of new associations setup on the channel's socket and the actual
|
||||
* maximum number of inbound/outbound streams that have been negotiated
|
||||
* with the peer can be retrieved from the appropriate {@link
|
||||
* Association}. The {@code Association} can be retrieved from the
|
||||
* {@link AssociationChangeNotification.AssocChangeEvent#COMM_UP COMM_UP}
|
||||
* {@link AssociationChangeNotification} belonging to that association.
|
||||
*
|
||||
* <p> This value is bounded by the actual implementation. In other
|
||||
* words the user may be able to support more streams than the Operating
|
||||
* System. In such a case, the Operating System limit may override the
|
||||
* value requested by the user. The default value of 0 indicates to use
|
||||
* the endpoints default value.
|
||||
*/
|
||||
public static final SctpSocketOption
|
||||
<SctpStandardSocketOptions.InitMaxStreams> SCTP_INIT_MAXSTREAMS =
|
||||
new SctpStdSocketOption<SctpStandardSocketOptions.InitMaxStreams>(
|
||||
"SCTP_INIT_MAXSTREAMS", SctpStandardSocketOptions.InitMaxStreams.class);
|
||||
|
||||
/**
|
||||
* Enables or disables a Nagle-like algorithm.
|
||||
*
|
||||
* <P> The value of this socket option is a {@code Boolean} that represents
|
||||
* whether the option is enabled or disabled. SCTP uses an algorithm like
|
||||
* <em>The Nagle Algorithm</em> to coalesce short segments and
|
||||
* improve network efficiency.
|
||||
*/
|
||||
public static final SctpSocketOption<Boolean> SCTP_NODELAY =
|
||||
new SctpStdSocketOption<Boolean>("SCTP_NODELAY", Boolean.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SCTP_NODELAY);
|
||||
|
||||
/**
|
||||
* Requests that the local SCTP stack use the given peer address as
|
||||
* the association primary.
|
||||
*
|
||||
* <P> The value of this socket option is a {@code SocketAddress}
|
||||
* that represents the peer address that the local SCTP stack should use as
|
||||
* the association primary. The address must be one of the association
|
||||
* peer's addresses.
|
||||
*
|
||||
* <P> An {@code SctpMultiChannel} can control more than one
|
||||
* association, the association parameter must be given when setting or
|
||||
* retrieving this option.
|
||||
*
|
||||
* <P> Since {@code SctpChannel} only controls one association,
|
||||
* the association parameter is not required and this option can be
|
||||
* set or queried directly.
|
||||
*/
|
||||
public static final SctpSocketOption<SocketAddress> SCTP_PRIMARY_ADDR =
|
||||
new SctpStdSocketOption<SocketAddress>
|
||||
("SCTP_PRIMARY_ADDR", SocketAddress.class);
|
||||
|
||||
/**
|
||||
* Requests that the peer mark the enclosed address as the association
|
||||
* primary.
|
||||
*
|
||||
* <P> The value of this socket option is a {@code SocketAddress}
|
||||
* that represents the local address that the peer should use as its
|
||||
* primary address. The given address must be one of the association's
|
||||
* locally bound addresses.
|
||||
*
|
||||
* <P> An {@code SctpMultiChannel} can control more than one
|
||||
* association, the association parameter must be given when setting or
|
||||
* retrieving this option.
|
||||
*
|
||||
* <P> Since {@code SctpChannel} only controls one association,
|
||||
* the association parameter is not required and this option can be
|
||||
* queried directly.
|
||||
*
|
||||
* <P> Note, this is a set only option and cannot be retrieved by {@code
|
||||
* getOption}. It is implementation specific whether or not this
|
||||
* option is supported.
|
||||
*/
|
||||
public static final SctpSocketOption<SocketAddress> SCTP_SET_PEER_PRIMARY_ADDR =
|
||||
new SctpStdSocketOption<SocketAddress>
|
||||
("SCTP_SET_PEER_PRIMARY_ADDR", SocketAddress.class);
|
||||
|
||||
/**
|
||||
* The size of the socket send buffer.
|
||||
*
|
||||
* <p> The value of this socket option is an {@code Integer} that is the
|
||||
* size of the socket send buffer in bytes. The socket send buffer is an
|
||||
* output buffer used by the networking implementation. It may need to be
|
||||
* increased for high-volume connections. The value of the socket option is
|
||||
* a <em>hint</em> to the implementation to size the buffer and the actual
|
||||
* size may differ. The socket option can be queried to retrieve the actual
|
||||
* size.
|
||||
*
|
||||
* <p> For {@code SctpChannel}, this controls the amount of data
|
||||
* the SCTP stack may have waiting in internal buffers to be sent. This
|
||||
* option therefore bounds the maximum size of data that can be sent in a
|
||||
* single send call.
|
||||
*
|
||||
* <P> For {@code SctpMultiChannel}, the effect is the same as for {@code
|
||||
* SctpChannel}, except that it applies to all associations. The option
|
||||
* applies to each association's window size separately.
|
||||
*
|
||||
* <p> An implementation allows this socket option to be set before the
|
||||
* socket is bound or connected. Whether an implementation allows the
|
||||
* socket send buffer to be changed after the socket is bound is system
|
||||
* dependent.
|
||||
*/
|
||||
public static final SctpSocketOption<Integer> SO_SNDBUF =
|
||||
new SctpStdSocketOption<Integer>("SO_SNDBUF", Integer.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SO_SNDBUF);
|
||||
|
||||
/**
|
||||
* The size of the socket receive buffer.
|
||||
*
|
||||
* <P> The value of this socket option is an {@code Integer} that is the
|
||||
* size of the socket receive buffer in bytes. The socket receive buffer is
|
||||
* an input buffer used by the networking implementation. It may need to be
|
||||
* increased for high-volume connections or decreased to limit the possible
|
||||
* backlog of incoming data. The value of the socket option is a
|
||||
* <em>hint</em> to the implementation to size the buffer and the actual
|
||||
* size may differ.
|
||||
*
|
||||
* <P> For {@code SctpChannel}, this controls the receiver window size.
|
||||
*
|
||||
* <P> For {@code SctpMultiChannel}, the meaning is implementation
|
||||
* dependent. It might control the receive buffer for each association bound
|
||||
* to the socket descriptor or it might control the receive buffer for the
|
||||
* whole socket.
|
||||
*
|
||||
* <p> An implementation allows this socket option to be set before the
|
||||
* socket is bound or connected. Whether an implementation allows the
|
||||
* socket receive buffer to be changed after the socket is bound is system
|
||||
* dependent.
|
||||
*/
|
||||
public static final SctpSocketOption<Integer> SO_RCVBUF =
|
||||
new SctpStdSocketOption<Integer>("SO_RCVBUF", Integer.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SO_RCVBUF);
|
||||
|
||||
/**
|
||||
* Linger on close if data is present.
|
||||
*
|
||||
* <p> The value of this socket option is an {@code Integer} that controls
|
||||
* the action taken when unsent data is queued on the socket and a method
|
||||
* to close the socket is invoked. If the value of the socket option is zero
|
||||
* or greater, then it represents a timeout value, in seconds, known as the
|
||||
* <em>linger interval</em>. The linger interval is the timeout for the
|
||||
* {@code close} method to block while the operating system attempts to
|
||||
* transmit the unsent data or it decides that it is unable to transmit the
|
||||
* data. If the value of the socket option is less than zero then the option
|
||||
* is disabled. In that case the {@code close} method does not wait until
|
||||
* unsent data is transmitted; if possible the operating system will transmit
|
||||
* any unsent data before the connection is closed.
|
||||
*
|
||||
* <p> This socket option is intended for use with sockets that are configured
|
||||
* in {@link java.nio.channels.SelectableChannel#isBlocking() blocking} mode
|
||||
* only. The behavior of the {@code close} method when this option is
|
||||
* enabled on a non-blocking socket is not defined.
|
||||
*
|
||||
* <p> The initial value of this socket option is a negative value, meaning
|
||||
* that the option is disabled. The option may be enabled, or the linger
|
||||
* interval changed, at any time. The maximum value of the linger interval
|
||||
* is system dependent. Setting the linger interval to a value that is
|
||||
* greater than its maximum value causes the linger interval to be set to
|
||||
* its maximum value.
|
||||
*/
|
||||
public static final SctpSocketOption<Integer> SO_LINGER =
|
||||
new SctpStdSocketOption<Integer>("SO_LINGER", Integer.class,
|
||||
sun.nio.ch.sctp.SctpStdSocketOption.SO_LINGER);
|
||||
|
||||
/**
|
||||
* This class is used to set the maximum number of inbound/outbound streams
|
||||
* used by the local endpoint during association initialization. An
|
||||
* instance of this class is used to set the {@link
|
||||
* SctpStandardSocketOptions#SCTP_INIT_MAXSTREAMS SCTP_INIT_MAXSTREAMS}
|
||||
* socket option.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public static class InitMaxStreams {
|
||||
private int maxInStreams;
|
||||
private int maxOutStreams;
|
||||
|
||||
private InitMaxStreams(int maxInStreams, int maxOutStreams) {
|
||||
this.maxInStreams = maxInStreams;
|
||||
this.maxOutStreams = maxOutStreams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an InitMaxStreams instance.
|
||||
*
|
||||
* @param maxInStreams
|
||||
* The maximum number of inbound streams, where
|
||||
* {@code 0 <= maxInStreams <= 65536}
|
||||
*
|
||||
* @param maxOutStreams
|
||||
* The maximum number of outbound streams, where
|
||||
* {@code 0 <= maxOutStreams <= 65536}
|
||||
*
|
||||
* @return An {@code InitMaxStreams} instance
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* If an argument is outside of specified bounds
|
||||
*/
|
||||
public static InitMaxStreams create
|
||||
(int maxInStreams, int maxOutStreams) {
|
||||
if (maxOutStreams < 0 || maxOutStreams > 65535)
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid maxOutStreams value");
|
||||
if (maxInStreams < 0 || maxInStreams > 65535)
|
||||
throw new IllegalArgumentException(
|
||||
"Invalid maxInStreams value");
|
||||
|
||||
return new InitMaxStreams(maxInStreams, maxOutStreams);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of inbound streams.
|
||||
*
|
||||
* @return Maximum inbound streams
|
||||
*/
|
||||
public int maxInStreams() {
|
||||
return maxInStreams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of outbound streams.
|
||||
*
|
||||
* @return Maximum outbound streams
|
||||
*/
|
||||
public int maxOutStreams() {
|
||||
return maxOutStreams;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this init max streams, including
|
||||
* the maximum in and out bound streams.
|
||||
*
|
||||
* @return A string representation of this init max streams
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(super.toString()).append(" [");
|
||||
sb.append("maxInStreams:").append(maxInStreams);
|
||||
sb.append("maxOutStreams:").append(maxOutStreams).append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the specified object is another {@code InitMaxStreams}
|
||||
* instance with the same number of in and out bound streams.
|
||||
*
|
||||
* @param obj
|
||||
* The object to be compared with this init max streams
|
||||
*
|
||||
* @return true if the specified object is another
|
||||
* {@code InitMaxStreams} instance with the same number of in
|
||||
* and out bound streams
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj != null && obj instanceof InitMaxStreams) {
|
||||
InitMaxStreams that = (InitMaxStreams) obj;
|
||||
if (this.maxInStreams == that.maxInStreams &&
|
||||
this.maxOutStreams == that.maxOutStreams)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hash code value for this init max streams.
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7 ^ maxInStreams ^ maxOutStreams;
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
90
jdkSrc/jdk8/com/sun/nio/sctp/SendFailedNotification.java
Normal file
90
jdkSrc/jdk8/com/sun/nio/sctp/SendFailedNotification.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
/**
|
||||
* Notification emitted when a send failed notification has been received.
|
||||
*
|
||||
* <P> A send failed notification indicates that a message cannot be delivered.
|
||||
* Typically this is because the association has been shutdown with unsent data
|
||||
* in the socket output buffer, or in the case of a {@link SctpMultiChannel}
|
||||
* the association failed to setup.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class SendFailedNotification implements Notification {
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected SendFailedNotification() {}
|
||||
|
||||
/**
|
||||
* Returns the association that this notification is applicable to.
|
||||
*
|
||||
* @return The association that failed to send, or {@code null} if
|
||||
* there is no association, that is, the notification follows a
|
||||
* {@linkplain
|
||||
* com.sun.nio.sctp.AssociationChangeNotification.AssocChangeEvent#CANT_START}
|
||||
*/
|
||||
@Override
|
||||
public abstract Association association();
|
||||
|
||||
/**
|
||||
* Returns the address.
|
||||
*
|
||||
* @return The peer primary address of the association or the address that
|
||||
* the message was sent to
|
||||
*/
|
||||
public abstract SocketAddress address();
|
||||
|
||||
/**
|
||||
* Returns the data that was to be sent.
|
||||
*
|
||||
* @return The user data. The buffers position will be {@code 0} and its
|
||||
* limit will be set to the end of the data.
|
||||
*/
|
||||
public abstract ByteBuffer buffer();
|
||||
|
||||
/**
|
||||
* Returns the error code.
|
||||
*
|
||||
* <P> The errorCode gives the reason why the send failed, and if set, will
|
||||
* be a SCTP protocol error code as defined in RFC2960 section 3.3.10
|
||||
*
|
||||
* @return The error code
|
||||
*/
|
||||
public abstract int errorCode();
|
||||
|
||||
/**
|
||||
* Returns the stream number that the messge was to be sent on.
|
||||
*
|
||||
* @return The stream number
|
||||
*/
|
||||
public abstract int streamNumber();
|
||||
}
|
||||
48
jdkSrc/jdk8/com/sun/nio/sctp/ShutdownNotification.java
Normal file
48
jdkSrc/jdk8/com/sun/nio/sctp/ShutdownNotification.java
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
package com.sun.nio.sctp;
|
||||
|
||||
/**
|
||||
* Notification emitted when a peers shutdowns an the association.
|
||||
*
|
||||
* <P> When a peer sends a <i>SHUTDOWN</i>, the SCTP stack delivers this
|
||||
* notification to inform the application that it should cease sending data.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
@jdk.Exported
|
||||
public abstract class ShutdownNotification implements Notification {
|
||||
/**
|
||||
* Initializes a new instance of this class.
|
||||
*/
|
||||
protected ShutdownNotification() {}
|
||||
|
||||
/**
|
||||
* Returns the association that this notification is applicable to.
|
||||
*
|
||||
* @return The association that received the shutdown
|
||||
*/
|
||||
public abstract Association association();
|
||||
}
|
||||
76
jdkSrc/jdk8/com/sun/nio/sctp/package-info.java
Normal file
76
jdkSrc/jdk8/com/sun/nio/sctp/package-info.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A Java API for Stream Control Transport Protocol.
|
||||
*
|
||||
* <P> The Stream Control Transport Protocol (SCTP) is a reliable,
|
||||
* message-oriented, transport protocol existing at an equivalent level with UDP
|
||||
* (User Datagram Protocol) and TCP (Transmission Control Protocol). SCTP is
|
||||
* session oriented and an association between the endpoints must be established
|
||||
* before any data can be transmitted.
|
||||
*
|
||||
* <P> SCTP has direct support for multi-homing, meaning than an endpoint may be
|
||||
* represented by more than one address and each address may be used for sending
|
||||
* and receiving data, thus providing network redundancy. The connection between
|
||||
* two endpoints is referred to as an association between those endpoints.
|
||||
* Endpoints can exchange a list of addresses during association setup. One
|
||||
* address is designated as the primary address, this is the default address that
|
||||
* the peer will use for sending data. A single port number is used across the
|
||||
* entire address list at an endpoint for a specific session.
|
||||
*
|
||||
* <P> SCTP is message based. I/O operations operate upon messages and message
|
||||
* boundaries are preserved. Each association may support multiple independant
|
||||
* logical streams. Each stream represents a sequence of messages within a single
|
||||
* association and streams are independant of one another, meaning that stream
|
||||
* identifiers and sequence numbers are included in the data packet to allow
|
||||
* sequencing of messages on a per-stream basis.
|
||||
*
|
||||
* <P> This package provides two programming model styles. The one-to-one style
|
||||
* supported by {@link com.sun.nio.sctp.SctpChannel} and {@link
|
||||
* com.sun.nio.sctp.SctpServerChannel}, and the one-to-many
|
||||
* style supported by {@link com.sun.nio.sctp.SctpMultiChannel}.
|
||||
* The semantics of the one-to-one style interface are very similar to TCP.
|
||||
* An {@code SctpChannel} can only control one SCTP association. The
|
||||
* semantics of the one-to-many style interface are very similar to UDP. An
|
||||
* {@code SctpMutliChannel} can control multiple SCTP associations.
|
||||
*
|
||||
* <P> Applications can send and receive per-message ancillary information through
|
||||
* {@link com.sun.nio.sctp.MessageInfo}. For example, the stream number that
|
||||
* the message it is to be sent or received from. The SCTP stack is event driven
|
||||
* and applications can receive notifications of certain SCTP events by invoking
|
||||
* the {@code receive} method of the SCTP channel with an appropriate {@link
|
||||
* com.sun.nio.sctp.NotificationHandler notification handler}.
|
||||
*
|
||||
* <P> The SCTP protocol is defined by
|
||||
* <A HREF="http://tools.ietf.org/html/rfc4960">RFC4960</A>, and the optional
|
||||
* extension for <I>Dynamic Address Reconfiguration</I> is defined by
|
||||
* <A HREF="http://tools.ietf.org/html/rfc5061">RFC5061</A>.
|
||||
*
|
||||
* @since 1.7
|
||||
*/
|
||||
|
||||
@jdk.Exported
|
||||
package com.sun.nio.sctp;
|
||||
Reference in New Issue
Block a user