1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
|
// **********************************************************************
//
// Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************
package IceSSL;
import java.nio.*;
import javax.net.ssl.*;
import javax.net.ssl.SSLEngineResult.*;
final class TransceiverI implements IceInternal.Transceiver
{
public java.nio.channels.SelectableChannel
fd()
{
assert(_fd != null);
return _fd;
}
public int
initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer)
{
try
{
if(_state == StateNeedConnect)
{
_state = StateConnectPending;
return IceInternal.SocketOperation.Connect;
}
else if(_state == StateConnectPending)
{
IceInternal.Network.doFinishConnect(_fd);
_desc = IceInternal.Network.fdToString(_fd, _proxy, _addr);
if(_proxy != null)
{
//
// Prepare the read & write buffers in advance.
//
_proxy.beginWriteConnectRequest(_addr, writeBuffer);
_proxy.beginReadConnectRequestResponse(readBuffer);
//
// Write the proxy connection message.
//
if(writeRaw(writeBuffer))
{
//
// Write completed without blocking.
//
_proxy.endWriteConnectRequest(writeBuffer);
//
// Try to read the response.
//
if(readRaw(readBuffer))
{
//
// Read completed without blocking - fall through.
//
_proxy.endReadConnectRequestResponse(readBuffer);
}
else
{
//
// Return SocketOperationRead to indicate we need to complete the read.
//
_state = StateProxyConnectRequestPending; // Wait for proxy response
return IceInternal.SocketOperation.Read;
}
}
else
{
//
// Return SocketOperationWrite to indicate we need to complete the write.
//
_state = StateProxyConnectRequest; // Send proxy connect request
return IceInternal.SocketOperation.Write;
}
}
_state = StateConnected;
}
else if(_state == StateProxyConnectRequest)
{
//
// Write completed.
//
_proxy.endWriteConnectRequest(writeBuffer);
_state = StateProxyConnectRequestPending; // Wait for proxy response
return IceInternal.SocketOperation.Read;
}
else if(_state == StateProxyConnectRequestPending)
{
//
// Read completed.
//
_proxy.endReadConnectRequestResponse(readBuffer);
_state = StateConnected;
}
if(_state == StateConnected)
{
return handshakeNonBlocking();
}
}
catch(Ice.LocalException ex)
{
if(_instance.networkTraceLevel() >= 2)
{
StringBuilder s = new StringBuilder(128);
s.append("failed to establish ssl connection\n");
s.append(IceInternal.Network.fdToString(_fd, _proxy, _addr));
_logger.trace(_instance.networkTraceCategory(), s.toString());
}
throw ex;
}
return IceInternal.SocketOperation.None;
}
public void
close()
{
if(_state == StateHandshakeComplete && _instance.networkTraceLevel() >= 1)
{
String s = "closing ssl connection\n" + toString();
_logger.trace(_instance.networkTraceCategory(), s);
}
assert(_fd != null);
if(_state >= StateConnected)
{
try
{
//
// Send the close_notify message.
//
_engine.closeOutbound();
_netOutput.clear();
while(!_engine.isOutboundDone())
{
_engine.wrap(_emptyBuffer, _netOutput);
try
{
//
// Note: we can't block to send the close_notify message. In some cases, the
// close_notify message might therefore not be receieved by the peer. This is
// not a big issue since the Ice protocol isn't subject to truncation attacks.
//
flushNonBlocking();
}
catch(Ice.LocalException ex)
{
// Ignore.
}
}
}
catch(SSLException ex)
{
//
// We can't throw in close.
//
// Ice.SecurityException se = new Ice.SecurityException(
// "IceSSL: SSL failure while shutting down socket", ex);
//
}
try
{
_engine.closeInbound();
}
catch(SSLException ex)
{
//
// SSLEngine always raises an exception with this message:
//
// Inbound closed before receiving peer's close_notify: possible truncation attack?
//
// We would probably need to wait for a response in shutdown() to avoid this.
// For now, we'll ignore this exception.
//
//_logger.error("IceSSL: error during close\n" + ex.getMessage());
}
}
try
{
IceInternal.Network.closeSocket(_fd);
}
finally
{
_fd = null;
}
}
public boolean
write(IceInternal.Buffer buf)
{
if(_state == StateProxyConnectRequest)
{
//
// We need to write the proxy message, but we have to use TCP and not SSL.
//
return writeRaw(buf);
}
//
// If the handshake isn't completed yet, we shouldn't be writing.
//
if(_state < StateHandshakeComplete)
{
throw new Ice.ConnectionLostException();
}
//
// We don't want write to be called on android main thread as this will cause
// NetworkOnMainThreadException to be thrown. If that is the android main thread
// we return false and this method will be later called from the thread pool.
//
if(IceInternal.Util.isAndroidMainThread(Thread.currentThread()))
{
return false;
}
int status = writeNonBlocking(buf.b);
if(status != IceInternal.SocketOperation.None)
{
assert(status == IceInternal.SocketOperation.Write);
return false;
}
return true;
}
@SuppressWarnings("deprecation")
public boolean
read(IceInternal.Buffer buf, Ice.BooleanHolder moreData)
{
moreData.value = false;
if(_state == StateProxyConnectRequestPending)
{
//
// We need to read the proxy reply, but we have to use TCP and not SSL.
//
return readRaw(buf);
}
//
// If the handshake isn't completed yet, we shouldn't be reading (read can be
// called by the thread pool when the connection is registered/unregistered
// with the pool to be closed).
//
if(_state < StateHandshakeComplete)
{
throw new Ice.ConnectionLostException();
}
int rem = 0;
if(_instance.networkTraceLevel() >= 3)
{
rem = buf.b.remaining();
}
//
// Try to satisfy the request from data we've already decrypted.
//
int pos = buf.b.position();
fill(buf.b);
if(_instance.networkTraceLevel() >= 3 && buf.b.position() > pos)
{
String s = "received " + (buf.b.position() - pos) + " of " + rem + " bytes via ssl\n" + toString();
_logger.trace(_instance.networkTraceCategory(), s);
}
//
// Read and decrypt more data if necessary. Note that we might read
// more data from the socket than is actually necessary to fill the
// caller's stream.
//
try
{
while(buf.b.hasRemaining())
{
_netInput.flip();
SSLEngineResult result = _engine.unwrap(_netInput, _appInput);
_netInput.compact();
switch(result.getStatus())
{
case BUFFER_OVERFLOW:
{
assert(false);
break;
}
case BUFFER_UNDERFLOW:
{
int status = readNonBlocking();
if(status != IceInternal.SocketOperation.None)
{
assert(status == IceInternal.SocketOperation.Read);
return false;
}
continue;
}
case CLOSED:
{
throw new Ice.ConnectionLostException();
}
case OK:
{
break;
}
}
pos = buf.b.position();
fill(buf.b);
if(_instance.networkTraceLevel() >= 3 && buf.b.position() > pos)
{
String s = "received " + (buf.b.position() - pos) + " of " + rem + " bytes via ssl\n" + toString();
_logger.trace(_instance.networkTraceCategory(), s);
}
}
}
catch(SSLException ex)
{
throw new Ice.SecurityException("IceSSL: error during read", ex);
}
//
// Return a boolean to indicate whether more data is available.
//
moreData.value = _netInput.position() > 0;
return true;
}
public String
type()
{
return "ssl";
}
public String
toString()
{
return _desc;
}
public Ice.ConnectionInfo
getInfo()
{
return getNativeConnectionInfo();
}
public void
checkSendSize(IceInternal.Buffer buf, int messageSizeMax)
{
if(buf.size() > messageSizeMax)
{
IceInternal.Ex.throwMemoryLimitException(buf.size(), messageSizeMax);
}
}
TransceiverI(Instance instance, javax.net.ssl.SSLEngine engine, java.nio.channels.SocketChannel fd,
IceInternal.NetworkProxy proxy, String host, java.net.InetSocketAddress addr)
{
init(instance, engine, fd);
_proxy = proxy;
_host = host;
_incoming = false;
_addr = addr;
_state = StateNeedConnect;
_desc = IceInternal.Network.fdToString(_fd, _proxy, _addr);
}
TransceiverI(Instance instance, javax.net.ssl.SSLEngine engine, java.nio.channels.SocketChannel fd,
String adapterName)
{
init(instance, engine, fd);
_host = "";
_adapterName = adapterName;
_incoming = true;
_state = StateConnected;
_desc = IceInternal.Network.fdToString(_fd);
}
@SuppressWarnings("deprecation")
private void init(Instance instance, javax.net.ssl.SSLEngine engine, java.nio.channels.SocketChannel fd)
{
_instance = instance;
_engine = engine;
_fd = fd;
_logger = instance.communicator().getLogger();
_maxPacketSize = 0;
if(System.getProperty("os.name").startsWith("Windows"))
{
//
// On Windows, limiting the buffer size is important to prevent
// poor throughput performances when transfering large amount of
// data. See Microsoft KB article KB823764.
//
_maxPacketSize = IceInternal.Network.getSendBufferSize(_fd) / 2;
if(_maxPacketSize < 512)
{
_maxPacketSize = 0;
}
}
_appInput = ByteBuffer.allocateDirect(engine.getSession().getApplicationBufferSize() * 2);
_netInput = ByteBuffer.allocateDirect(engine.getSession().getPacketBufferSize() * 2);
_netOutput = ByteBuffer.allocateDirect(engine.getSession().getPacketBufferSize() * 2);
}
protected void
finalize()
throws Throwable
{
try
{
IceUtilInternal.Assert.FinalizerAssert(_fd == null);
}
catch(java.lang.Exception ex)
{
}
finally
{
super.finalize();
}
}
private NativeConnectionInfo
getNativeConnectionInfo()
{
//
// This can only be called on an open transceiver.
//
NativeConnectionInfo info = new NativeConnectionInfo();
if(_fd != null)
{
java.net.Socket socket = _fd.socket();
//
// On some platforms (e.g., early Android releases), sockets don't
// correctly return address information.
//
if(socket.getLocalAddress() != null)
{
info.localAddress = socket.getLocalAddress().getHostAddress();
info.localPort = socket.getLocalPort();
}
if(socket.getInetAddress() != null)
{
info.remoteAddress = socket.getInetAddress().getHostAddress();
info.remotePort = socket.getPort();
}
SSLSession session = _engine.getSession();
info.cipher = session.getCipherSuite();
try
{
java.util.ArrayList<String> certs = new java.util.ArrayList<String>();
info.nativeCerts = session.getPeerCertificates();
for(java.security.cert.Certificate c : info.nativeCerts)
{
StringBuffer s = new StringBuffer("-----BEGIN CERTIFICATE-----\n");
s.append(IceUtilInternal.Base64.encode(c.getEncoded()));
s.append("\n-----END CERTIFICATE-----");
certs.add(s.toString());
}
info.certs = certs.toArray(new String[0]);
}
catch(java.security.cert.CertificateEncodingException ex)
{
}
catch(javax.net.ssl.SSLPeerUnverifiedException ex)
{
// No peer certificates.
}
}
info.adapterName = _adapterName;
info.incoming = _incoming;
return info;
}
private int
handshakeNonBlocking()
{
try
{
HandshakeStatus status = _engine.getHandshakeStatus();
while(_state != StateHandshakeComplete)
{
SSLEngineResult result = null;
switch(status)
{
case FINISHED:
case NOT_HANDSHAKING:
handshakeCompleted();
break;
case NEED_TASK:
{
Runnable task;
while((task = _engine.getDelegatedTask()) != null)
{
task.run();
}
status = _engine.getHandshakeStatus();
break;
}
case NEED_UNWRAP:
{
//
// The engine needs more data. We might already have enough data in
// the _netInput buffer to satisfy the engine. If not, the engine
// responds with BUFFER_UNDERFLOW and we'll read from the socket.
//
_netInput.flip();
result = _engine.unwrap(_netInput, _appInput);
_netInput.compact();
//
// FINISHED is only returned from wrap or unwrap, not from engine.getHandshakeResult().
//
status = result.getHandshakeStatus();
switch(result.getStatus())
{
case BUFFER_OVERFLOW:
assert(false);
break;
case BUFFER_UNDERFLOW:
{
assert(status == javax.net.ssl.SSLEngineResult.HandshakeStatus.NEED_UNWRAP);
int ss = readNonBlocking();
if(ss != IceInternal.SocketOperation.None)
{
return ss;
}
break;
}
case CLOSED:
throw new Ice.ConnectionLostException();
case OK:
break;
}
break;
}
case NEED_WRAP:
{
//
// The engine needs to send a message.
//
result = _engine.wrap(_emptyBuffer, _netOutput);
if(result.bytesProduced() > 0)
{
int ss = flushNonBlocking();
if(ss != IceInternal.SocketOperation.None)
{
return ss;
}
}
//
// FINISHED is only returned from wrap or unwrap, not from engine.getHandshakeResult().
//
status = result.getHandshakeStatus();
break;
}
}
if(result != null)
{
switch(result.getStatus())
{
case BUFFER_OVERFLOW:
assert(false);
break;
case BUFFER_UNDERFLOW:
// Need to read again.
assert(status == HandshakeStatus.NEED_UNWRAP);
break;
case CLOSED:
throw new Ice.ConnectionLostException();
case OK:
break;
}
}
}
}
catch(SSLException ex)
{
throw new Ice.SecurityException("IceSSL: handshake error", ex);
}
return IceInternal.SocketOperation.None;
}
private void
handshakeCompleted()
{
_state = StateHandshakeComplete;
//
// IceSSL.VerifyPeer is translated into the proper SSLEngine configuration
// for a server, but we have to do it ourselves for a client.
//
if(!_incoming)
{
int verifyPeer =
_instance.communicator().getProperties().getPropertyAsIntWithDefault("IceSSL.VerifyPeer", 2);
if(verifyPeer > 0)
{
try
{
_engine.getSession().getPeerCertificates();
}
catch(javax.net.ssl.SSLPeerUnverifiedException ex)
{
throw new Ice.SecurityException("IceSSL: server did not supply a certificate", ex);
}
}
}
//
// Additional verification.
//
_instance.verifyPeer(getNativeConnectionInfo(), _fd, _host);
if(_instance.networkTraceLevel() >= 1)
{
String s;
if(_incoming)
{
s = "accepted ssl connection\n" + _desc;
}
else
{
s = "ssl connection established\n" + _desc;
}
_logger.trace(_instance.networkTraceCategory(), s);
}
if(_instance.securityTraceLevel() >= 1)
{
_instance.traceConnection(_fd, _engine, _incoming);
}
}
@SuppressWarnings("deprecation")
private int
writeNonBlocking(ByteBuffer buf)
{
//
// This method has two purposes: encrypt the application's message buffer into our
// _netOutput buffer, and write the contents of _netOutput to the socket without
// blocking.
//
try
{
while(buf.hasRemaining() || _netOutput.position() > 0)
{
final int rem = buf.remaining();
if(rem > 0)
{
//
// Encrypt the buffer.
//
SSLEngineResult result = _engine.wrap(buf, _netOutput);
switch(result.getStatus())
{
case BUFFER_OVERFLOW:
//
// Need to make room in _netOutput.
//
break;
case BUFFER_UNDERFLOW:
assert(false);
break;
case CLOSED:
throw new Ice.ConnectionLostException();
case OK:
break;
}
//
// If the SSL engine consumed any of the application's message buffer,
// then log it.
//
if(result.bytesConsumed() > 0)
{
if(_instance.networkTraceLevel() >= 3)
{
String s = "sent " + result.bytesConsumed() + " of " + rem + " bytes via ssl\n" +
toString();
_logger.trace(_instance.networkTraceCategory(), s);
}
}
}
//
// Write the encrypted data to the socket. We continue writing until we've written
// all of _netOutput, or until flushNonBlocking indicates that it cannot write
// (i.e., by returning NeedWrite).
//
if(_netOutput.position() > 0)
{
int ss = flushNonBlocking();
if(ss != IceInternal.SocketOperation.None)
{
assert(ss == IceInternal.SocketOperation.Write);
return ss;
}
}
}
}
catch(SSLException ex)
{
throw new Ice.SecurityException("IceSSL: error while encoding message", ex);
}
assert(_netOutput.position() == 0);
return IceInternal.SocketOperation.None;
}
private int
flushNonBlocking()
{
_netOutput.flip();
final int size = _netOutput.limit();
int packetSize = size - _netOutput.position();
if(_maxPacketSize > 0 && packetSize > _maxPacketSize)
{
packetSize = _maxPacketSize;
_netOutput.limit(_netOutput.position() + packetSize);
}
int status = IceInternal.SocketOperation.None;
while(_netOutput.hasRemaining())
{
try
{
assert(_fd != null);
int ret = _fd.write(_netOutput);
if(ret == -1)
{
throw new Ice.ConnectionLostException();
}
else if(ret == 0)
{
status = IceInternal.SocketOperation.Write;
break;
}
if(packetSize == _maxPacketSize)
{
assert(_netOutput.position() == _netOutput.limit());
packetSize = size - _netOutput.position();
if(packetSize > _maxPacketSize)
{
packetSize = _maxPacketSize;
}
_netOutput.limit(_netOutput.position() + packetSize);
}
}
catch(java.io.InterruptedIOException ex)
{
continue;
}
catch(java.io.IOException ex)
{
throw new Ice.ConnectionLostException(ex);
}
}
if(status == IceInternal.SocketOperation.None)
{
_netOutput.clear();
}
else
{
_netOutput.limit(size);
_netOutput.compact();
}
return status;
}
private int
readNonBlocking()
{
while(true)
{
try
{
assert(_fd != null);
int ret = _fd.read(_netInput);
if(ret == -1)
{
throw new Ice.ConnectionLostException();
}
else if(ret == 0)
{
return IceInternal.SocketOperation.Read;
}
break;
}
catch(java.io.InterruptedIOException ex)
{
continue;
}
catch(java.io.IOException ex)
{
throw new Ice.ConnectionLostException(ex);
}
}
return IceInternal.SocketOperation.None;
}
private void
fill(ByteBuffer buf)
{
_appInput.flip();
if(_appInput.hasRemaining())
{
int bytesAvailable = _appInput.remaining();
int bytesNeeded = buf.remaining();
if(bytesAvailable > bytesNeeded)
{
bytesAvailable = bytesNeeded;
}
if(buf.hasArray())
{
//
// Copy directly into the destination buffer's backing array.
//
byte[] arr = buf.array();
int offset = buf.arrayOffset() + buf.position();
_appInput.get(arr, offset, bytesAvailable);
buf.position(offset + bytesAvailable);
}
else if(_appInput.hasArray())
{
//
// Copy directly from the source buffer's backing array.
//
byte[] arr = _appInput.array();
int offset = _appInput.arrayOffset() + _appInput.position();
buf.put(arr, offset, bytesAvailable);
_appInput.position(offset + bytesAvailable);
}
else
{
//
// Copy using a temporary array.
//
byte[] arr = new byte[bytesAvailable];
_appInput.get(arr);
buf.put(arr);
}
}
_appInput.compact();
}
@SuppressWarnings("deprecation")
private boolean
writeRaw(IceInternal.Buffer buf)
{
//
// We don't want write to be called on android main thread as this will cause
// NetworkOnMainThreadException to be thrown. If that is the android main thread
// we return false and this method will be later called from the thread pool.
//
if(IceInternal.Util.isAndroidMainThread(Thread.currentThread()))
{
return false;
}
final int size = buf.b.limit();
int packetSize = size - buf.b.position();
while(buf.b.hasRemaining())
{
try
{
assert(_fd != null);
int ret = _fd.write(buf.b);
if(ret == -1)
{
throw new Ice.ConnectionLostException();
}
else if(ret == 0)
{
return false;
}
if(_instance.networkTraceLevel() >= 3)
{
String s = "sent " + ret + " of " + packetSize + " bytes via tcp\n" + toString();
_logger.trace(_instance.networkTraceCategory(), s);
}
}
catch(java.io.InterruptedIOException ex)
{
continue;
}
catch(java.io.IOException ex)
{
throw new Ice.SocketException(ex);
}
}
return true;
}
@SuppressWarnings("deprecation")
private boolean
readRaw(IceInternal.Buffer buf)
{
int packetSize = buf.b.remaining();
while(buf.b.hasRemaining())
{
try
{
assert(_fd != null);
int ret = _fd.read(buf.b);
if(ret == -1)
{
throw new Ice.ConnectionLostException();
}
if(ret == 0)
{
return false;
}
if(ret > 0)
{
if(_instance.networkTraceLevel() >= 3)
{
String s = "received " + ret + " of " + packetSize + " bytes via tcp\n" + toString();
_logger.trace(_instance.networkTraceCategory(), s);
}
}
packetSize = buf.b.remaining();
}
catch(java.io.InterruptedIOException ex)
{
continue;
}
catch(java.io.IOException ex)
{
throw new Ice.ConnectionLostException(ex);
}
}
return true;
}
private Instance _instance;
private java.nio.channels.SocketChannel _fd;
private javax.net.ssl.SSLEngine _engine;
private IceInternal.NetworkProxy _proxy;
private String _host;
private boolean _incoming;
private String _adapterName;
private java.net.InetSocketAddress _addr;
private int _state;
private Ice.Logger _logger;
private String _desc;
private int _maxPacketSize;
private ByteBuffer _appInput; // Holds clear-text data to be read by the application.
private ByteBuffer _netInput; // Holds encrypted data read from the socket.
private ByteBuffer _netOutput; // Holds encrypted data to be written to the socket.
private static ByteBuffer _emptyBuffer = ByteBuffer.allocate(0); // Used during handshaking.
private static final int StateNeedConnect = 0;
private static final int StateConnectPending = 1;
private static final int StateProxyConnectRequest = 2;
private static final int StateProxyConnectRequestPending = 3;
private static final int StateConnected = 4;
private static final int StateHandshakeComplete = 5;
}
|