Skip to content

Commit

Permalink
Support Connection get/setNetworkTimeout().
Browse files Browse the repository at this point in the history
  • Loading branch information
brettwooldridge committed Apr 14, 2017
1 parent 598a3b4 commit 9a20061
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,26 @@ final void close() {

packetLogger.finest(logMsg.toString());
}

/**
* Get the current socket SO_TIMEOUT value.
*
* @return the current socket timeout value
* @throws IOException thrown if the socket timeout cannot be read
*/
final int getNetworkTimeout() throws IOException {
return tcpSocket.getSoTimeout();
}

/**
* Set the socket SO_TIMEOUT value.
*
* @param timeout the socket timeout in milliseconds
* @throws IOException thrown if the socket timeout cannot be set
*/
final void setNetworkTimeout(int timeout) throws IOException {
tcpSocket.setSoTimeout(timeout);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4636,14 +4636,42 @@ public void setHoldability(int holdability) throws SQLServerException {
}

public int getNetworkTimeout() throws SQLException {
// this operation is not supported
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
loggerExternal.entering(getClassNameLogging(), "getNetworkTimeout");

checkClosed();

int timeout = 0;
try {
timeout = tdsChannel.getNetworkTimeout();
}
catch (IOException ioe) {
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, ioe.getMessage(), ioe);
}

loggerExternal.exiting(getClassNameLogging(), "getNetworkTimeout");
return timeout;
}

public void setNetworkTimeout(Executor executor,
int timeout) throws SQLException {
// this operation is not supported
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
loggerExternal.entering(getClassNameLogging(), "setNetworkTimeout", timeout);

if (timeout < 0) {
MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSocketTimeout"));
Object[] msgArgs = {timeout};
SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
}

checkClosed();

try {
tdsChannel.setNetworkTimeout(timeout);
}
catch (IOException ioe) {
terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, ioe.getMessage(), ioe);
}

loggerExternal.exiting(getClassNameLogging(), "setNetworkTimeout");
}

public String getSchema() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,14 +554,14 @@ public PreparedStatement prepareStatement(String sql,
}

public int getNetworkTimeout() throws SQLException {
// The driver currently does not implement the optional JDBC APIs
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
checkClosed();
return wrappedConnection.getNetworkTimeout();
}

public void setNetworkTimeout(Executor executor,
int timeout) throws SQLException {
// The driver currently does not implement the optional JDBC APIs
throw new SQLFeatureNotSupportedException(SQLServerException.getErrString("R_notSupported"));
checkClosed();
wrappedConnection.setNetworkTimeout(executor, timeout);
}

public String getSchema() throws SQLException {
Expand Down

0 comments on commit 9a20061

Please sign in to comment.