Index: org/postgresql/core/v3/ConnectionFactoryImpl.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/core/v3/ConnectionFactoryImpl.java,v retrieving revision 1.25 diff -c -r1.25 ConnectionFactoryImpl.java *** org/postgresql/core/v3/ConnectionFactoryImpl.java 19 Apr 2011 01:15:21 -0000 1.25 --- org/postgresql/core/v3/ConnectionFactoryImpl.java 21 Apr 2011 14:03:29 -0000 *************** *** 93,98 **** --- 93,137 ---- // Enable TCP keep-alive probe if required. newStream.getSocket().setKeepAlive(requireTCPKeepAlive); + // Try to set SO_SNDBUF and SO_RECVBUF socket options, if requested. + // If receive_buffer_size and send_buffer_size are set to a value greater + // than 0, adjust. -1 means use the system default, 0 is ignored since not + // supported. + + // Set SO_RECVBUF read buffer size + String receiveBufferSizeProperty = info.getProperty("receive_buffer_size", "-1"); + try { + int receiveBufferSize = Integer.parseInt(receiveBufferSizeProperty); + if (receiveBufferSize > -1) { + // value of 0 not a valid buffer size value + if (receiveBufferSize > 0) { + newStream.getSocket().setReceiveBufferSize(receiveBufferSize); + } else { + logger.info("Ignore invalid value for receive_buffer_size: " + receiveBufferSize); + } + } + } catch (NumberFormatException nfe) { + logger.info("Couldn't parse receive_buffer_size value: " + receiveBufferSizeProperty); + } + + // Set SO_SNDBUF write buffer size + String sendBufferSizeProperty = info.getProperty("send_buffer_size", "-1"); + try { + int sendBufferSize = Integer.parseInt(sendBufferSizeProperty); + if (sendBufferSize > -1) { + if (sendBufferSize > 0) { + newStream.getSocket().setSendBufferSize(sendBufferSize); + } else { + logger.info("Ignore invalid value for send_buffer_size: " + sendBufferSize); + } + } + } catch (NumberFormatException nfe) { + logger.info("Couldn't parse send_buffer_size value: " + sendBufferSizeProperty); + } + + logger.debug("Receive Buffer Size is " + newStream.getSocket().getReceiveBufferSize()); + logger.debug("Send Buffer Size is " + newStream.getSocket().getSendBufferSize()); + // Construct and send a startup packet. String[][] params = { { "user", user }, Index: org/postgresql/ds/common/BaseDataSource.java =================================================================== RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/ds/common/BaseDataSource.java,v retrieving revision 1.22 diff -c -r1.22 BaseDataSource.java *** org/postgresql/ds/common/BaseDataSource.java 25 Dec 2010 22:57:23 -0000 1.22 --- org/postgresql/ds/common/BaseDataSource.java 21 Apr 2011 14:03:30 -0000 *************** *** 53,58 **** --- 53,60 ---- private int unknownLength = Integer.MAX_VALUE; private int loginTimeout = 0; // in seconds private int socketTimeout = 0; // in seconds + private int receive_buffer_size = -1; // off (-1), not in use + private int send_buffer_size = -1; // off (-1), not in use private boolean ssl = false; private String sslfactory; private boolean tcpKeepAlive = false; *************** *** 292,297 **** --- 294,315 ---- } /** + * Sets the write buffer size of TCP/IP socket. + */ + public void setReceiveBufferSize(int nbytes) + { + this.receive_buffer_size = nbytes; + } + + /** + * Sets the send buffer size of TCP/IP socket. + */ + public void setSendBufferSize(int nbytes) + { + this.send_buffer_size = nbytes; + } + + /** * Gets the default threshold for enabling server-side prepare. * * @see #setPrepareThreshold(int) *************** *** 424,429 **** --- 442,450 ---- sb.append(applicationName); } + sb.append("&receive_buffer_size=").append(receive_buffer_size); + sb.append("&send_buffer_size=").append(send_buffer_size); + return sb.toString(); } *************** *** 473,478 **** --- 494,502 ---- ref.add(new StringRefAddr("protocolVersion", Integer.toString(protocolVersion))); ref.add(new StringRefAddr("ApplicationName", applicationName)); + ref.add(new StringRefAddr("receive_buffer_size", Integer.toString(receive_buffer_size))); + ref.add(new StringRefAddr("send_buffer_size", Integer.toString(send_buffer_size))); + return ref; } *************** *** 494,499 **** --- 518,525 ---- out.writeInt(logLevel); out.writeInt(protocolVersion); out.writeObject(applicationName); + out.writeInt(receive_buffer_size); + out.writeInt(send_buffer_size); } protected void readBaseObject(ObjectInputStream in) throws IOException, ClassNotFoundException *************** *** 513,519 **** compatible = (String)in.readObject(); logLevel = in.readInt(); protocolVersion = in.readInt(); ! applicationName = (String)in.readObject(); } public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException { --- 539,547 ---- compatible = (String)in.readObject(); logLevel = in.readInt(); protocolVersion = in.readInt(); ! applicationName = (String)in.readObject(); ! receive_buffer_size = in.readInt(); ! send_buffer_size = in.readInt(); } public void initializeFrom(BaseDataSource source) throws IOException, ClassNotFoundException {