@@ -179,37 +179,31 @@ protected TNonblockingSSLSocket(String host, int port, int timeout, SSLContext s
179179 isHandshakeCompleted = false ;
180180 }
181181
182- /**
183- * Register the new SocketChannel with our Selector, indicating we'd like to be notified when it's
184- * ready for I/O.
185- *
186- * @param selector
187- * @return the selection key for this socket.
188- */
182+ /** {@inheritDoc} */
183+ @ Override
189184 public SelectionKey registerSelector (Selector selector , int interests ) throws IOException {
190185 selectionKey = super .registerSelector (selector , interests );
191186 return selectionKey ;
192187 }
193188
194- /** Checks whether the socket is connected. */
189+ /** {@inheritDoc} */
190+ @ Override
195191 public boolean isOpen () {
196192 // isConnected() does not return false after close(), but isOpen() does
197193 return super .isOpen () && isHandshakeCompleted ;
198194 }
199195
200- /** Do not call, the implementation provides its own lazy non-blocking connect. */
196+ /** {@inheritDoc} */
197+ @ Override
201198 public void open () throws TTransportException {
202199 throw new RuntimeException ("open() is not implemented for TNonblockingSSLSocket" );
203200 }
204201
205- /** Perform a nonblocking read into buffer. */
206- public int read (ByteBuffer buffer ) throws TTransportException {
202+ /** {@inheritDoc} */
203+ @ Override
204+ public synchronized int read (ByteBuffer buffer ) throws TTransportException {
207205 int numBytes = buffer .limit ();
208206 while (decodedBytes .remaining () < numBytes ) {
209- HandshakeStatus hs = sslEngine_ .getHandshakeStatus ();
210- if (hs == HandshakeStatus .FINISHED )
211- throw new TTransportException (
212- TTransportException .UNKNOWN , "Read operation is terminated. Handshake is completed" );
213207 try {
214208 if (doUnwrap () == -1 ) {
215209 throw new IOException ("Unable to read " + numBytes + " bytes" );
@@ -244,8 +238,9 @@ public int read(ByteBuffer buffer) throws TTransportException {
244238 return numBytes ;
245239 }
246240
247- /** Perform a nonblocking write of the data in buffer; */
248- public int write (ByteBuffer buffer ) throws TTransportException {
241+ /** {@inheritDoc} */
242+ @ Override
243+ public synchronized int write (ByteBuffer buffer ) throws TTransportException {
249244 int numBytes = 0 ;
250245
251246 if (buffer .position () > 0 ) buffer .flip ();
@@ -273,13 +268,15 @@ public int write(ByteBuffer buffer) throws TTransportException {
273268 return numBytes ;
274269 }
275270
276- /** Closes the socket. */
271+ /** {@inheritDoc} */
272+ @ Override
277273 public void close () {
278274 sslEngine_ .closeOutbound ();
279275 super .close ();
280276 }
281277
282278 /** {@inheritDoc} */
279+ @ Override
283280 public boolean startConnect () throws IOException {
284281 if (this .isOpen ()) {
285282 return true ;
@@ -289,6 +286,7 @@ public boolean startConnect() throws IOException {
289286 }
290287
291288 /** {@inheritDoc} */
289+ @ Override
292290 public boolean finishConnect () throws IOException {
293291 return super .finishConnect () && doHandShake ();
294292 }
@@ -333,15 +331,7 @@ private synchronized boolean doTask() {
333331 runnable .run ();
334332 }
335333 HandshakeStatus hs = sslEngine_ .getHandshakeStatus ();
336- if (hs == HandshakeStatus .NEED_TASK ) {
337- try {
338- throw new TTransportException (
339- TTransportException .UNKNOWN , "handshake shouldn't need additional tasks" );
340- } catch (TTransportException e ) {
341- return false ;
342- }
343- }
344- return true ;
334+ return hs != HandshakeStatus .NEED_TASK ;
345335 }
346336
347337 private synchronized int doUnwrap () throws IOException {
0 commit comments