Пример #1
0
 private boolean _isOpenImpl() throws IOException {
   boolean wasBlocking = socketChannel.isBlocking();
   ByteBuffer buffer = ByteBuffer.allocate(1);
   if (wasBlocking) {
     socketChannel.configureBlocking(false);
   }
   int read;
   try {
     read = socketChannel.read(buffer);
   } catch (IOException e) {
     /* This should never happen in non Windows systems.
      * In Windows systems an IOException is thrown
      * whenever a client has closed its output connection
      * towards this channel and this method is called by
      * CommCore.
      */
     return false;
   }
   if (wasBlocking) {
     socketChannel.configureBlocking(true);
   }
   if (read == -1) {
     return false;
   } else if (read > 0) {
     istream.append(buffer.get(0));
   }
   return true;
 }
Пример #2
0
  /**
   * Connects the socket with a remote address. A timeout of zero is interpreted as an infinite
   * timeout. The connection will then block until established or an error occurs.
   *
   * @param endpoint The address to connect to
   * @exception IOException If an error occurs
   * @exception IllegalArgumentException If the address type is not supported
   * @exception IllegalBlockingModeException If this socket has an associated channel, and the
   *     channel is in non-blocking mode
   * @exception SocketTimeoutException If the timeout is reached
   * @since 1.4
   */
  public void connect(SocketAddress endpoint, int timeout) throws IOException {
    if (closed) throw new SocketException("Socket is closed");

    if (!(endpoint instanceof InetSocketAddress))
      throw new IllegalArgumentException("Address type not supported");

    if (ch != null && !ch.isBlocking()) throw new IllegalBlockingModeException();

    impl.connect(endpoint, timeout);
  }
Пример #3
0
 public boolean isBlocking() {
   return sc.isBlocking();
 }