private void setSocketParameters(Socket client_sock) throws SocketException {
    if (log.isTraceEnabled())
      log.trace(
          "["
              + local_addr
              + "] accepted connection from "
              + client_sock.getInetAddress()
              + ":"
              + client_sock.getPort());
    try {
      client_sock.setSendBufferSize(send_buf_size);
    } catch (IllegalArgumentException ex) {
      if (log.isErrorEnabled())
        log.error("exception setting send buffer size to " + send_buf_size + " bytes", ex);
    }
    try {
      client_sock.setReceiveBufferSize(recv_buf_size);
    } catch (IllegalArgumentException ex) {
      if (log.isErrorEnabled())
        log.error("exception setting receive buffer size to " + send_buf_size + " bytes", ex);
    }

    client_sock.setKeepAlive(true);
    client_sock.setTcpNoDelay(tcp_nodelay);
    if (linger > 0) client_sock.setSoLinger(true, linger);
    else client_sock.setSoLinger(false, -1);
  }
Exemple #2
0
  protected void setSocketParameters(Socket client_sock) throws SocketException {
    try {
      client_sock.setSendBufferSize(server.send_buf_size);
    } catch (IllegalArgumentException ex) {
      server.log.error(
          "%s: exception setting send buffer to %d bytes: %s",
          server.local_addr, server.send_buf_size, ex);
    }
    try {
      client_sock.setReceiveBufferSize(server.recv_buf_size);
    } catch (IllegalArgumentException ex) {
      server.log.error(
          "%s: exception setting receive buffer to %d bytes: %s",
          server.local_addr, server.recv_buf_size, ex);
    }

    client_sock.setKeepAlive(true);
    client_sock.setTcpNoDelay(server.tcp_nodelay);
    if (server.linger > 0) client_sock.setSoLinger(true, server.linger);
    else client_sock.setSoLinger(false, -1);
  }
  /**
   * Applies the current settings to the given socket.
   *
   * @param s Socket to apply the settings to
   * @return Socket the input socket
   */
  protected Socket applySettings(Socket s) {
    try {
      s.setKeepAlive(SO_KEEPALIVE);
      s.setOOBInline(OOBINLINE);
      s.setReuseAddress(SO_REUSEADDR);
      s.setTcpNoDelay(TCP_NODELAY);
      s.setOOBInline(OOBINLINE);

      s.setReceiveBufferSize(SO_RCVBUF);
      s.setSendBufferSize(SO_SNDBUF);
      s.setSoTimeout(SO_TIMEOUT);
      s.setSoLinger(SO_LINGER, LINGER);
    } catch (SocketException e) {
      throw new RuntimeException(e);
    }
    return s;
  }
Exemple #4
0
 public void setSoLinger(boolean on, int linger) throws SocketException {
   mSocket.setSoLinger(on, linger);
 }