Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Connection get/setNetworkTimeout(). #253

Merged
merged 1 commit into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This misses the requirement to check for permission SQLPermission.setNetworkTimeout

Copy link
Contributor

@xiangyushawn xiangyushawn Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrotteveel Thank you for pointing it out. I created a PR #255 for it. Could you or @brettwooldridge review it and see if you are satisfied with it? Thank you.

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