当前位置: 首页>>代码示例>>Java>>正文


Java Socket.getSoTimeout方法代码示例

本文整理汇总了Java中java.net.Socket.getSoTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java Socket.getSoTimeout方法的具体用法?Java Socket.getSoTimeout怎么用?Java Socket.getSoTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.Socket的用法示例。


在下文中一共展示了Socket.getSoTimeout方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: discardStream

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Discards the response body so that the connection can be reused. This
 * needs to be done judiciously, since it delays the current request in
 * order to speed up a potential future request that may never occur.
 *
 * <p>A stream may be discarded to encourage response caching (a response
 * cannot be cached unless it is consumed completely) or to enable connection
 * reuse.
 */
private static boolean discardStream(HttpEngine httpEngine, InputStream responseBodyIn) {
  Connection connection = httpEngine.connection;
  if (connection == null) return false;
  Socket socket = connection.getSocket();
  if (socket == null) return false;
  try {
    int socketTimeout = socket.getSoTimeout();
    socket.setSoTimeout(DISCARD_STREAM_TIMEOUT_MILLIS);
    try {
      Util.skipAll(responseBodyIn);
      return true;
    } finally {
      socket.setSoTimeout(socketTimeout);
    }
  } catch (IOException e) {
    return false;
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:28,代码来源:HttpTransport.java

示例2: isHealthy

import java.net.Socket; //导入方法依赖的package包/类
boolean isHealthy(boolean doExtensiveChecks) {
    if (!connected) {
        return false;
    }

    Socket socket;
    BufferedSource source;
    synchronized (this) {
        socket = this.socket;
        source = this.source;
    }
    if (socket == null ||
            source == null ||
            socket.isClosed() ||
            socket.isInputShutdown() ||
            socket.isOutputShutdown()) {
        return false;
    }

    if (doExtensiveChecks) {
        try {
            int readTimeout = socket.getSoTimeout();
            try {
                socket.setSoTimeout(1);
                return !source.exhausted();
            } finally {
                socket.setSoTimeout(readTimeout);
            }
        } catch (SocketTimeoutException ignored) {
            ignored.printStackTrace();
            // Read timed out; socket is good.
        } catch (IOException e) {
            return false; // Couldn't read; socket is closed.
        }
    }

    return true;
}
 
开发者ID:pCloud,项目名称:pcloud-networking-java,代码行数:39,代码来源:RealConnection.java

示例3: getSocketTimeout

import java.net.Socket; //导入方法依赖的package包/类
@Override
public int getSocketTimeout() {
    final Socket socket = this.socketHolder.get();
    if (socket != null) {
        try {
            return socket.getSoTimeout();
        } catch (final SocketException ignore) {
            return -1;
        }
    } else {
        return -1;
    }
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:14,代码来源:BHttpConnectionBase.java

示例4: fillInputBuffer

import java.net.Socket; //导入方法依赖的package包/类
private int fillInputBuffer(final int timeout) throws IOException {
    final Socket socket = this.socketHolder.get();
    final int oldtimeout = socket.getSoTimeout();
    try {
        socket.setSoTimeout(timeout);
        return this.inbuffer.fillBuffer();
    } finally {
        socket.setSoTimeout(oldtimeout);
    }
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:11,代码来源:BHttpConnectionBase.java

示例5: HandShake

import java.net.Socket; //导入方法依赖的package包/类
/**
 * HandShake Constructor used by server side connection
 */
public HandShake(Socket sock, int timeout, DistributedSystem sys, Version clientVersion,
    byte communicationMode) throws IOException, AuthenticationRequiredException {
  this.clientVersion = clientVersion;
  this.system = sys;
  // SocketChannel sc = sock.getChannel();
  /*
   * if (sc != null) { } else
   */ {
    int soTimeout = -1;
    try {
      soTimeout = sock.getSoTimeout();
      sock.setSoTimeout(timeout);
      InputStream is = sock.getInputStream();
      int valRead = is.read();
      // this.code = (byte)is.read();
      if (valRead == -1) {
        throw new EOFException(
            LocalizedStrings.HandShake_HANDSHAKE_EOF_REACHED_BEFORE_CLIENT_CODE_COULD_BE_READ
                .toLocalizedString());
      }
      this.code = (byte) valRead;
      if (this.code != REPLY_OK) {
        throw new IOException(
            LocalizedStrings.HandShake_HANDSHAKE_REPLY_CODE_IS_NOT_OK.toLocalizedString());
      }
      try {
        DataInputStream dis = new DataInputStream(is);
        DataOutputStream dos = new DataOutputStream(sock.getOutputStream());
        this.clientReadTimeout = dis.readInt();
        if (clientVersion.compareTo(Version.CURRENT) < 0) {
          // versioned streams allow object serialization code to deal with older clients
          dis = new VersionedDataInputStream(dis, clientVersion);
          dos = new VersionedDataOutputStream(dos, clientVersion);
        }
        this.id = ClientProxyMembershipID.readCanonicalized(dis);
        // Note: credentials should always be the last piece in handshake for
        // Diffie-Hellman key exchange to work
        if (clientVersion.compareTo(Version.GFE_603) >= 0) {
          setOverrides(new byte[] {dis.readByte()});
        } else {
          setClientConflation(dis.readByte());
        }
        // Hitesh
        if (this.clientVersion.compareTo(Version.GFE_65) < 0
            || communicationMode == Acceptor.GATEWAY_TO_GATEWAY) {
          this.credentials = readCredentials(dis, dos, sys);
        } else {
          this.credentials = this.readCredential(dis, dos, sys);
        }
      } catch (IOException ioe) {
        this.code = -2;
        throw ioe;
      } catch (ClassNotFoundException cnfe) {
        this.code = -3;
        throw new IOException(
            LocalizedStrings.HandShake_CLIENTPROXYMEMBERSHIPID_CLASS_COULD_NOT_BE_FOUND_WHILE_DESERIALIZING_THE_OBJECT
                .toLocalizedString());
      }
    } finally {
      if (soTimeout != -1) {
        try {
          sock.setSoTimeout(soTimeout);
        } catch (IOException ignore) {
        }
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:72,代码来源:HandShake.java

示例6: readClientVersion

import java.net.Socket; //导入方法依赖的package包/类
private static Version readClientVersion(ServerConnection connection)
    throws IOException, VersionException {

  Socket socket = connection.getSocket();
  int timeout = connection.getHandShakeTimeout();

  int soTimeout = -1;
  try {
    soTimeout = socket.getSoTimeout();
    socket.setSoTimeout(timeout);
    InputStream is = socket.getInputStream();
    short clientVersionOrdinal = Version.readOrdinalFromInputStream(is);
    if (clientVersionOrdinal == -1) {
      throw new EOFException(
          LocalizedStrings.ServerHandShakeProcessor_HANDSHAKEREADER_EOF_REACHED_BEFORE_CLIENT_VERSION_COULD_BE_READ
              .toLocalizedString());
    }
    Version clientVersion = null;
    try {
      clientVersion = Version.fromOrdinal(clientVersionOrdinal, true);
    } catch (UnsupportedVersionException uve) {
      // Allows higher version of wan site to connect to server
      if (connection.getCommunicationMode() == Acceptor.GATEWAY_TO_GATEWAY
          && !(clientVersionOrdinal == Version.NOT_SUPPORTED_ORDINAL)) {
        return Acceptor.VERSION;
      } else {
        SocketAddress sa = socket.getRemoteSocketAddress();
        String sInfo = "";
        if (sa != null) {
          sInfo = " Client: " + sa.toString() + ".";
        }
        throw new UnsupportedVersionException(uve.getMessage() + sInfo);
      }
    }

    if (!clientVersion.compatibleWith(Acceptor.VERSION)) {
      throw new IncompatibleVersionException(clientVersion, Acceptor.VERSION);// we can throw this
                                                                              // to restrict
    } // Backward Compatibilty Support to limited no of versions
    return clientVersion;
  } finally {
    if (soTimeout != -1) {
      try {
        socket.setSoTimeout(soTimeout);
      } catch (IOException ignore) {
      }
    }
  }
}
 
开发者ID:ampool,项目名称:monarch,代码行数:50,代码来源:ServerHandShakeProcessor.java

示例7: SocketInputStream

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Same as SocketInputStream(socket.getChannel(), socket.getSoTimeout())
 * :<br><br>
 * 
 * Create a new input stream with the given timeout. If the timeout
 * is zero, it will be treated as infinite timeout. The socket's
 * channel will be configured to be non-blocking.
 * @see SocketInputStream#SocketInputStream(ReadableByteChannel, long)
 *  
 * @param socket should have a channel associated with it.
 * @throws IOException
 */
public SocketInputStream(Socket socket) throws IOException {
  this(socket.getChannel(), socket.getSoTimeout());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:16,代码来源:SocketInputStream.java


注:本文中的java.net.Socket.getSoTimeout方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。