@@ -1130,25 +1130,29 @@ synchronized public void startHandshake() throws IOException {
11301130 "entered startHandshake()" );
11311131
11321132 synchronized (handshakeLock ) {
1133- if (handshakeInitCalled == true || handshakeComplete == true ) {
1134- /* handshake already started or finished */
1133+ if (handshakeComplete == true ) {
1134+ /* handshake already finished */
11351135 return ;
11361136 }
1137+
1138+ if (handshakeInitCalled == false ) {
1139+ /* will throw SSLHandshakeException if session creation is
1140+ not allowed */
1141+ EngineHelper .initHandshake ();
1142+ handshakeInitCalled = true ;
1143+ }
11371144 }
11381145
11391146 synchronized (ioLock ) {
11401147 WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
11411148 "thread got ioLock (handshake)" );
11421149
1143- /* will throw SSLHandshakeException if session creation is
1144- not allowed */
1145- EngineHelper .initHandshake ();
1146- handshakeInitCalled = true ;
1147-
11481150 try {
11491151 ret = EngineHelper .doHandshake (0 , this .getSoTimeout ());
11501152 } catch (SocketTimeoutException e ) {
1151- throw new IOException (e );
1153+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1154+ "got socket timeout in doHandshake()" );
1155+ throw e ;
11521156 }
11531157
11541158 WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
@@ -1781,8 +1785,15 @@ public int read(byte[] b, int off, int len)
17811785 }
17821786
17831787 /* do handshake if not completed yet, handles synchronization */
1784- if (socket .handshakeComplete == false ) {
1785- socket .startHandshake ();
1788+ try {
1789+ /* do handshake if not completed yet, handles synchronization */
1790+ if (socket .handshakeComplete == false ) {
1791+ socket .startHandshake ();
1792+ }
1793+ } catch (SocketTimeoutException e ) {
1794+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1795+ "got socket timeout in read()" );
1796+ throw e ;
17861797 }
17871798
17881799 if (b .length == 0 || len == 0 ) {
@@ -1899,9 +1910,15 @@ public void write(byte[] b, int off, int len) throws IOException {
18991910 }
19001911 }
19011912
1902- /* do handshake if not completed yet, handles synchronization */
1903- if (socket .handshakeComplete == false ) {
1904- socket .startHandshake ();
1913+ try {
1914+ /* do handshake if not completed yet, handles synchronization */
1915+ if (socket .handshakeComplete == false ) {
1916+ socket .startHandshake ();
1917+ }
1918+ } catch (SocketTimeoutException e ) {
1919+ WolfSSLDebug .log (getClass (), WolfSSLDebug .INFO ,
1920+ "got socket timeout in write()" );
1921+ throw e ;
19051922 }
19061923
19071924 if (off < 0 || len < 0 || (off + len ) > b .length ) {
0 commit comments