Skip to content

Commit a1eb370

Browse files
Merge pull request #66 from cconlon/getSoTimeout
Correct behavior of WolfSSLSocket.getSoTimeout()
2 parents 72732f0 + 131f78d commit a1eb370

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

src/java/com/wolfssl/provider/jsse/WolfSSLSocket.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ public class WolfSSLSocket extends SSLSocket {
6969
private Socket socket = null;
7070
private boolean autoClose;
7171
private InetSocketAddress address = null;
72-
private int readTimeout = 0;
7372

7473
private WolfSSLInputStream inStream;
7574
private WolfSSLOutputStream outStream;
@@ -1283,7 +1282,6 @@ public void setSoTimeout(int timeout) throws SocketException {
12831282
} else {
12841283
super.setSoTimeout(timeout);
12851284
}
1286-
this.readTimeout = timeout;
12871285
}
12881286

12891287
/**
@@ -1295,7 +1293,11 @@ public void setSoTimeout(int timeout) throws SocketException {
12951293
*/
12961294
@Override
12971295
public int getSoTimeout() throws SocketException {
1298-
return this.readTimeout;
1296+
if (this.socket != null) {
1297+
return this.socket.getSoTimeout();
1298+
} else {
1299+
return super.getSoTimeout();
1300+
}
12991301
}
13001302

13011303
/**
@@ -1324,6 +1326,8 @@ synchronized public void setSSLParameters(SSLParameters params) {
13241326
@Override
13251327
synchronized public void close() throws IOException {
13261328

1329+
int ret;
1330+
13271331
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
13281332
"entered close()");
13291333

@@ -1353,7 +1357,11 @@ synchronized public void close() throws IOException {
13531357
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
13541358
"thread got ioLock (shutdown)");
13551359

1356-
int ret = ssl.shutdownSSL(this.readTimeout);
1360+
if (this.socket != null) {
1361+
ret = ssl.shutdownSSL(this.socket.getSoTimeout());
1362+
} else {
1363+
ret = ssl.shutdownSSL(super.getSoTimeout());
1364+
}
13571365
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
13581366
"ssl.shutdownSSL() ret = " + ret);
13591367

@@ -1655,9 +1663,9 @@ public int read(byte[] b, int off, int len)
16551663
int err;
16561664

16571665
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,
1658-
"ssl.read() socket timeout = " + socket.readTimeout);
1666+
"ssl.read() socket timeout = " + socket.getSoTimeout());
16591667

1660-
ret = ssl.read(data, len, socket.readTimeout);
1668+
ret = ssl.read(data, len, socket.getSoTimeout());
16611669
err = ssl.getError(ret);
16621670

16631671
WolfSSLDebug.log(getClass(), WolfSSLDebug.INFO,

src/test/com/wolfssl/provider/jsse/test/WolfSSLSocketFactoryTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,26 @@ public void testCreateSocket()
280280

281281
/* Socket, String, int, boolean */
282282
s = new Socket(addr, port);
283+
284+
/* Set timeout, to test that createSocket returns it */
285+
int tmpTimeout = 15000;
286+
s.setSoTimeout(tmpTimeout);
287+
283288
ss = (SSLSocket)sf.createSocket(s, addrStr, port, true);
284289
if (ss == null) {
285290
System.out.println("\t\t\t... failed");
286291
fail("SSLSocketFactory.createSocket(SkSib) failed");
287292
return;
288293
}
294+
295+
/* verify getSoTimeout matches set value */
296+
if (ss.getSoTimeout() != tmpTimeout) {
297+
System.out.println("\t\t\t... failed");
298+
fail("SSLSocketFactory.createSocket(SkSib) failed " +
299+
"setSoTimeout check");
300+
return;
301+
}
302+
289303
ss.close();
290304
s.close();
291305

0 commit comments

Comments
 (0)