本文整理汇总了Java中java.net.SocketOptions.SO_TIMEOUT属性的典型用法代码示例。如果您正苦于以下问题:Java SocketOptions.SO_TIMEOUT属性的具体用法?Java SocketOptions.SO_TIMEOUT怎么用?Java SocketOptions.SO_TIMEOUT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.net.SocketOptions
的用法示例。
在下文中一共展示了SocketOptions.SO_TIMEOUT属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOption
public Object getOption(int optID) throws IOException
{
if (fd == null) {
throw new IOException("socket not created");
}
if (optID == SocketOptions.SO_TIMEOUT) {
return 0;
}
int value = getOption_native(fd, optID);
switch (optID)
{
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_SNDBUF:
return value;
case SocketOptions.SO_REUSEADDR:
default:
return value;
}
}
示例2: getOption
@Override
public Object getOption(int optID) throws SocketException {
if (optID == SocketOptions.SO_TIMEOUT) {
return Integer.valueOf(receiveTimeout);
} else if (optID == SocketOptions.IP_TOS) {
return Integer.valueOf(trafficClass);
} else {
// Call the native first so there will be
// an exception if the socket if closed.
Object result = netImpl.getSocketOption(fd, optID);
if (optID == SocketOptions.IP_MULTICAST_IF
&& (netImpl.getSocketFlags() & MULTICAST_IF) != 0) {
try {
return InetAddress.getByAddress(ipaddress);
} catch (UnknownHostException e) {
return null;
}
}
return result;
}
}
示例3: getOption
public Object getOption(int optID) throws SocketException {
if (optID == SocketOptions.SO_TIMEOUT) {
return Integer.valueOf(receiveTimeout);
} else if (optID == SocketOptions.IP_TOS) {
return Integer.valueOf(trafficClass);
} else {
// Call the native first so there will be
// an exception if the socket if closed.
Object result = netImpl.getSocketOption(fd, optID);
if (optID == SocketOptions.IP_MULTICAST_IF
&& (netImpl.getSocketFlags() & MULTICAST_IF) != 0) {
try {
return InetAddress.getByAddress(ipaddress);
} catch (UnknownHostException e) {
return null;
}
}
return result;
}
}
示例4: getOption
@Override
public Object getOption(int optID) throws SocketException {
if (optID == SocketOptions.SO_TIMEOUT) {
return Integer.valueOf(receiveTimeout);
} else if (optID == SocketOptions.IP_TOS) {
return Integer.valueOf(trafficClass);
} else {
// Call the native first so there will be
// an exception if the socket if closed.
Object result = netImpl.getSocketOption(fd, optID);
if (optID == SocketOptions.TCP_NODELAY
&& (netImpl.getSocketFlags() & TCP_NODELAY) != 0) {
return Boolean.valueOf(tcpNoDelay);
}
return result;
}
}
示例5: getOption
public Object getOption(int key) throws SocketException {
if (key==SocketOptions.SO_TIMEOUT) {
// get timeout
return inputStreamTimeout;
}
if (key==SocketOptions.TCP_NODELAY) {
return tcpNodelay;
}
if (key==SocketOptions.SO_LINGER) {
// get timeout
return soLinger;
}
// unsupported option
String msg = "no implementation for getOption("+key+"). List of all options in java.net.SocketOptions.";
if (log.isLoggable(Level.FINER)) {
log.log(Level.FINER, msg, new Throwable("method not completely implemented"));
} else {
log.info(msg+" - Log with level=FINER to get call hierarchy.");
}
return null;
}
示例6: getOption
/**
* Get a socket option. This implementation is only required to support
* socket options that are boolean values, which include:
*
* SocketOptions.IP_MULTICAST_LOOP
* SocketOptions.SO_BROADCAST
* SocketOptions.SO_KEEPALIVE
* SocketOptions.SO_OOBINLINE
* SocketOptions.SO_REUSEADDR
* SocketOptions.TCP_NODELAY
*
* and socket options that are integer values, which include:
*
* SocketOptions.IP_TOS
* SocketOptions.SO_LINGER
* SocketOptions.SO_RCVBUF
* SocketOptions.SO_SNDBUF
* SocketOptions.SO_TIMEOUT
*
* @param optionId The option ID to fetch.
* @return A {@link Boolean} or {@link Integer} containing the socket
* option.
* @throws SocketException
*/
public Object getOption(int optionId) throws SocketException
{
int value;
try
{
value = getOption(nfd.getNativeFD(), optionId);
}
catch (IOException ioe)
{
SocketException se = new SocketException();
se.initCause(ioe);
throw se;
}
switch (optionId)
{
case SocketOptions.IP_MULTICAST_LOOP:
case SocketOptions.SO_BROADCAST:
case SocketOptions.SO_KEEPALIVE:
case SocketOptions.SO_OOBINLINE:
case SocketOptions.SO_REUSEADDR:
case SocketOptions.TCP_NODELAY:
return Boolean.valueOf(value != 0);
case SocketOptions.IP_TOS:
case SocketOptions.SO_LINGER:
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_SNDBUF:
case SocketOptions.SO_TIMEOUT:
return new Integer(value);
default:
throw new SocketException("getting option " + optionId +
" not supported here");
}
}
示例7: getOption
/**
* Get a socket option. This implementation is only required to support
* socket options that are boolean values, which include:
*
* SocketOptions.IP_MULTICAST_LOOP
* SocketOptions.SO_BROADCAST
* SocketOptions.SO_KEEPALIVE
* SocketOptions.SO_OOBINLINE
* SocketOptions.SO_REUSEADDR
* SocketOptions.TCP_NODELAY
*
* and socket options that are integer values, which include:
*
* SocketOptions.IP_TOS
* SocketOptions.SO_LINGER
* SocketOptions.SO_RCVBUF
* SocketOptions.SO_SNDBUF
* SocketOptions.SO_TIMEOUT
*
* @param optionId The option ID to fetch.
* @return A {@link Boolean} or {@link Integer} containing the socket
* option.
* @throws SocketException
*/
public Object getOption(int optionId) throws SocketException
{
int value;
try
{
value = getOption(nfd.getNativeFD(), optionId);
}
catch (IOException ioe)
{
SocketException se = new SocketException();
se.initCause(ioe);
throw se;
}
switch (optionId)
{
case SocketOptions.IP_MULTICAST_LOOP:
case SocketOptions.SO_BROADCAST:
case SocketOptions.SO_KEEPALIVE:
case SocketOptions.SO_OOBINLINE:
case SocketOptions.SO_REUSEADDR:
case SocketOptions.TCP_NODELAY:
return Boolean.valueOf(value != 0);
case SocketOptions.IP_TOS:
case SocketOptions.SO_LINGER:
case SocketOptions.SO_RCVBUF:
case SocketOptions.SO_SNDBUF:
case SocketOptions.SO_TIMEOUT:
return new Integer(value);
default:
throw new SocketException("getting option " + optionId +
" not supported here");
}
}
示例8: getOption
@Override
public Object getOption(final int key) throws SocketException
{
if (key == SocketOptions.SO_TIMEOUT)
{
// get timeout
return inputStreamTimeout;
}
if (key == SocketOptions.TCP_NODELAY)
{
return tcpNodelay;
}
if (key == SocketOptions.SO_LINGER)
{
// get timeout
return soLinger;
}
// unsupported option
final String msg = "no implementation for getOption(" + key
+ "). List of all options in java.net.SocketOptions.";
if (logger.isDebugEnabled())
{
logger.debug(msg, new Throwable("method not completely implemented"));
}
else
{
logger.info(msg + " - Log with level=debug to get call hierarchy.");
}
return null;
}
示例9: setOption
@Override
public void setOption(int optID, Object val) throws SocketException {
if (optID == SocketOptions.SO_TIMEOUT) {
receiveTimeout = ((Integer) val).intValue();
} else {
try {
netImpl.setSocketOption(fd, optID, val);
if (optID == SocketOptions.TCP_NODELAY
&& (netImpl.getSocketFlags() & TCP_NODELAY) != 0) {
tcpNoDelay = ((Boolean) val).booleanValue();
}
} catch (SocketException e) {
// we don't throw an exception for IP_TOS even if the platform
// won't let us set the requested value
if (optID != SocketOptions.IP_TOS) {
throw e;
}
}
/*
* save this value as it is actually used differently for IPv4 and
* IPv6 so we cannot get the value using the getOption. The option
* is actually only set for IPv4 and a masked version of the value
* will be set as only a subset of the values are allowed on the
* socket. Therefore we need to retain it to return the value that
* was set. We also need the value to be passed into a number of
* natives so that it can be used properly with IPv6
*/
if (optID == SocketOptions.IP_TOS) {
trafficClass = ((Integer) val).intValue();
}
}
}
示例10: getOption
public Object getOption(int optID) throws SocketException {
if(optID == SocketOptions.SO_LINGER) {
return 0;
} else if(optID == SocketOptions.TCP_NODELAY) {
return Boolean.TRUE;
} else if(optID == SocketOptions.SO_TIMEOUT) {
return 0;
} else {
return 0;
}
}
示例11: getOption
/**
* Answer the nominated socket option. Receive timeouts are maintained
* in Java, rather than in the JNI code.
*
* @param optID the socket option to retrieve
* @return Object the option value
* @exception SocketException thrown if an error occurs while accessing the option
*/
public synchronized Object getOption(int optID) throws SocketException {
if (optID == SocketOptions.SO_TIMEOUT) {
return receiveTimeout;
} else if (optID == SocketOptions.SO_BINDADDR) {
return localAddress;
} else if (optID == SocketOptions.SO_SNDBUF) {
return sysCall.sysNetSocketSndBuf(native_fd);
} else {
throw new VM_UnimplementedError("JikesRVMSocketImpl.getOption: " + optID);
}
}
示例12: getSocketOptionErrno
private static Object getSocketOptionErrno(FileDescriptor fd, int option) throws ErrnoException, SocketException {
switch (option) {
case SocketOptions.IP_MULTICAST_IF:
// This is IPv4-only.
return Libcore.os.getsockoptInAddr(fd, IPPROTO_IP, IP_MULTICAST_IF);
case SocketOptions.IP_MULTICAST_IF2:
// This is IPv6-only.
return Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_MULTICAST_IF);
case SocketOptions.IP_MULTICAST_LOOP:
// Since setting this from java.net always sets IPv4 and IPv6 to the same value,
// it doesn't matter which we return.
return booleanFromInt(Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP));
case IoBridge.JAVA_IP_MULTICAST_TTL:
// Since setting this from java.net always sets IPv4 and IPv6 to the same value,
// it doesn't matter which we return.
return Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS);
case SocketOptions.IP_TOS:
// Since setting this from java.net always sets IPv4 and IPv6 to the same value,
// it doesn't matter which we return.
return Libcore.os.getsockoptInt(fd, IPPROTO_IPV6, IPV6_TCLASS);
case SocketOptions.SO_BROADCAST:
return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_BROADCAST));
case SocketOptions.SO_KEEPALIVE:
return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_KEEPALIVE));
case SocketOptions.SO_LINGER:
StructLinger linger = Libcore.os.getsockoptLinger(fd, SOL_SOCKET, SO_LINGER);
if (!linger.isOn()) {
return false;
}
return linger.l_linger;
case SocketOptions.SO_OOBINLINE:
return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_OOBINLINE));
case SocketOptions.SO_RCVBUF:
return Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_RCVBUF);
case SocketOptions.SO_REUSEADDR:
return booleanFromInt(Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_REUSEADDR));
case SocketOptions.SO_SNDBUF:
return Libcore.os.getsockoptInt(fd, SOL_SOCKET, SO_SNDBUF);
case SocketOptions.SO_TIMEOUT:
return (int) Libcore.os.getsockoptTimeval(fd, SOL_SOCKET, SO_RCVTIMEO).toMillis();
case SocketOptions.TCP_NODELAY:
return booleanFromInt(Libcore.os.getsockoptInt(fd, IPPROTO_TCP, TCP_NODELAY));
default:
throw new SocketException("Unknown socket option: " + option);
}
}
示例13: setOption
@Override
public synchronized void setOption(final int key, final Object value)
throws SocketException
{
logger.debug("setOption(key={},value={})", key, value);
if (key == SocketOptions.SO_TIMEOUT)
{
// set timeout
if (value instanceof Integer)
{
inputStreamTimeout = (Integer) value;
if (inputStream != null)
{
inputStream.setTimeout(inputStreamTimeout);
}
}
else
{
logger.warn("ignored value of wrong type of setOption(key={}"
+ ",value={}"
+ "). List of all options in java.net.SocketOptions.", key, value);
}
return;
}
if (key == SocketOptions.TCP_NODELAY)
{
// ignore the value but keep it for later get operations
if (value instanceof Boolean)
{
tcpNodelay = (Boolean) value;
}
else
{
logger.warn("ignored value of wrong type of setOption(key={}"
+ ",value={}). List of all options in java.net.SocketOptions.", key, value);
}
return;
}
if (key == SocketOptions.SO_TIMEOUT)
{
// ignore the value but keep it for later get operations
if (value instanceof Integer)
{
soLinger = (Integer) value;
}
else
{
logger.warn("ignored value of wrong type of setOption(key={}"
+ ",value={}). List of all options in java.net.SocketOptions.", key, value);
}
return;
}
// unsupported option
final String msg = "no implementation for setOption(key=" + key
+ ",value=" + value
+ "). List of all options in java.net.SocketOptions.";
if (logger.isDebugEnabled())
{
logger.debug(msg, new Throwable("method not completely implemented"));
}
else
{
logger.warn(msg + " Log with level=debug to get call hierarchy.");
}
}
示例14: setOption
public synchronized void setOption(int key, Object value) throws SocketException {
log.fine("setOption(key="+key+",value="+value+")");
if (key==SocketOptions.SO_TIMEOUT) {
// set timeout
if (value instanceof Integer) {
inputStreamTimeout = (Integer)value;
if (inputStream!=null) {
inputStream.setTimeout(inputStreamTimeout);
}
} else {
log.warning("ignored value of wrong type of setOption(key="+key+",value="+value+"). List of all options in java.net.SocketOptions.");
}
return;
}
if (key==SocketOptions.TCP_NODELAY) {
// ignore the value but keep it for later get operations
if (value instanceof Boolean) {
tcpNodelay = (Boolean)value;
} else {
log.warning("ignored value of wrong type of setOption(key="+key+",value="+value+"). List of all options in java.net.SocketOptions.");
}
return;
}
if (key==SocketOptions.SO_TIMEOUT) {
// ignore the value but keep it for later get operations
if (value instanceof Integer) {
soLinger = (Integer)value;
} else {
log.warning("ignored value of wrong type of setOption(key="+key+",value="+value+"). List of all options in java.net.SocketOptions.");
}
return;
}
// unsupported option
String msg = "no implementation for setOption(key="+key+",value="+value+"). List of all options in java.net.SocketOptions.";
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE, msg, new Throwable("method not completely implemented"));
} else {
log.warning(msg+" Log with level=FINE to get call hierarchy.");
}
}