提交 aabab279 编写于 作者: C chegar

4927640: Implementation of the sctp protocol

Summary: An implementation-specific API for the Stream Control Transmission Protocol
Reviewed-by: alanb, michaelm, jccollet
上级 6547cb86
......@@ -41,7 +41,7 @@ endif
# Omit mirror since it's built with the apt tool.
SUBDIRS = $(SCRIPT_SUBDIR) image security crypto/provider jndi jmx \
java inputmethods org xml rowset net/httpserver net/ssl demo \
tools jarsigner tracing servicetag
tools jarsigner tracing servicetag nio
all build clean clobber::
$(SUBDIRS-loop)
......
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
#
# Makefile for com.sun.nio packages.
#
BUILDDIR = ../../..
include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = sctp
all build clean clobber::
$(SUBDIRS-loop)
clean clobber::
$(RM) -r $(CLASSDESTDIR)/com/sun/nio
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
#
# These are the names of Java classes for which we will make .h files.
#
ifneq ($(PLATFORM), windows)
FILES_export = \
sun/nio/ch/SctpAssocChange.java \
sun/nio/ch/SctpChannelImpl.java \
sun/nio/ch/SctpNet.java \
sun/nio/ch/SctpPeerAddrChange.java \
sun/nio/ch/SctpResultContainer.java \
sun/nio/ch/SctpServerChannelImpl.java \
sun/nio/ch/SctpStdSocketOption.java
endif
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
ifneq ($(PLATFORM),windows)
FILES_c = \
SctpNet.c \
SctpChannelImpl.c \
SctpServerChannelImpl.c
endif
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
FILES_java = \
com/sun/nio/sctp/AbstractNotificationHandler.java \
com/sun/nio/sctp/Association.java \
com/sun/nio/sctp/AssociationChangeNotification.java \
com/sun/nio/sctp/HandlerResult.java \
com/sun/nio/sctp/IllegalReceiveException.java \
com/sun/nio/sctp/IllegalUnbindException.java \
com/sun/nio/sctp/InvalidStreamException.java \
com/sun/nio/sctp/MessageInfo.java \
com/sun/nio/sctp/Notification.java \
com/sun/nio/sctp/NotificationHandler.java \
com/sun/nio/sctp/PeerAddressChangeNotification.java \
com/sun/nio/sctp/SctpChannel.java \
com/sun/nio/sctp/SctpMultiChannel.java \
com/sun/nio/sctp/SctpServerChannel.java \
com/sun/nio/sctp/SctpSocketOption.java \
com/sun/nio/sctp/SctpStandardSocketOption.java \
com/sun/nio/sctp/SendFailedNotification.java \
com/sun/nio/sctp/ShutdownNotification.java \
\
sun/nio/ch/SctpMessageInfoImpl.java \
sun/nio/ch/SctpStdSocketOption.java
ifneq ($(PLATFORM), windows)
FILES_java += \
sun/nio/ch/SctpAssocChange.java \
sun/nio/ch/SctpAssociationImpl.java \
sun/nio/ch/SctpChannelImpl.java \
sun/nio/ch/SctpMultiChannelImpl.java \
sun/nio/ch/SctpNet.java \
sun/nio/ch/SctpNotification.java \
sun/nio/ch/SctpPeerAddrChange.java \
sun/nio/ch/SctpResultContainer.java \
sun/nio/ch/SctpSendFailed.java \
sun/nio/ch/SctpServerChannelImpl.java \
sun/nio/ch/SctpShutdown.java \
sun/nio/ch/SctpSocketDispatcher.java
else
FILES_java += \
sun/nio/ch/SctpChannelImpl.java \
sun/nio/ch/SctpMultiChannelImpl.java \
sun/nio/ch/SctpServerChannelImpl.java
endif
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
#
# Makefile for com.sun.nio.sctp
#
BUILDDIR = ../../../..
PACKAGE = com.sun.nio.sctp
LIBRARY = sctp
PRODUCT = sun
#OTHER_JAVACFLAGS += -Xmaxwarns 1000 -Xlint
include $(BUILDDIR)/common/Defs.gmk
#
# Files to compile
#
include FILES_c.gmk
include FILES_java.gmk
include Exportedfiles.gmk
ifneq ($(PLATFORM), windows)
include $(BUILDDIR)/common/Mapfile-vers.gmk
include $(BUILDDIR)/common/Library.gmk
#
# Find platform-specific C source files
#
vpath %.c $(PLATFORM_SRC)/native/sun/nio/ch
#
# Include nio.h, net_util.h, sun_nio_ch_IOStatus.h, etc
#
OTHER_INCLUDES += \
-I$(SHARE_SRC)/native/sun/nio/ch \
-I$(SHARE_SRC)/native/java/net \
-I$(PLATFORM_SRC)/native/java/net \
-I$(CLASSHDRDIR)/../../../../java/java.nio/nio/CClassHeaders
ifeq ($(PLATFORM), linux)
COMPILER_WARNINGS_FATAL=true
#OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread -ldl
OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -lnio -lnet -lpthread -ldl
endif
ifeq ($(PLATFORM), solaris)
#LIBSCTP = -lsctp
OTHER_LDLIBS += $(LIBSOCKET) -L$(LIBDIR)/$(LIBARCH) -lnet -lnio
endif # PLATFORM
else # windows
include $(BUILDDIR)/common/Classes.gmk
endif # ifneq windows
clean clobber::
$(RM) -r $(CLASSDESTDIR)/com/sun/nio/sctp
$(RM) -r $(CLASSDESTDIR)/sun/nio/ch
#
# Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
# particular file as subject to the "Classpath" exception as provided
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
SUNWprivate_1.1 {
global:
Java_sun_nio_ch_SctpNet_socket0;
Java_sun_nio_ch_SctpNet_bindx;
Java_sun_nio_ch_SctpNet_getLocalAddresses0;
Java_sun_nio_ch_SctpNet_getRemoteAddresses0;
Java_sun_nio_ch_SctpNet_getPrimAddrOption0;
Java_sun_nio_ch_SctpNet_setPrimAddrOption0;
Java_sun_nio_ch_SctpNet_setPeerPrimAddrOption0;
Java_sun_nio_ch_SctpNet_getInitMsgOption0;
Java_sun_nio_ch_SctpNet_setInitMsgOption0;
Java_sun_nio_ch_SctpNet_getIntOption0;
Java_sun_nio_ch_SctpNet_setIntOption0;
Java_sun_nio_ch_SctpNet_shutdown0;
Java_sun_nio_ch_SctpChannelImpl_initIDs;
Java_sun_nio_ch_SctpChannelImpl_checkConnect;
Java_sun_nio_ch_SctpChannelImpl_receive0;
Java_sun_nio_ch_SctpChannelImpl_send0;
Java_sun_nio_ch_SctpServerChannelImpl_initIDs;
Java_sun_nio_ch_SctpServerChannelImpl_accept0;
JNI_OnLoad;
local:
*;
};
......@@ -86,6 +86,8 @@ TREEAPI_PKGS = com.sun.source.tree \
SMARTCARDIO_PKGS = javax.smartcardio
SCTPAPI_PKGS = com.sun.nio.sctp
TRACING_PKGS = com.sun.tracing \
com.sun.tracing.dtrace
......@@ -98,4 +100,6 @@ NON_CORE_PKGS = $(DOMAPI_PKGS) \
$(OLD_JSSE_PKGS) \
$(HTTPSERVER_PKGS) \
$(SMARTCARDIO_PKGS) \
$(TRACING_PKGS)
$(TRACING_PKGS) \
$(SCTPAPI_PKGS)
......@@ -189,6 +189,7 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_UnixNativeDispatcher_getgrnam0;
Java_sun_nio_fs_UnixNativeDispatcher_getextmntent;
Java_sun_nio_fs_UnixCopyFile_transfer;
handleSocketError;
local:
*;
......
......@@ -175,6 +175,7 @@ SUNWprivate_1.1 {
Java_sun_nio_fs_SolarisWatchService_portDissociate;
Java_sun_nio_fs_SolarisWatchService_portSend;
Java_sun_nio_fs_SolarisWatchService_portGetn;
handleSocketError;
local:
*;
......
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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;
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
public class Association {
private final int associationID;
private final int maxInStreams;
private final int maxOutStreams;
/**
* Initializes a new instance of this class.
*/
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;
};
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
public abstract class AssociationChangeNotification
implements Notification
{
/**
* Defines the type of change event that happened to the association.
*
* @since 1.7
*/
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();
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
public enum HandlerResult {
/**
* Try to receieve another message or notification.
*/
CONTINUE,
/**
* Return without trying to receive any more data.
*/
RETURN;
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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.
*/
public IllegalReceiveException(String msg) {
super(msg);
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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.
*/
public IllegalUnbindException(String msg) {
super(msg);
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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.
*/
public InvalidStreamException(String msg) {
super(msg);
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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.SctpMessageInfoImpl(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.SctpMessageInfoImpl(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 SctpStandardSocketOption#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 SctpStandardSocketOption#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);
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
public interface Notification {
/**
* Returns the association that this notification is applicable to.
*/
public Association association();
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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);
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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
*/
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();
}
此差异已折叠。
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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>
* <tr>
* <th>Option Name</th>
* <th>Description</th>
* </tr>
* <tr>
* <td> {@link SctpStandardSocketOption#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
*/
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.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 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 SctpStandardSocketOption
*/
public abstract <T> T getOption(SctpSocketOption<T> name) throws IOException;
/**
* Sets the value of a socket option.
*
* @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 SctpStandardSocketOption
*/
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;
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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 SctpStandardSocketOption
*/
public interface SctpSocketOption<T> extends SocketOption<T> { }
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package com.sun.nio.sctp;
import java.net.SocketAddress;
import sun.nio.ch.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
*/
public class SctpStandardSocketOption {
private SctpStandardSocketOption() {}
/**
* 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.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.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.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
* SctpStandardSocketOption.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
<SctpStandardSocketOption.InitMaxStreams> SCTP_INIT_MAXSTREAMS =
new SctpStdSocketOption<SctpStandardSocketOption.InitMaxStreams>(
"SCTP_INIT_MAXSTREAMS", SctpStandardSocketOption.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.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.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.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.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
* SctpStandardSocketOption#SCTP_INIT_MAXSTREAMS SCTP_INIT_MAXSTREAMS}
* socket option.
*
* @since 1.7
*/
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;
}
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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();
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
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();
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.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
*/
package com.sun.nio.sctp;
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import java.net.SocketAddress;
import com.sun.nio.sctp.MessageInfo;
import com.sun.nio.sctp.Association;
/**
* An implementation of a MessageInfo.
*/
public class SctpMessageInfoImpl extends MessageInfo {
private final SocketAddress address;
private final int bytes; /* 0 */
private Association association;
private int assocId;
private int streamNumber;
private boolean complete = true;
private boolean unordered; /* false */
private long timeToLive; /* 0L */
private int ppid; /* 0 */
public SctpMessageInfoImpl(Association association,
SocketAddress address,
int streamNumber) {
this.association = association;
this.address = address;
this.streamNumber = streamNumber;
bytes = 0;
}
/* Invoked from native */
private SctpMessageInfoImpl(int assocId,
SocketAddress address,
int bytes,
int streamNumber,
boolean complete,
boolean unordered,
int ppid) {
this.assocId = assocId;
this.address = address;
this.bytes = bytes;
this.streamNumber = streamNumber;
this.complete = complete;
this.unordered = unordered;
this.ppid = ppid;
}
@Override
public Association association() {
return association;
}
/**
* SctpMessageInfoImpl instances created from native will need to have their
* association set from the channel.
*/
void setAssociation(Association association) {
this.association = association;
}
int associationID() {
return assocId;
}
@Override
public SocketAddress address() {
return address;
}
@Override
public int bytes() {
return bytes;
}
@Override
public int streamNumber() {
return streamNumber;
}
@Override
public MessageInfo streamNumber(int streamNumber) {
if (streamNumber < 0 || streamNumber > 65536)
throw new IllegalArgumentException("Invalid stream number");
this.streamNumber = streamNumber;
return this;
}
@Override
public int payloadProtocolID() {
return ppid;
}
@Override
public MessageInfo payloadProtocolID(int ppid) {
this.ppid = ppid;
return this;
}
@Override
public boolean isComplete() {
return complete;
}
@Override
public MessageInfo complete(boolean complete) {
this.complete = complete;
return this;
}
@Override
public boolean isUnordered() {
return unordered;
}
@Override
public MessageInfo unordered(boolean unordered) {
this.unordered = unordered;
return this;
}
@Override
public long timeToLive() {
return timeToLive;
}
@Override
public MessageInfo timeToLive(long millis) {
timeToLive = millis;
return this;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder(super.toString());
sb.append( "[Address: ").append(address)
.append(", Association: ").append(association)
.append(", Assoc ID: ").append(assocId)
.append(", Bytes: ").append(bytes)
.append(", Stream Number: ").append(streamNumber)
.append(", Complete: ").append(complete)
.append(", isUnordered: ").append(unordered)
.append("]");
return sb.toString();
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import com.sun.nio.sctp.SctpSocketOption;
public class SctpStdSocketOption<T>
implements SctpSocketOption<T>
{
/* for native mapping of int options */
public static final int SCTP_DISABLE_FRAGMENTS = 1;
public static final int SCTP_EXPLICIT_COMPLETE = 2;
public static final int SCTP_FRAGMENT_INTERLEAVE = 3;
public static final int SCTP_NODELAY = 4;
public static final int SO_SNDBUF = 5;
public static final int SO_RCVBUF = 6;
public static final int SO_LINGER = 7;
private final String name;
private final Class<T> type;
/* for native mapping of int options */
private int constValue;
public SctpStdSocketOption(String name, Class<T> type) {
this.name = name;
this.type = type;
}
public SctpStdSocketOption(String name, Class<T> type, int constValue) {
this.name = name;
this.type = type;
this.constValue = constValue;
}
@Override
public String name() {
return name;
}
@Override
public Class<T> type() {
return type;
}
@Override
public String toString() {
return name;
}
int constValue() {
return constValue;
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import com.sun.nio.sctp.Association;
import com.sun.nio.sctp.AssociationChangeNotification;
/**
* An implementation of AssociationChangeNotification
*/
public class SctpAssocChange extends AssociationChangeNotification
implements SctpNotification
{
/* static final ints so that they can be referenced from native */
private final static int SCTP_COMM_UP = 1;
private final static int SCTP_COMM_LOST = 2;
private final static int SCTP_RESTART = 3;
private final static int SCTP_SHUTDOWN = 4;
private final static int SCTP_CANT_START = 5;
private Association association;
/* assocId is used to lookup the association before the notification is
* returned to user code */
private int assocId;
private AssocChangeEvent event;
private int maxOutStreams;
private int maxInStreams;
/* Invoked from native */
private SctpAssocChange(int assocId,
int intEvent,
int maxOutStreams,
int maxInStreams) {
switch (intEvent) {
case SCTP_COMM_UP :
this.event = AssocChangeEvent.COMM_UP;
break;
case SCTP_COMM_LOST :
this.event = AssocChangeEvent.COMM_LOST;
break;
case SCTP_RESTART :
this.event = AssocChangeEvent.RESTART;
break;
case SCTP_SHUTDOWN :
this.event = AssocChangeEvent.SHUTDOWN;
break;
case SCTP_CANT_START :
this.event = AssocChangeEvent.CANT_START;
break;
default :
throw new AssertionError(
"Unknown Association Change Event type: " + intEvent);
}
this.assocId = assocId;
this.maxOutStreams = maxOutStreams;
this.maxInStreams = maxInStreams;
}
@Override
public int assocId() {
return assocId;
}
@Override
public void setAssociation(Association association) {
this.association = association;
}
@Override
public Association association() {
assert association != null;
return association;
}
@Override
public AssocChangeEvent event() {
return event;
}
int maxOutStreams() {
return maxOutStreams;
}
int maxInStreams() {
return maxInStreams;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString()).append(" [");
sb.append("Association:").append(association);
sb.append(", Event: ").append(event).append("]");
return sb.toString();
}
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import com.sun.nio.sctp.Association;
/**
* An implementation of Association
*/
public class SctpAssociationImpl extends Association {
public SctpAssociationImpl(int associationID,
int maxInStreams,
int maxOutStreams) {
super(associationID, maxInStreams, maxOutStreams);
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer(super.toString());
return sb.append("[associationID:")
.append(associationID())
.append(", maxIn:")
.append(maxInboundStreams())
.append(", maxOut:")
.append(maxOutboundStreams())
.append("]")
.toString();
}
}
此差异已折叠。
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import java.io.FileDescriptor;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.Set;
import java.util.HashSet;
import java.security.AccessController;
import sun.security.action.GetPropertyAction;
import com.sun.nio.sctp.SctpSocketOption;
import static com.sun.nio.sctp.SctpStandardSocketOption.*;
public class SctpNet {
static final String osName = AccessController.doPrivileged(
new GetPropertyAction("os.name"));
/* -- Miscellaneous SCTP utilities -- */
static boolean bindxIPv4MappedAddresses() {
if ("SunOS".equals(osName)) {
/* Solaris supports IPv4Mapped Addresses with bindx */
return true;
} /* else { //other OS/implementations */
/* lksctp/linux requires Ipv4 addresses */
return false;
}
/**
* @param oneToone
* if {@code true} returns a one-to-one sctp socket, otherwise
* returns a one-to-many sctp socket
*/
static FileDescriptor socket(boolean oneToOne) throws IOException {
int nativefd = socket0(oneToOne);
return IOUtil.newFD(nativefd);
}
static void bindx(int fd, InetAddress[] addrs, int port, boolean add)
throws IOException {
bindx(fd, addrs, port, addrs.length, add,
bindxIPv4MappedAddresses());
}
static Set<SocketAddress> getLocalAddresses(int fd)
throws IOException {
HashSet<SocketAddress> set = null;
SocketAddress[] saa = getLocalAddresses0(fd);
if (saa != null) {
set = new HashSet<SocketAddress>(saa.length);
for (SocketAddress sa : saa)
set.add(sa);
}
return set;
}
static Set<SocketAddress> getRemoteAddresses(int fd, int assocId)
throws IOException {
HashSet<SocketAddress> set = null;
SocketAddress[] saa = getRemoteAddresses0(fd, assocId);
if (saa != null) {
set = new HashSet<SocketAddress>(saa.length);
for (SocketAddress sa : saa)
set.add(sa);
}
return set;
}
static void setSocketOption(int fd,
SctpSocketOption name,
Object value,
int assocId)
throws IOException {
if (value == null)
throw new IllegalArgumentException("Invalid option value");
Class<?> type = name.type();
if (!type.isInstance(value))
throw new IllegalArgumentException("Invalid option value");
if (name.equals(SCTP_INIT_MAXSTREAMS)) {
InitMaxStreams maxStreamValue = (InitMaxStreams)value;
SctpNet.setInitMsgOption0(fd,
maxStreamValue.maxInStreams(), maxStreamValue.maxOutStreams());
} else if (name.equals(SCTP_PRIMARY_ADDR) ||
name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) {
SocketAddress addr = (SocketAddress) value;
if (addr == null)
throw new IllegalArgumentException("Invalid option value");
Net.checkAddress(addr);
InetSocketAddress netAddr = (InetSocketAddress)addr;
if (name.equals(SCTP_PRIMARY_ADDR)) {
setPrimAddrOption0(fd, assocId,
netAddr.getAddress(), netAddr.getPort());
} else {
setPeerPrimAddrOption0(fd, assocId,
netAddr.getAddress(), netAddr.getPort());
}
} else if (name.equals(SCTP_DISABLE_FRAGMENTS) ||
name.equals(SCTP_EXPLICIT_COMPLETE) ||
name.equals(SCTP_FRAGMENT_INTERLEAVE) ||
name.equals(SCTP_NODELAY) ||
name.equals(SO_SNDBUF) ||
name.equals(SO_RCVBUF) ||
name.equals(SO_LINGER)) {
setIntOption(fd, name, value);
} else {
throw new AssertionError("Unknown socket option");
}
}
static Object getSocketOption(int fd, SctpSocketOption name, int assocId)
throws IOException {
if (name.equals(SCTP_SET_PEER_PRIMARY_ADDR)) {
throw new IllegalArgumentException(
"SCTP_SET_PEER_PRIMARY_ADDR cannot be retrieved");
} else if (name.equals(SCTP_INIT_MAXSTREAMS)) {
/* container for holding maxIn/Out streams */
int[] values = new int[2];
SctpNet.getInitMsgOption0(fd, values);
return InitMaxStreams.create(values[0], values[1]);
} else if (name.equals(SCTP_PRIMARY_ADDR)) {
return getPrimAddrOption0(fd, assocId);
} else if (name.equals(SCTP_DISABLE_FRAGMENTS) ||
name.equals(SCTP_EXPLICIT_COMPLETE) ||
name.equals(SCTP_FRAGMENT_INTERLEAVE) ||
name.equals(SCTP_NODELAY) ||
name.equals(SO_SNDBUF) ||
name.equals(SO_RCVBUF) ||
name.equals(SO_LINGER)) {
return getIntOption(fd, name);
} else {
throw new AssertionError("Unknown socket option");
}
}
static void setIntOption(int fd, SctpSocketOption name, Object value)
throws IOException {
if (value == null)
throw new IllegalArgumentException("Invalid option value");
Class<?> type = name.type();
if (type != Integer.class && type != Boolean.class)
throw new AssertionError("Should not reach here");
if (name == SO_RCVBUF ||
name == SO_SNDBUF)
{
int i = ((Integer)value).intValue();
if (i < 0)
throw new IllegalArgumentException(
"Invalid send/receive buffer size");
} else if (name == SO_LINGER) {
int i = ((Integer)value).intValue();
if (i < 0)
value = Integer.valueOf(-1);
if (i > 65535)
value = Integer.valueOf(65535);
} else if (name.equals(SCTP_FRAGMENT_INTERLEAVE)) {
int i = ((Integer)value).intValue();
if (i < 0 || i > 2)
throw new IllegalArgumentException(
"Invalid value for SCTP_FRAGMENT_INTERLEAVE");
}
int arg;
if (type == Integer.class) {
arg = ((Integer)value).intValue();
} else {
boolean b = ((Boolean)value).booleanValue();
arg = (b) ? 1 : 0;
}
setIntOption0(fd, ((SctpStdSocketOption)name).constValue(), arg);
}
static Object getIntOption(int fd, SctpSocketOption name)
throws IOException {
Class<?> type = name.type();
if (type != Integer.class && type != Boolean.class)
throw new AssertionError("Should not reach here");
if (!(name instanceof SctpStdSocketOption))
throw new AssertionError("Should not reach here");
int value = getIntOption0(fd,
((SctpStdSocketOption)name).constValue());
if (type == Integer.class) {
return Integer.valueOf(value);
} else {
return (value == 0) ? Boolean.FALSE : Boolean.TRUE;
}
}
static void shutdown(int fd, int assocId)
throws IOException {
shutdown0(fd, assocId);
}
/* Native Methods */
static native int socket0(boolean oneToOne) throws IOException;
static native void bindx(int fd, InetAddress[] addrs, int port, int length,
boolean add, boolean preferIPv6) throws IOException;
static native int getIntOption0(int fd, int opt) throws IOException;
static native void setIntOption0(int fd, int opt, int arg)
throws IOException;
static native SocketAddress[] getLocalAddresses0(int fd) throws IOException;
static native SocketAddress[] getRemoteAddresses0(int fd, int assocId)
throws IOException;
static native void setPrimAddrOption0(int fd, int assocId, InetAddress ia,
int port) throws IOException;
static native void setPeerPrimAddrOption0(int fd, int assocId,
InetAddress ia, int port) throws IOException;
static native SocketAddress getPrimAddrOption0(int fd, int assocId)
throws IOException;
/* retVals [0] maxInStreams, [1] maxOutStreams */
static native void getInitMsgOption0(int fd, int[] retVals) throws IOException;
static native void setInitMsgOption0(int fd, int arg1, int arg2)
throws IOException;
static native void shutdown0(int fd, int assocId);
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import com.sun.nio.sctp.Association;
import com.sun.nio.sctp.Notification;
/**
* All Notification implemenations MUST implement this interface to provide
* access to the native association identidier.
*/
interface SctpNotification extends Notification {
int assocId();
void setAssociation(Association association);
}
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import java.net.SocketAddress;
import com.sun.nio.sctp.Association;
import com.sun.nio.sctp.PeerAddressChangeNotification;
/**
* An implementation of PeerAddressChangeNotification
*/
public class SctpPeerAddrChange extends PeerAddressChangeNotification
implements SctpNotification
{
/* static final ints so that they can be referenced from native */
private final static int SCTP_ADDR_AVAILABLE = 1;
private final static int SCTP_ADDR_UNREACHABLE = 2;
private final static int SCTP_ADDR_REMOVED = 3;
private final static int SCTP_ADDR_ADDED = 4;
private final static int SCTP_ADDR_MADE_PRIM = 5;
private final static int SCTP_ADDR_CONFIRMED =6;
private Association association;
/* assocId is used to lookup the association before the notification is
* returned to user code */
private int assocId;
private SocketAddress address;
private AddressChangeEvent event;
/* Invoked from native */
private SctpPeerAddrChange(int assocId, SocketAddress address, int intEvent) {
switch (intEvent) {
case SCTP_ADDR_AVAILABLE :
this.event = AddressChangeEvent.ADDR_AVAILABLE;
break;
case SCTP_ADDR_UNREACHABLE :
this.event = AddressChangeEvent.ADDR_UNREACHABLE;
break;
case SCTP_ADDR_REMOVED :
this.event = AddressChangeEvent.ADDR_REMOVED;
break;
case SCTP_ADDR_ADDED :
this.event = AddressChangeEvent.ADDR_ADDED;
break;
case SCTP_ADDR_MADE_PRIM :
this.event = AddressChangeEvent.ADDR_MADE_PRIMARY;
break;
case SCTP_ADDR_CONFIRMED :
this.event = AddressChangeEvent.ADDR_CONFIRMED;
break;
default:
throw new AssertionError("Unknown event type");
}
this.assocId = assocId;
this.address = address;
}
@Override
public int assocId() {
return assocId;
}
@Override
public void setAssociation(Association association) {
this.association = association;
}
@Override
public SocketAddress address() {
assert address != null;
return address;
}
@Override
public Association association() {
assert association != null;
return association;
}
@Override
public AddressChangeEvent event() {
assert event != null;
return event;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString()).append(" [");
sb.append("Address: ").append(address);
sb.append(", Association:").append(association);
sb.append(", Event: ").append(event).append("]");
return sb.toString();
}
}
此差异已折叠。
此差异已折叠。
/*
* Copyright 2009 Sun Microsystems, Inc. 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. Sun designates this
* particular file as subject to the "Classpath" exception as provided
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
package sun.nio.ch;
import com.sun.nio.sctp.Association;
import com.sun.nio.sctp.ShutdownNotification;
/**
* An implementation of ShutdownNotification
*/
public class SctpShutdown extends ShutdownNotification
implements SctpNotification
{
private Association association;
/* assocId is used to lookup the association before the notification is
* returned to user code */
private int assocId;
/* Invoked from native */
private SctpShutdown(int assocId) {
this.assocId = assocId;
}
@Override
public int assocId() {
return assocId;
}
@Override
public void setAssociation(Association association) {
this.association = association;
}
@Override
public Association association() {
assert association != null;
return association;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(super.toString()).append(" [");
sb.append("Association:").append(association).append("]");
return sb.toString();
}
}
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册