本文整理匯總了Java中java.net.Socket.setSendBufferSize方法的典型用法代碼示例。如果您正苦於以下問題:Java Socket.setSendBufferSize方法的具體用法?Java Socket.setSendBufferSize怎麽用?Java Socket.setSendBufferSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.net.Socket
的用法示例。
在下文中一共展示了Socket.setSendBufferSize方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
示例2: 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());
}
示例3: 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);
}
}
示例4: createSocketForPipeline
import java.net.Socket; //導入方法依賴的package包/類
/**
* Create a socket for a write pipeline
* @param first the first datanode
* @param length the pipeline length
* @param client client
* @return the socket connected to the first datanode
*/
static Socket createSocketForPipeline(final DatanodeInfo first,
final int length, final DFSClient client) throws IOException {
final String dnAddr = first.getXferAddr(
client.getConf().connectToDnViaHostname);
if (DFSClient.LOG.isDebugEnabled()) {
DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
}
final InetSocketAddress isa = NetUtils.createSocketAddr(dnAddr);
final Socket sock = client.socketFactory.createSocket();
final int timeout = client.getDatanodeReadTimeout(length);
NetUtils.connect(sock, isa, client.getRandomLocalInterfaceAddr(), client.getConf().socketTimeout);
sock.setSoTimeout(timeout);
sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE);
if(DFSClient.LOG.isDebugEnabled()) {
DFSClient.LOG.debug("Send buf size " + sock.getSendBufferSize());
}
return sock;
}
示例5: 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);
}
}
示例6: NodeReceiveThread
import java.net.Socket; //導入方法依賴的package包/類
public NodeReceiveThread(Socket sk) {
super();
this.sk = sk;
try {
sk.setSendBufferSize(1024*1024);
sk.setReceiveBufferSize(1024*1024);
out = new ObjectOutputStream(sk.getOutputStream());
in = new ObjectInputStream(sk.getInputStream());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();logger.error("Exception",e);
}
}
示例7: configureSocket
import java.net.Socket; //導入方法依賴的package包/類
private void configureSocket(Socket socket) throws SocketException {
socket.setTcpNoDelay(TCP_NO_DELAY.get(settings));
ByteSizeValue tcpSendBufferSize = TCP_SEND_BUFFER_SIZE.get(settings);
if (tcpSendBufferSize.getBytes() > 0) {
socket.setSendBufferSize(tcpSendBufferSize.bytesAsInt());
}
ByteSizeValue tcpReceiveBufferSize = TCP_RECEIVE_BUFFER_SIZE.get(settings);
if (tcpReceiveBufferSize.getBytes() > 0) {
socket.setReceiveBufferSize(tcpReceiveBufferSize.bytesAsInt());
}
socket.setReuseAddress(TCP_REUSE_ADDRESS.get(settings));
}
示例8: 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);
}
}
示例9: configureSocket
import java.net.Socket; //導入方法依賴的package包/類
/**
* Configures socket properties based on properties from the connection
* (tcpNoDelay, snd/rcv buf, traffic class, etc).
*
* @param props
* @throws SocketException
* @throws IOException
*/
private void configureSocket(Socket sock, Properties props) throws SocketException, IOException {
sock.setTcpNoDelay(Boolean.valueOf(props.getProperty(TCP_NO_DELAY_PROPERTY_NAME, TCP_NO_DELAY_DEFAULT_VALUE)).booleanValue());
String keepAlive = props.getProperty(TCP_KEEP_ALIVE_PROPERTY_NAME, TCP_KEEP_ALIVE_DEFAULT_VALUE);
if (keepAlive != null && keepAlive.length() > 0) {
sock.setKeepAlive(Boolean.valueOf(keepAlive).booleanValue());
}
int receiveBufferSize = Integer.parseInt(props.getProperty(TCP_RCV_BUF_PROPERTY_NAME, TCP_RCV_BUF_DEFAULT_VALUE));
if (receiveBufferSize > 0) {
sock.setReceiveBufferSize(receiveBufferSize);
}
int sendBufferSize = Integer.parseInt(props.getProperty(TCP_SND_BUF_PROPERTY_NAME, TCP_SND_BUF_DEFAULT_VALUE));
if (sendBufferSize > 0) {
sock.setSendBufferSize(sendBufferSize);
}
int trafficClass = Integer.parseInt(props.getProperty(TCP_TRAFFIC_CLASS_PROPERTY_NAME, TCP_TRAFFIC_CLASS_DEFAULT_VALUE));
if (trafficClass > 0) {
sock.setTrafficClass(trafficClass);
}
}
示例10: listen
import java.net.Socket; //導入方法依賴的package包/類
public void listen() throws Exception {
if (doListen()) {
log.warn("ServerSocket already started");
return;
}
setListen(true);
while ( doListen() ) {
Socket socket = null;
if ( getTaskPool().available() < 1 ) {
if ( log.isWarnEnabled() )
log.warn("All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
}
BioReplicationTask task = (BioReplicationTask)getTaskPool().getRxTask();
if ( task == null ) continue; //should never happen
try {
socket = serverSocket.accept();
}catch ( Exception x ) {
if ( doListen() ) throw x;
}
if ( !doListen() ) {
task.setDoRun(false);
task.serviceSocket(null,null);
getExecutor().execute(task);
break; //regular shutdown
}
if ( socket == null ) continue;
socket.setReceiveBufferSize(getRxBufSize());
socket.setSendBufferSize(getTxBufSize());
socket.setTcpNoDelay(getTcpNoDelay());
socket.setKeepAlive(getSoKeepAlive());
socket.setOOBInline(getOoBInline());
socket.setReuseAddress(getSoReuseAddress());
socket.setSoLinger(getSoLingerOn(),getSoLingerTime());
socket.setSoTimeout(getTimeout());
ObjectReader reader = new ObjectReader(socket);
task.serviceSocket(socket,reader);
getExecutor().execute(task);
}//while
}
示例11: create
import java.net.Socket; //導入方法依賴的package包/類
@Override
public HttpClientConnection create(final HttpHost host) throws IOException {
final String scheme = host.getSchemeName();
Socket socket = null;
if ("http".equalsIgnoreCase(scheme)) {
socket = this.plainfactory != null ? this.plainfactory.createSocket() :
new Socket();
} if ("https".equalsIgnoreCase(scheme)) {
socket = (this.sslfactory != null ? this.sslfactory :
SSLSocketFactory.getDefault()).createSocket();
}
if (socket == null) {
throw new IOException(scheme + " scheme is not supported");
}
final String hostname = host.getHostName();
int port = host.getPort();
if (port == -1) {
if (host.getSchemeName().equalsIgnoreCase("http")) {
port = 80;
} else if (host.getSchemeName().equalsIgnoreCase("https")) {
port = 443;
}
}
socket.setSoTimeout(this.sconfig.getSoTimeout());
if (this.sconfig.getSndBufSize() > 0) {
socket.setSendBufferSize(this.sconfig.getSndBufSize());
}
if (this.sconfig.getRcvBufSize() > 0) {
socket.setReceiveBufferSize(this.sconfig.getRcvBufSize());
}
socket.setTcpNoDelay(this.sconfig.isTcpNoDelay());
final int linger = this.sconfig.getSoLinger();
if (linger >= 0) {
socket.setSoLinger(true, linger);
}
socket.setKeepAlive(this.sconfig.isSoKeepAlive());
socket.connect(new InetSocketAddress(hostname, port), this.connectTimeout);
return this.connFactory.createConnection(socket);
}
示例12: 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);
}
}
示例13: listen
import java.net.Socket; //導入方法依賴的package包/類
public void listen() throws Exception {
if (doListen()) {
log.warn("ServerSocket already started");
return;
}
setListen(true);
while (doListen()) {
Socket socket = null;
if (getTaskPool().available() < 1) {
if (log.isWarnEnabled())
log.warn(
"All BIO server replication threads are busy, unable to handle more requests until a thread is freed up.");
}
BioReplicationTask task = (BioReplicationTask) getTaskPool().getRxTask();
if (task == null)
continue; // should never happen
try {
socket = serverSocket.accept();
} catch (Exception x) {
if (doListen())
throw x;
}
if (!doListen()) {
task.setDoRun(false);
task.serviceSocket(null, null);
getExecutor().execute(task);
break; // regular shutdown
}
if (socket == null)
continue;
socket.setReceiveBufferSize(getRxBufSize());
socket.setSendBufferSize(getTxBufSize());
socket.setTcpNoDelay(getTcpNoDelay());
socket.setKeepAlive(getSoKeepAlive());
socket.setOOBInline(getOoBInline());
socket.setReuseAddress(getSoReuseAddress());
socket.setSoLinger(getSoLingerOn(), getSoLingerTime());
socket.setSoTimeout(getTimeout());
ObjectReader reader = new ObjectReader(socket);
task.serviceSocket(socket, reader);
getExecutor().execute(task);
} // while
}
示例14: process
import java.net.Socket; //導入方法依賴的package包/類
protected void
process(
int local_port,
TransportHelperFilter filter )
{
SocketChannel channel = ((TCPTransportHelper)filter.getHelper()).getSocketChannel();
Socket socket = channel.socket();
//set advanced socket options
try {
int so_sndbuf_size = COConfigurationManager.getIntParameter( "network.tcp.socket.SO_SNDBUF" );
if( so_sndbuf_size > 0 ) socket.setSendBufferSize( so_sndbuf_size );
String ip_tos = COConfigurationManager.getStringParameter( "network.tcp.socket.IPDiffServ" );
if( ip_tos.length() > 0 ) socket.setTrafficClass( Integer.decode( ip_tos ).intValue() );
}
catch( Throwable t ) {
t.printStackTrace();
}
AEProxyAddressMapper.AppliedPortMapping applied_mapping = proxy_address_mapper.applyPortMapping( socket.getInetAddress(), socket.getPort());
InetSocketAddress tcp_address = applied_mapping.getAddress();
ConnectionEndpoint co_ep = new ConnectionEndpoint(tcp_address);
Map<String,Object> properties = applied_mapping.getProperties();
if ( properties != null ){
co_ep.addProperties( properties );
}
ProtocolEndpointTCP pe_tcp = (ProtocolEndpointTCP)ProtocolEndpointFactory.createEndpoint( ProtocolEndpoint.PROTOCOL_TCP, co_ep, tcp_address );
Transport transport = new TCPTransportImpl( pe_tcp, filter );
incoming_manager.addConnection( local_port, filter, transport );
}