微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.net.SocketOptions的实例源码

项目:silvertunnel-ng    文件LocalSocketImpl.java   
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;
    }
}
项目:evosuite    文件EvoSuiteSocket.java   
@Override
protected void bind(InetAddress host,int port) throws IOException {

       if(port == 0) {
           port = VirtualNetwork.getInstance().getNewLocalephemeralPort();
       }

    //Todo: need to check special cases like multicast
    boolean opened = VirtualNetwork.getInstance().openTcpserver(host.getHostAddress(),port);
    if(!opened) {
        throw new IOException("Failed to open TCP port");
    }
    super.localport = port;
    setoption(Socketoptions.so_BINDADDR,host);
       isBound = true;
}
项目:In-the-Box-Fork    文件BlockGuard.java   
private boolean isLingerSocket(FileDescriptor fd) throws SocketException {
    try {
        Object lingerValue = mNetwork.getSocketoption(fd,Socketoptions.so_LINGER);
        if (lingerValue instanceof Boolean) {
            return (Boolean) lingerValue;
        } else if (lingerValue instanceof Integer) {
            return ((Integer) lingerValue) != 0;
        }
        throw new AssertionError(lingerValue.getClass().getName());
    } catch (Exception ignored) {
        // We're called via Socket.close (which doesn't ask for us to be called),so we
        // must not throw here,because Socket.close must not throw if asked to close an
        // already-closed socket.
        return false;
    }
}
项目:cInterphone    文件PlainDatagramSocketImpl.java   
@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;
    }
}
项目:cn1    文件PlainDatagramSocketImpl.java   
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;
    }
}
项目:cn1    文件PlainSocketImpl.java   
@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;
    }
}
项目:freeVM    文件PlainDatagramSocketImpl.java   
@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;
    }
}
项目:freeVM    文件PlainSocketImpl.java   
@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;
    }
}
项目:freeVM    文件PlainDatagramSocketImpl.java   
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;
    }
}
项目:phonty    文件PlainDatagramSocketImpl.java   
@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;
    }
}
项目:netlib    文件NetSocket2SocketImpl.java   
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;
}
项目:java-coap    文件QoSDatagramSocket.java   
/**
 * Non-synchronized on purpose (Todo refactor away the need to do this)
 */
@SuppressWarnings("sync-override")
@Override
public void setTrafficclass(int tc) throws SocketException {
    if (tc < 0 || tc > 255) {
        throw new IllegalArgumentException("tc is not in range 0 -- 255");
    }
    if (isClosed()) {
        throw new SocketException("Socket is closed");
    }
    impl.setoption(Socketoptions.IP_TOS,tc);

}
项目:javify    文件VMPlainSocketImpl.java   
public void setoption(int optionId,Object optionValue)
  throws SocketException
{
  int value;
  if (optionValue instanceof Integer)
    value = ((Integer) optionValue).intValue();
  else if (optionValue instanceof Boolean)
    // Switching off the linger behavior is done by setting
    // the value to -1. This is how the Java API interprets
    // it.
    value = ((Boolean) optionValue).booleanValue()
            ? 1
            : (optionId == Socketoptions.so_LINGER)
            ? -1
            : 0;
  else
    throw new IllegalArgumentException("option value type "
                                       + optionValue.getClass().getName());

  try
    {
      setoption(nfd.getNativeFD(),optionId,value);
    }
  catch (IOException ioe)
    {
      SocketException se = new SocketException();
      se.initCause(ioe);
      throw se;
    }
}
项目:javify    文件VMPlainSocketImpl.java   
/**
 * 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");
    }
}
项目:jvm-stm    文件VMPlainSocketImpl.java   
public void setoption(int optionId,value);
    }
  catch (IOException ioe)
    {
      SocketException se = new SocketException();
      se.initCause(ioe);
      throw se;
    }
}
项目:jvm-stm    文件VMPlainSocketImpl.java   
/**
 * 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");
    }
}
项目:j2objc    文件PlainServerSocketImpl.java   
@Override
protected void create(boolean isstreaming) throws IOException {
    super.create(isstreaming);
    if (isstreaming) {
        setoption(Socketoptions.so_REUSEADDR,Boolean.TRUE);
    }
}
项目:silvertunnel-monteux    文件NetSocket2SocketImpl.java   
@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;
}
项目:evosuite    文件MockSocket.java   
@Override
public void setSoLinger(boolean on,int linger) throws SocketException {
    if (isClosed())
        throw new SocketException("Socket is closed");
    if (!on) {
        getImpl().setoption(Socketoptions.so_LINGER,new Boolean(on));
    } else {
        if (linger < 0) {
            throw new IllegalArgumentException("invalid value for SO_LINGER");
        }
        if (linger > 65535)
            linger = 65535;
        getImpl().setoption(Socketoptions.so_LINGER,new Integer(linger));
    }
}
项目:evosuite    文件MockSocket.java   
@Override
public int getSoLinger() throws SocketException {
    if (isClosed())
        throw new SocketException("Socket is closed");
    Object o = getImpl().getoption(Socketoptions.so_LINGER);
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return -1;
    }
}
项目:evosuite    文件MockSocket.java   
@Override
public synchronized void setSoTimeout(int timeout) throws SocketException {
    if (isClosed())
        throw new SocketException("Socket is closed");
    if (timeout < 0)
        throw new IllegalArgumentException("timeout can't be negative");

    getImpl().setoption(Socketoptions.so_TIMEOUT,new Integer(timeout));
}
项目:evosuite    文件MockSocket.java   
@Override
public synchronized int getSoTimeout() throws SocketException {
    if (isClosed())
        throw new SocketException("Socket is closed");
    Object o = getImpl().getoption(Socketoptions.so_TIMEOUT);
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return 0;
    }
}
项目:evosuite    文件MockSocket.java   
@Override
public synchronized void setSendBufferSize(int size) throws SocketException{
    if (!(size > 0)) {
        throw new IllegalArgumentException("negative send size");
    }
    if (isClosed())
        throw new SocketException("Socket is closed");
    getImpl().setoption(Socketoptions.so_SNDBUF,new Integer(size));
}
项目:evosuite    文件MockSocket.java   
@Override
public synchronized int getSendBufferSize() throws SocketException {
    if (isClosed())
        throw new SocketException("Socket is closed");
    int result = 0;
    Object o = getImpl().getoption(Socketoptions.so_SNDBUF);
    if (o instanceof Integer) {
        result = ((Integer)o).intValue();
    }
    return result;
}
项目:evosuite    文件MockSocket.java   
@Override
public synchronized void setReceiveBufferSize(int size) throws SocketException{
    if (size <= 0) {
        throw new IllegalArgumentException("invalid receive size");
    }
    if (isClosed())
        throw new SocketException("Socket is closed");
    getImpl().setoption(Socketoptions.so_RCVBUF,new Integer(size));
}
项目:evosuite    文件MockSocket.java   
@Override
public synchronized int getReceiveBufferSize() throws SocketException{
    if (isClosed())
        throw new SocketException("Socket is closed");
    int result = 0;
    Object o = getImpl().getoption(Socketoptions.so_RCVBUF);
    if (o instanceof Integer) {
        result = ((Integer)o).intValue();
    }
    return result;
}
项目:evosuite    文件MockSocket.java   
@Override
public void setTrafficclass(int tc) throws SocketException {
    if (tc < 0 || tc > 255)
        throw new IllegalArgumentException("tc is not in range 0 -- 255");

    if (isClosed())
        throw new SocketException("Socket is closed");
    getImpl().setoption(Socketoptions.IP_TOS,new Integer(tc));
}
项目:evosuite    文件EvoSuiteSocket.java   
private void initOptions() {
    // see AbstractPlainSocketImpl
    options.put(Socketoptions.so_TIMEOUT,0);
    options.put(Socketoptions.so_RCVBUF,131072);
    options.put(Socketoptions.so_SNDBUF,131072);
    options.put(Socketoptions.so_LINGER,-1);
    options.put(Socketoptions.so_KEEPALIVE,false);
    options.put(Socketoptions.so_OOBINLINE,false);
    options.put(Socketoptions.so_REUSEADDR,false);
    options.put(Socketoptions.TCP_NODELAY,false);
       options.put(Socketoptions.IP_TOS,0);
}
项目:evosuite    文件EvoSuiteSocket.java   
@Override
protected void accept(SocketImpl s) throws IOException {

    if(!(s instanceof EvoSuiteSocket)) {
        throw new IOException("Can only handle mocked sockets");
    }

    EvoSuiteSocket mock = (EvoSuiteSocket) s;

    /*
     * If the test case has set up an incoming connection,then
     * simulate an immediate connection.
     * If not,there is no point in blocking the SUT for
     * a connection that will never arrive: just throw an exception
     */

    InetAddress localHost = (InetAddress) options.get(Socketoptions.so_BINDADDR); 
    NativeTcp tcp = VirtualNetwork.getInstance().pullTcpConnection(localHost.getHostAddress(),localport);

    if(tcp == null) {
        throw new IOException("Simulated exception on waiting server");
    } else {
        mock.openedConnection = tcp;
        mock.setoption(Socketoptions.so_BINDADDR,localHost);       
        mock.setLocalPort(localport);
        mock.setRemoteAddress(InetAddress.getByName(tcp.getRemoteEndPoint().getHost()));
        mock.setRemotePort(tcp.getRemoteEndPoint().getPort());
    }
}
项目:evosuite    文件MockServerSocket.java   
@Override
public synchronized void setSoTimeout(int timeout) throws SocketException {
       if(!MockFramework.isEnabled()){
           super.setSoTimeout(timeout);
           return;
       }
       if (isClosed())
        throw new SocketException("Socket is closed");
    getImpl().setoption(Socketoptions.so_TIMEOUT,new Integer(timeout));
}
项目:evosuite    文件MockServerSocket.java   
@Override
public synchronized int getSoTimeout() throws IOException {
       if(!MockFramework.isEnabled()){
           return super.getSoTimeout();
       }
       if (isClosed())
        throw new SocketException("Socket is closed");
    Object o = getImpl().getoption(Socketoptions.so_TIMEOUT);
    /* extra type safety */
    if (o instanceof Integer) {
        return ((Integer) o).intValue();
    } else {
        return 0;
    }
}
项目:evosuite    文件MockServerSocket.java   
@Override
public void setReuseAddress(boolean on) throws SocketException {
       if(!MockFramework.isEnabled()){
           super.setReuseAddress(on);
           return;
       }
       if (isClosed())
        throw new SocketException("Socket is closed");
    getImpl().setoption(Socketoptions.so_REUSEADDR,Boolean.valueOf(on));
}
项目:evosuite    文件MockServerSocket.java   
@Override
public boolean getReuseAddress() throws SocketException {
       if(!MockFramework.isEnabled()){
           return super.getReuseAddress();
       }
       if (isClosed())
        throw new SocketException("Socket is closed");
    return ((Boolean) (getImpl().getoption(Socketoptions.so_REUSEADDR))).booleanValue();
}
项目:In-the-Box-Fork    文件PlainServerSocketImpl.java   
@Override
protected void create(boolean isstreaming) throws IOException {
    super.create(isstreaming);
    if (isstreaming) {
        setoption(Socketoptions.so_REUSEADDR,Boolean.TRUE);
    }
}
项目:cn1    文件SocketChannelImpl.java   
/**
 * @see java.net.socket#getKeepAlive()
 */
@Override
public boolean getKeepAlive() throws SocketException {
    checkopen();
    return ((Boolean) socketImpl.getoption(Socketoptions.so_KEEPALIVE))
            .booleanValue();
}
项目:cn1    文件SocketChannelImpl.java   
/**
 * @see java.net.socket#getoOBInline()
 */
@Override
public boolean getoOBInline() throws SocketException {
    checkopen();
    return ((Boolean) socketImpl.getoption(Socketoptions.so_OOBINLINE))
            .booleanValue();
}
项目:cn1    文件SocketChannelImpl.java   
/**
 * @see java.net.socket#getSoLinger()
 */
@Override
public int getSoLinger() throws SocketException {
    checkopen();
    return ((Integer) socketImpl.getoption(Socketoptions.so_LINGER))
            .intValue();
}
项目:cn1    文件SocketChannelImpl.java   
/**
 * @see java.net.socket#getTcpNoDelay()
 */
@Override
public boolean getTcpNoDelay() throws SocketException {
    checkopen();
    return ((Boolean) socketImpl.getoption(Socketoptions.TCP_NODELAY))
            .booleanValue();
}
项目:cn1    文件SocketChannelImpl.java   
@Override
public synchronized void setReceiveBufferSize(int size)
        throws SocketException {
    checkopen();
    if (size < 1) {
        throw new IllegalArgumentException(Messages.getString("nio.0E")); //$NON-NLS-1$
    }
    socketImpl
            .setoption(Socketoptions.so_RCVBUF,Integer.valueOf(size));
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。