本文整理了Java中java.net.Socket.setSendBufferSize()
方法的一些代码示例,展示了Socket.setSendBufferSize()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Socket.setSendBufferSize()
方法的具体详情如下:
包路径:java.net.Socket
类名称:Socket
方法名:setSendBufferSize
[英]Sets this socket's SocketOptions#SO_SNDBUF.
[中]设置此套接字的SocketOptions#SO#u SNDBUF。
代码示例来源:origin: apache/kafka
private void configureSocketChannel(SocketChannel socketChannel, int sendBufferSize, int receiveBufferSize)
throws IOException {
socketChannel.configureBlocking(false);
Socket socket = socketChannel.socket();
socket.setKeepAlive(true);
if (sendBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE)
socket.setSendBufferSize(sendBufferSize);
if (receiveBufferSize != Selectable.USE_DEFAULT_BUFFER_SIZE)
socket.setReceiveBufferSize(receiveBufferSize);
socket.setTcpNoDelay(true);
}
代码示例来源:origin: wildfly/wildfly
static void set(Socket socket) throws SocketException {
socket.setTcpNoDelay(true);
socket.setReceiveBufferSize(20000000);
socket.setSendBufferSize(10000000);
}
代码示例来源:origin: mpetazzoni/ttorrent
public static void setBuffersSizeIfNecessary(SocketChannel socketChannel, int sendBufferSize, int receiveBufferSize) throws IOException {
final Socket socket = socketChannel.socket();
if (sendBufferSize > 0) {
socket.setSendBufferSize(sendBufferSize);
}
if (receiveBufferSize > 0) {
socket.setReceiveBufferSize(receiveBufferSize);
}
}
}
代码示例来源:origin: voldemort/voldemort
+ socketChannel.socket().getPort());
socketChannel.socket().setTcpNoDelay(true);
socketChannel.socket().setReuseAddress(true);
socketChannel.socket().setKeepAlive(socketKeepAlive);
socketChannel.socket().setSendBufferSize(socketBufferSize);
代码示例来源:origin: org.postgresql/postgresql
newStream.getSocket().setKeepAlive(requireTCPKeepAlive);
newStream.getSocket().setReceiveBufferSize(receiveBufferSize);
} else {
LOGGER.log(Level.WARNING, "Ignore invalid value for receiveBufferSize: {0}", receiveBufferSize);
if (sendBufferSize > -1) {
if (sendBufferSize > 0) {
newStream.getSocket().setSendBufferSize(sendBufferSize);
} else {
LOGGER.log(Level.WARNING, "Ignore invalid value for sendBufferSize: {0}", sendBufferSize);
代码示例来源:origin: voldemort/voldemort
private void configureSocket(Socket socket) throws SocketException {
socket.setTcpNoDelay(true);
socket.setSendBufferSize(this.socketBufferSize);
if(socket.getReceiveBufferSize() != this.socketBufferSize)
logger.debug("Requested socket receive buffer size was " + this.socketBufferSize
+ " bytes but actual size is " + socket.getReceiveBufferSize() + " bytes.");
if(socket.getSendBufferSize() != this.socketBufferSize)
logger.debug("Requested socket send buffer size was " + this.socketBufferSize
+ " bytes but actual size is " + socket.getSendBufferSize() + " bytes.");
}
代码示例来源:origin: apache/ignite
@Nullable @Override public Object call() throws Exception {
ServerSocket srvSock = null;
Socket sock = null;
try {
srvSock = new ServerSocket(60000, 0, addr);
sock = srvSock.accept();
X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
sock.setKeepAlive(true);
sock.setSoTimeout(2000);
sock.setSendBufferSize(256 * 1024);
X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
", sndBuf=" + sock.getSendBufferSize() + ", rcvBuf=" + sock.getReceiveBufferSize() + ']');
while (!done.get())
X.println("Read from socket: " + sock.getInputStream().read());
return null;
}
finally {
U.closeQuiet(srvSock);
U.closeQuiet(sock);
}
}
},
代码示例来源:origin: libgdx/libgdx
private void applyHints (SocketHints hints) {
if (hints != null) {
try {
socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency,
hints.performancePrefBandwidth);
socket.setTrafficClass(hints.trafficClass);
socket.setTcpNoDelay(hints.tcpNoDelay);
socket.setKeepAlive(hints.keepAlive);
socket.setSendBufferSize(hints.sendBufferSize);
socket.setReceiveBufferSize(hints.receiveBufferSize);
socket.setSoLinger(hints.linger, hints.lingerDuration);
socket.setSoTimeout(hints.socketTimeout);
} catch (Exception e) {
throw new GdxRuntimeException("Error setting socket hints.", e);
}
}
}
代码示例来源:origin: rapidoid/rapidoid
private void configureSocket(SocketChannel socketChannel) throws IOException {
socketChannel.configureBlocking(false);
Socket socket = socketChannel.socket();
socket.setTcpNoDelay(noDelay);
socket.setReceiveBufferSize(bufSize);
socket.setSendBufferSize(bufSize);
socket.setReuseAddress(true);
}
代码示例来源:origin: wildfly/wildfly
socket.setKeepAlive(keepAlive != 0);
socket.setOOBInline(oobInline != 0);
socket.setTcpNoDelay(tcpNoDelay != 0);
final int sendBuffer = this.sendBuffer;
if (sendBuffer > 0) socket.setSendBufferSize(sendBuffer);
final WorkerThread ioThread = worker.getIoThread(hash);
final SelectionKey selectionKey = ioThread.registerChannel(accepted);
代码示例来源:origin: ggrandes/bouncer
public static void setupSocket(final Socket sock) throws SocketException {
sock.setKeepAlive(true);
sock.setReuseAddress(true);
sock.setSoTimeout(Constants.READ_TIMEOUT);
sock.setSendBufferSize(Math.max(sock.getSendBufferSize(), Constants.BUFFER_LEN * Constants.IO_BUFFERS));
sock.setReceiveBufferSize(Math.max(sock.getReceiveBufferSize(), Constants.BUFFER_LEN
* Constants.IO_BUFFERS));
}
代码示例来源:origin: wildfly/wildfly
protected Connection getConnection(SocketAddress dest) throws Exception {
Connection conn=connections.get(dest);
if(conn != null)
return conn;
Socket dest_sock=new Socket();
dest_sock.setSendBufferSize(send_buf_size);
dest_sock.setReceiveBufferSize(recv_buf_size);
dest_sock.connect(dest);
Connection c=connections.putIfAbsent(dest, conn=new Connection(dest_sock).start());
if(c != null) {
Util.close(conn);
return c;
}
return conn;
}
代码示例来源:origin: peter-lawrey/Java-Chronicle
public Handler(@NotNull SocketChannel socket) throws SocketException {
this.socket = socket;
socket.socket().setSendBufferSize(256 * 1024);
socket.socket().setTcpNoDelay(true);
}
代码示例来源:origin: apache/ignite
@Nullable @Override public Object call() throws Exception {
Socket sock = null;
try {
sock = new Socket(addr, 60000);
X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
sock.setKeepAlive(true);
sock.setSoTimeout(2000);
sock.setSendBufferSize(256 * 1024);
X.println("Socket [timeout=" + sock.getSoTimeout() + ", linger=" + sock.getSoLinger() +
", sndBuf=" + sock.getSendBufferSize() + ", sndBuf=" + sock.getSendBufferSize() + ']');
int i = 0;
while (!done.get()) {
sock.getOutputStream().write(++i);
sock.getOutputStream().flush();
X.println("Wrote to socket: " + i);
X.println("Socket connected: " + sock.isConnected());
X.println("Socket keep alive: " + sock.getKeepAlive());
U.sleep(1000);
}
return null;
}
finally {
U.closeQuiet(sock);
}
}
},
代码示例来源:origin: libgdx/libgdx
private void applyHints (SocketHints hints) {
if (hints != null) {
try {
socket.setPerformancePreferences(hints.performancePrefConnectionTime, hints.performancePrefLatency,
hints.performancePrefBandwidth);
socket.setTrafficClass(hints.trafficClass);
socket.setTcpNoDelay(hints.tcpNoDelay);
socket.setKeepAlive(hints.keepAlive);
socket.setSendBufferSize(hints.sendBufferSize);
socket.setReceiveBufferSize(hints.receiveBufferSize);
socket.setSoLinger(hints.linger, hints.lingerDuration);
socket.setSoTimeout(hints.socketTimeout);
} catch (Exception e) {
throw new GdxRuntimeException("Error setting socket hints.", e);
}
}
}
代码示例来源:origin: rapidoid/rapidoid
private void configureSocket(SocketChannel socketChannel) throws IOException {
socketChannel.configureBlocking(false);
Socket socket = socketChannel.socket();
socket.setTcpNoDelay(noDelay);
socket.setReceiveBufferSize(bufSize);
socket.setSendBufferSize(bufSize);
socket.setReuseAddress(true);
}
代码示例来源:origin: wildfly/wildfly
socket.setKeepAlive(keepAlive != 0);
socket.setOOBInline(oobInline != 0);
socket.setTcpNoDelay(tcpNoDelay != 0);
final int sendBuffer = this.sendBuffer;
if (sendBuffer > 0) socket.setSendBufferSize(sendBuffer);
final WorkerThread ioThread = worker.getIoThread(hash);
ok = true;
代码示例来源:origin: com.orientechnologies/orientdb-enterprise
public OChannelTextServer(final Socket iSocket, final OContextConfiguration iConfiguration) throws IOException {
super(iSocket, iConfiguration);
socket.setKeepAlive(true);
socket.setPerformancePreferences(1, 2, 0);
socket.setSendBufferSize(socketBufferSize);
socket.setReceiveBufferSize(socketBufferSize);
inStream = new BufferedInputStream(socket.getInputStream(), socketBufferSize);
outStream = new BufferedOutputStream(socket.getOutputStream(), socketBufferSize);
}
}
代码示例来源:origin: wildfly/wildfly
public void init(String local_addr, String remote_addr, int local_port, int remote_port) throws Exception {
local=new InetSocketAddress(local_addr, local_port);
remote=new InetSocketAddress(remote_addr, remote_port);
srv_sock=Util.createServerSocket(new DefaultSocketFactory(), "server", local.getAddress(), local.getPort(), local.getPort());
System.out.println("Listening on " + srv_sock.getLocalSocketAddress());
acceptor=new Acceptor();
acceptor.start();
sock=new Socket();
//sock.bind(local);
sock.setSendBufferSize(SOCK_SEND_BUF_SIZE);
sock.setReceiveBufferSize(SOCK_RECV_BUF_SIZE);
try {
sock.connect(remote);
output=new DataOutputStream(new BufferedOutputStream(sock.getOutputStream()));
System.out.println("Connected to " + sock.getRemoteSocketAddress());
}
catch(Throwable t) {
System.out.println("Failed connecting to " + remote + ": will only act as server");
}
}
代码示例来源:origin: apache/geode
public ServerQueueStatus connect(EndpointManager endpointManager, ServerLocation location,
ClientSideHandshake handshake, int socketBufferSize, int handshakeTimeout, int readTimeout,
CommunicationMode communicationMode, GatewaySender sender, SocketCreator sc)
throws IOException {
theSocket = sc.connectForClient(location.getHostName(), location.getPort(), handshakeTimeout,
socketBufferSize);
theSocket.setTcpNoDelay(true);
theSocket.setSendBufferSize(socketBufferSize);
// Verify buffer sizes
verifySocketBufferSize(socketBufferSize, theSocket.getReceiveBufferSize(), "receive");
verifySocketBufferSize(socketBufferSize, theSocket.getSendBufferSize(), "send");
theSocket.setSoTimeout(handshakeTimeout);
out = theSocket.getOutputStream();
in = theSocket.getInputStream();
this.status = handshake.handshakeWithServer(this, location, communicationMode);
commBuffer = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket);
if (sender != null) {
commBufferForAsyncRead = ServerConnection.allocateCommBuffer(socketBufferSize, theSocket);
}
theSocket.setSoTimeout(readTimeout);
endpoint = endpointManager.referenceEndpoint(location, this.status.getMemberId());
this.connectFinished = true;
this.endpoint.getStats().incConnections(1);
return status;
}
内容来源于网络,如有侵权,请联系作者删除!