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


Java Socket.setSoLinger方法代码示例

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


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

示例1: bind

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void bind(final Socket socket, final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    assertNotOpen();
    socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
    socket.setKeepAlive(HttpConnectionParams.getSoKeepalive(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    super.bind(socket, params);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:DefaultHttpServerConnection.java

示例2: connect

import java.net.Socket; //导入方法依赖的package包/类
public void connect() {

		if (!isConnected()) {

			try {
				socket = new Socket();
				socket.setReuseAddress(true);
				socket.setKeepAlive(true);
				socket.setTcpNoDelay(true);
				socket.setSoLinger(true, 0);
				
				socket.connect(new InetSocketAddress(host, port), connectionTimeout);
				if ( soTimeout > 0)
		          socket.setSoTimeout(soTimeout);
		        
		        outputStream = new RedisOutputStream(socket.getOutputStream());
		        inputStream = new RedisInputStream(socket.getInputStream());
		        
			} catch (IOException ex) {
				broken = true;
				throw new JedisConnectionException("Failed connecting to host " + host + ":" + port, ex);
			}
		}
	}
 
开发者ID:variflight,项目名称:feeyo-redisproxy,代码行数:25,代码来源:JedisConnection.java

示例3: setProperties

import java.net.Socket; //导入方法依赖的package包/类
public void setProperties(Socket socket) throws SocketException{
    if (rxBufSize != null)
        socket.setReceiveBufferSize(rxBufSize.intValue());
    if (txBufSize != null)
        socket.setSendBufferSize(txBufSize.intValue());
    if (ooBInline !=null)
        socket.setOOBInline(ooBInline.booleanValue());
    if (soKeepAlive != null)
        socket.setKeepAlive(soKeepAlive.booleanValue());
    if (performanceConnectionTime != null && performanceLatency != null &&
            performanceBandwidth != null)
        socket.setPerformancePreferences(
                performanceConnectionTime.intValue(),
                performanceLatency.intValue(),
                performanceBandwidth.intValue());
    if (soReuseAddress != null)
        socket.setReuseAddress(soReuseAddress.booleanValue());
    if (soLingerOn != null && soLingerTime != null)
        socket.setSoLinger(soLingerOn.booleanValue(),
                soLingerTime.intValue());
    if (soTimeout != null && soTimeout.intValue() >= 0)
        socket.setSoTimeout(soTimeout.intValue());
    if (tcpNoDelay != null)
        socket.setTcpNoDelay(tcpNoDelay.booleanValue());
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:26,代码来源:SocketProperties.java

示例4: bind

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void bind(
        final Socket socket,
        final HttpParams params) throws IOException {
    if (socket == null) {
        throw new IllegalArgumentException("Socket may not be null");
    }
    if (params == null) {
        throw new IllegalArgumentException("HTTP parameters may not be null");
    }
    assertNotOpen();
    socket.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    socket.setSoTimeout(HttpConnectionParams.getSoTimeout(params));
    socket.setKeepAlive(HttpConnectionParams.getSoKeepalive(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    super.bind(socket, params);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:DefaultHttpClientConnection.java

示例5: bind

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void bind(
        final Socket socket,
        final HttpParams params) throws IOException {
    Args.notNull(socket, "Socket");
    Args.notNull(params, "HTTP parameters");
    assertNotOpen();
    socket.setTcpNoDelay(params.getBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true));
    socket.setSoTimeout(params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0));
    socket.setKeepAlive(params.getBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, false));
    final int linger = params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    super.bind(socket, params);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:17,代码来源:DefaultHttpClientConnection.java

示例6: bind

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void bind(final Socket socket, final HttpParams params) throws IOException {
    Args.notNull(socket, "Socket");
    Args.notNull(params, "HTTP parameters");
    assertNotOpen();
    socket.setTcpNoDelay(params.getBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true));
    socket.setSoTimeout(params.getIntParameter(CoreConnectionPNames.SO_TIMEOUT, 0));
    socket.setKeepAlive(params.getBooleanParameter(CoreConnectionPNames.SO_KEEPALIVE, false));
    final int linger = params.getIntParameter(CoreConnectionPNames.SO_LINGER, -1);
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    if (linger >= 0) {
        socket.setSoLinger(linger > 0, linger);
    }
    super.bind(socket, params);
}
 
开发者ID:mozilla-mobile,项目名称:FirefoxData-android,代码行数:18,代码来源:DefaultHttpServerConnection.java

示例7: configure

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void configure(final Socket socket) throws IOException {
    if(preferences.getInteger("connection.buffer.receive") > 0) {
        socket.setReceiveBufferSize(preferences.getInteger("connection.buffer.receive"));
    }
    if(preferences.getInteger("connection.buffer.send") > 0) {
        socket.setSendBufferSize(preferences.getInteger("connection.buffer.send"));
    }
    final int timeout = preferences.getInteger("connection.timeout.seconds") * 1000;
    if(log.isInfoEnabled()) {
        log.info(String.format("Set timeout to %dms for socket %s", timeout, socket));
    }
    socket.setSoTimeout(timeout);
    if(preferences.getBoolean("connection.socket.linger")) {
        // The setting only affects socket close. Make sure closing SSL socket does not hang because close_notify cannot be sent.
        socket.setSoLinger(true, timeout);
    }
    if(preferences.getBoolean("connection.socket.keepalive")) {
        socket.setKeepAlive(true);
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:22,代码来源:DefaultSocketConfigurator.java

示例8: connect

import java.net.Socket; //导入方法依赖的package包/类
public void connect() {
  if (!isConnected()) {
    try {
      socket = new Socket();
      // ->@wjw_add
      socket.setReuseAddress(true);
      socket.setKeepAlive(true); // Will monitor the TCP connection is
      // valid
      socket.setTcpNoDelay(true); // Socket buffer Whetherclosed, to
      // ensure timely delivery of data
      socket.setSoLinger(true, 0); // Control calls close () method,
      // the underlying socket is closed
      // immediately
      // <-[email protected]_add

      socket.connect(new InetSocketAddress(host, port), connectionTimeout);
      socket.setSoTimeout(soTimeout);
      outputStream = new RedisOutputStream(socket.getOutputStream());
      inputStream = new RedisInputStream(socket.getInputStream());
    } catch (IOException ex) {
      broken = true;
      throw new JedisConnectionException(ex);
    }
  }
}
 
开发者ID:x7-framework,项目名称:x7,代码行数:26,代码来源:Connection.java

示例9: run

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void run() {
    try {
        while (!isTerminated() && !Thread.interrupted()) {
            final Socket socket = this.serversocket.accept();
            socket.setSoTimeout(this.socketConfig.getSoTimeout());
            socket.setKeepAlive(this.socketConfig.isSoKeepAlive());
            socket.setTcpNoDelay(this.socketConfig.isTcpNoDelay());
            if (this.socketConfig.getRcvBufSize() > 0) {
                socket.setReceiveBufferSize(this.socketConfig.getRcvBufSize());
            }
            if (this.socketConfig.getSndBufSize() > 0) {
                socket.setSendBufferSize(this.socketConfig.getSndBufSize());
            }
            if (this.socketConfig.getSoLinger() >= 0) {
                socket.setSoLinger(true, this.socketConfig.getSoLinger());
            }
            final HttpServerConnection conn = this.connectionFactory.createConnection(socket);
            final Worker worker = new Worker(this.httpService, conn, this.exceptionLogger);
            this.executorService.execute(worker);
        }
    } catch (final Exception ex) {
        this.exceptionLogger.log(ex);
    }
}
 
开发者ID:gusavila92,项目名称:java-android-websocket-client,代码行数:26,代码来源:RequestListener.java

示例10: setSocketProperties

import java.net.Socket; //导入方法依赖的package包/类
private void setSocketProperties(Socket socket)
        throws SocketException
{
    socket.setSoLinger(false, 0);
    socket.setTcpNoDelay(true);
    socket.setKeepAlive(true);
    socket.setSoTimeout(Ints.saturatedCast(requestTimeoutMillis));
}
 
开发者ID:airlift,项目名称:drift,代码行数:9,代码来源:ApacheThriftMethodInvoker.java

示例11: openSocket

import java.net.Socket; //导入方法依赖的package包/类
/**
 * open real socket and set time out when waitForAck is enabled
 * is socket open return directly
 */
protected void openSocket() throws IOException {
   if(isConnected()) return ;
   try {
       socket = new Socket();
       InetSocketAddress sockaddr = new InetSocketAddress(getAddress(), getPort());
       socket.connect(sockaddr,(int)getTimeout());
       socket.setSendBufferSize(getTxBufSize());
       socket.setReceiveBufferSize(getRxBufSize());
       socket.setSoTimeout( (int) getTimeout());
       socket.setTcpNoDelay(getTcpNoDelay());
       socket.setKeepAlive(getSoKeepAlive());
       socket.setReuseAddress(getSoReuseAddress());
       socket.setOOBInline(getOoBInline());
       socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
       socket.setTrafficClass(getSoTrafficClass());
       setConnected(true);
       soOut = socket.getOutputStream();
       soIn  = socket.getInputStream();
       setRequestCount(0);
       setConnectTime(System.currentTimeMillis());
       if (log.isDebugEnabled())
           log.debug(sm.getString("IDataSender.openSocket", getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)));
  } catch (IOException ex1) {
      SenderState.getSenderState(getDestination()).setSuspect();
      if (log.isDebugEnabled())
          log.debug(sm.getString("IDataSender.openSocket.failure",getAddress().getHostAddress(), Integer.valueOf(getPort()), Long.valueOf(0)), ex1);
      throw (ex1);
    }
    
 }
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:35,代码来源:BioSender.java

示例12: prepareSocket

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Performs standard initializations on a newly created socket.
 *
 * @param sock      the socket to prepare
 * @param context   the context for the connection
 * @param params    the parameters from which to prepare the socket
 *
 * @throws IOException      in case of an IO problem
 */
protected void prepareSocket(
        final Socket sock,
        final HttpContext context,
        final HttpParams params) throws IOException {
    sock.setTcpNoDelay(HttpConnectionParams.getTcpNoDelay(params));
    sock.setSoTimeout(HttpConnectionParams.getSoTimeout(params));

    int linger = HttpConnectionParams.getLinger(params);
    if (linger >= 0) {
        sock.setSoLinger(linger > 0, linger);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:DefaultClientConnectionOperator.java

示例13: setSocketOptions

import java.net.Socket; //导入方法依赖的package包/类
/**
 * Set the options for the current socket.
 */
protected boolean setSocketOptions(Socket socket) {
    // Process the connection
    int step = 1;
    try {

        // 1: Set socket options: timeout, linger, etc
        if (soLinger >= 0) { 
            socket.setSoLinger(true, soLinger);
        }
        if (tcpNoDelay) {
            socket.setTcpNoDelay(tcpNoDelay);
        }
        if (soTimeout > 0) {
            socket.setSoTimeout(soTimeout);
        }

        // 2: SSL handshake
        step = 2;
        serverSocketFactory.handshake(socket);

    } catch (Throwable t) {
        if (log.isDebugEnabled()) {
            if (step == 2) {
                log.debug(sm.getString("endpoint.err.handshake"), t);
            } else {
                log.debug(sm.getString("endpoint.err.unexpected"), t);
            }
        }
        // Tell to close the socket
        return false;
    }
    return true;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:37,代码来源:JIoEndpoint.java

示例14: shutdown

import java.net.Socket; //导入方法依赖的package包/类
@Override
public void shutdown() throws IOException {
    final Socket socket = this.socketHolder.getAndSet(null);
    if (socket != null) {
        // force abortive close (RST)
        try {
            socket.setSoLinger(true, 0);
        } catch (final IOException ex) {
        } finally {
            socket.close();
        }
    }
}
 
开发者ID:kalikov,项目名称:lighthouse,代码行数:14,代码来源:BHttpConnectionBase.java

示例15: main

import java.net.Socket; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try (ServerSocket ss = new ServerSocket(0)) {
        final int port = ss.getLocalPort();
        final Phaser phaser = new Phaser(THREADS + 1);
        for (int i=0; i<100; i++) {
            final Socket s = new Socket("localhost", port);
            s.setSoLinger(false, 0);
            try (Socket sa = ss.accept()) {
                sa.setSoLinger(false, 0);
                final InputStream is = s.getInputStream();
                Thread[] threads = new Thread[THREADS];
                for (int j=0; j<THREADS; j++) {
                    threads[j] = new Thread() {
                    public void run() {
                        try {
                            phaser.arriveAndAwaitAdvance();
                            while (is.read() != -1)
                                Thread.sleep(50);
                        } catch (Exception x) {
                            if (!(x instanceof SocketException
                                  && x.getMessage().equalsIgnoreCase("socket closed")))
                                x.printStackTrace();
                            // ok, expect Socket closed
                        }
                    }};
                }
                for (int j=0; j<100; j++)
                    threads[j].start();
                phaser.arriveAndAwaitAdvance();
                s.close();
                for (int j=0; j<100; j++)
                    threads[j].join();
            }
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:Race.java


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