Java Code Examples for java.net.Socket#getReceiveBufferSize()

The following examples show how to use java.net.Socket#getReceiveBufferSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ObjectReader.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Creates an <code>ObjectReader</code> for a TCP socket
 * @param socket Socket
 */
public ObjectReader(Socket socket) {
    try{
        this.buffer = new XByteBuffer(socket.getReceiveBufferSize(), true);
    }catch ( IOException x ) {
        //unable to get buffer size
        log.warn(sm.getString("objectReader.retrieveFailed.socketReceiverBufferSize"));
        this.buffer = new XByteBuffer(43800,true);
    }
}
 
Example 2
Source File: ObjectReader.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an <code>ObjectReader</code> for a TCP socket
 * @param socket Socket
 */
public ObjectReader(Socket socket) {
    try{
        this.buffer = new XByteBuffer(socket.getReceiveBufferSize(), true);
    }catch ( IOException x ) {
        //unable to get buffer size
        log.warn("Unable to retrieve the socket receiver buffer size, setting to default 43800 bytes.");
        this.buffer = new XByteBuffer(43800,true);
    }
}
 
Example 3
Source File: BufferOptions.java    From netcrusher-java with Apache License 2.0 5 votes vote down vote up
public void checkTcpSocket(Socket socket) throws SocketException {
    final long sizeTotal = count * size;

    if (sizeTotal < socket.getReceiveBufferSize()) {
        LOGGER.warn("Total buffer size {} is less than TCP socket SO_RCVBUF buffer size {}. Increase buffer size",
            sizeTotal, socket.getReceiveBufferSize());
    }

    if (sizeTotal < socket.getSendBufferSize()) {
        LOGGER.warn("Total buffer size {} is less than TCP socket SO_SNDBUF buffer size {}. Increase buffer size",
            sizeTotal, socket.getSendBufferSize());
    }
}
 
Example 4
Source File: ObjectReader.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an <code>ObjectReader</code> for a TCP socket
 * @param socket Socket
 */
public ObjectReader(Socket socket) {
    try{
        this.buffer = new XByteBuffer(socket.getReceiveBufferSize(), true);
    }catch ( IOException x ) {
        //unable to get buffer size
        log.warn("Unable to retrieve the socket receiver buffer size, setting to default 43800 bytes.");
        this.buffer = new XByteBuffer(43800,true);
    }
}
 
Example 5
Source File: WiFiP2PSocket.java    From nfcspy with GNU General Public License v3.0 5 votes vote down vote up
private static void tuneupSocket(Socket skt) throws SocketException {
	skt.setTcpNoDelay(true);
	skt.setTrafficClass(0x04 | 0x10);

	if (skt.getSendBufferSize() < WiFiP2PSocket.BUF_SIZE)
		skt.setSendBufferSize(WiFiP2PSocket.BUF_SIZE);

	if (skt.getReceiveBufferSize() < WiFiP2PSocket.BUF_SIZE)
		skt.setReceiveBufferSize(WiFiP2PSocket.BUF_SIZE);
}
 
Example 6
Source File: RestClient.java    From Doradus with Apache License 2.0 5 votes vote down vote up
public void connect(String host, int port)
throws Exception
{
    disconnect();

    m_host = host;
    m_port = port;

    m_socket = new Socket();
    if (m_socket == null) {
        throw new Exception("Failed to create socket");
    }

    try  {
        if (DISABLE_NAGLES) {
            m_socket.setTcpNoDelay(true);
        }
        if (USE_CUSTOM_BUFFER_SIZE) {
            if (m_socket.getSendBufferSize() < NET_BUFFER_SIZE) {
                m_socket.setSendBufferSize(NET_BUFFER_SIZE);
            }
            if (m_socket.getReceiveBufferSize() < NET_BUFFER_SIZE) {
                m_socket.setReceiveBufferSize(NET_BUFFER_SIZE);
            }
        }

        SocketAddress addr = new InetSocketAddress(m_host, m_port);
        m_socket.connect(addr);

        m_inStream  = new BufferedInputStream(m_socket.getInputStream(), NET_BUFFER_SIZE);
        m_outStream = new BufferedOutputStream(m_socket.getOutputStream(), NET_BUFFER_SIZE);
    }
    catch(Exception ex) {
        disconnect();
        String msg = "Failed to connect to " + m_host + ":" + m_port;
        throw new Exception(msg, ex);
    }
}