public int read(IceInternal.Buffer buf, ref bool hasMoreData) { // // Force caller to use async read. // return(buf.b.hasRemaining() ? IceInternal.SocketOperation.Read : IceInternal.SocketOperation.None); }
public void checkSendSize(IceInternal.Buffer buf, int messageSizeMax) { if (buf.size() > messageSizeMax) { IceInternal.Ex.throwMemoryLimitException(buf.size(), messageSizeMax); } }
public int initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer, ref bool hasMoreData) { int status = _stream.connect(readBuffer, writeBuffer, ref hasMoreData); if (status != IceInternal.SocketOperation.None) { return(status); } _stream.setBlock(true); // SSL requires a blocking socket if (_sslStream == null) { NetworkStream ns = new NetworkStream(_stream.fd(), false); _sslStream = new SslStream(ns, false, new RemoteCertificateValidationCallback(validationCallback), new LocalCertificateSelectionCallback(selectCertificate)); return(IceInternal.SocketOperation.Connect); } Debug.Assert(_sslStream.IsAuthenticated); _authenticated = true; _instance.verifyPeer((NativeConnectionInfo)getInfo(), _stream.fd(), _host); if (_instance.securityTraceLevel() >= 1) { _instance.traceStream(_sslStream, _stream.ToString()); } return(IceInternal.SocketOperation.None); }
public int write(IceInternal.Buffer buf) { // // Force caller to use async write. // return(buf.b.hasRemaining() ? IceInternal.SocketOperation.Write : IceInternal.SocketOperation.None); }
public int initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer, ref bool hasMoreData) { if (!_isConnected) { int status = _delegate.initialize(readBuffer, writeBuffer, ref hasMoreData); if (status != IceInternal.SocketOperation.None) { return(status); } _isConnected = true; } IceInternal.Network.setBlock(fd(), true); // SSL requires a blocking socket // // For timeouts to work properly, we need to receive/send // the data in several chunks. Otherwise, we would only be // notified when all the data is received/written. The // connection timeout could easily be triggered when // receiging/sending large messages. // _maxSendPacketSize = Math.Max(512, IceInternal.Network.getSendBufferSize(fd())); _maxRecvPacketSize = Math.Max(512, IceInternal.Network.getRecvBufferSize(fd())); if (_sslStream == null) { try { _sslStream = new SslStream(new NetworkStream(_delegate.fd(), false), false, new RemoteCertificateValidationCallback(validationCallback), new LocalCertificateSelectionCallback(selectCertificate)); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } else { throw new Ice.SocketException(ex); } } return(IceInternal.SocketOperation.Connect); } Debug.Assert(_sslStream.IsAuthenticated); _authenticated = true; _cipher = _sslStream.CipherAlgorithm.ToString(); _instance.verifyPeer(_host, (ConnectionInfo)getInfo(), ToString()); if (_instance.securityTraceLevel() >= 1) { _instance.traceStream(_sslStream, ToString()); } return(IceInternal.SocketOperation.None); }
public byte[] finished() { IceInternal.Buffer buf = _os.prepareWrite(); byte[] result = new byte[buf.b.limit()]; buf.b.get(result); return(result); }
public void finishRead(IceInternal.Buffer buf) { if (!_isConnected) { _delegate.finishRead(buf); return; } else if (_sslStream == null) // Transceiver was closed { _readResult = null; return; } Debug.Assert(_readResult != null); try { int ret; try { ret = _readResult.Result; } catch (AggregateException ex) { throw ex.InnerException; } if (ret == 0) { throw new Ice.ConnectionLostException(); } Debug.Assert(ret > 0); buf.b.position(buf.b.position() + ret); } catch (Ice.LocalException) { throw; } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public void finishWrite(IceInternal.Buffer buf) { if (!_isConnected) { _delegate.finishWrite(buf); return; } else if (_sslStream == null) // Transceiver was closed { if (getSendPacketSize(buf.b.remaining()) == buf.b.remaining()) // Sent last packet { buf.b.position(buf.b.limit()); // Assume all the data was sent for at-most-once semantics. } _writeResult = null; return; } else if (!_authenticated) { finishAuthenticate(); return; } int sent = getSendPacketSize(buf.b.remaining()); Debug.Assert(_writeResult != null); try { try { _writeResult.Wait(); } catch (AggregateException ex) { throw ex.InnerException; } buf.b.position(buf.b.position() + sent); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { Debug.Assert(_fd != null); if (_state == StateProxyConnectRequestPending) { _proxy.beginReadConnectRequestResponse(buf); } int packetSize = buf.b.remaining(); if (_maxReceivePacketSize > 0 && packetSize > _maxReceivePacketSize) { packetSize = _maxReceivePacketSize; } try { _readCallback = callback; if (_stream != null) { _readResult = _stream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSize, readCompleted, state); } else { _readResult = _fd.BeginReceive(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None, readCompleted, state); } return(_readResult.CompletedSynchronously); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (Ice.LocalException) { throw; } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public void FinishWrite(IceInternal.Buffer buf) { if (!_isConnected) { _delegate.FinishWrite(buf); return; } else if (_sslStream == null) // Transceiver was closed { if (GetSendPacketSize(buf.B.Remaining()) == buf.B.Remaining()) // Sent last packet { buf.B.Position(buf.B.Limit()); // Assume all the data was sent for at-most-once semantics. } _writeResult = null; return; } else if (!_authenticated) { FinishAuthenticate(); return; } Debug.Assert(_writeResult != null); int sent = GetSendPacketSize(buf.B.Remaining()); try { _sslStream.EndWrite(_writeResult); _writeResult = null; buf.B.Position(buf.B.Position() + sent); } catch (IOException ex) { if (IceInternal.Network.ConnectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.Timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state, out bool completed) { if (!_stream.isConnected()) { return(_stream.startWrite(buf, callback, state, out completed)); } Debug.Assert(_sslStream != null); if (!_authenticated) { completed = false; return(startAuthenticate(callback, state)); } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = _stream.getSendPacketSize(buf.b.remaining()); try { _writeCallback = callback; _writeResult = _sslStream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, writeCompleted, state); completed = packetSize == buf.b.remaining(); return(_writeResult.CompletedSynchronously); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public void reset(bool clearBuffer) { _os.clear(); IceInternal.Buffer buf = _os.getBuffer(); if (clearBuffer) { buf.clear(); } else { buf.reset(); } buf.b.position(0); }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback cb, object state, out bool completed) { if (!_isConnected) { return(_delegate.startWrite(buf, cb, state, out completed)); } Debug.Assert(_sslStream != null); if (!_authenticated) { completed = false; return(startAuthenticate(cb, state)); } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = getSendPacketSize(buf.b.remaining()); try { _writeResult = _sslStream.WriteAsync(buf.b.rawBytes(), buf.b.position(), packetSize); _writeResult.ContinueWith(task => cb(state), TaskScheduler.Default); completed = packetSize == buf.b.remaining(); return(false); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
private void initialize(IceInternal.Instance instance, byte[] data, EncodingVersion v, bool copyData) { if (copyData) { _is = new IceInternal.BasicStream(instance, v); _is.resize(data.Length, true); IceInternal.Buffer buf = _is.getBuffer(); buf.b.position(0); buf.b.put(data); buf.b.position(0); } else { _is = new IceInternal.BasicStream(instance, v, data); } _is.closure(this); }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { if (!_isConnected) { return(_delegate.startRead(buf, callback, state)); } Debug.Assert(_sslStream != null && _sslStream.IsAuthenticated); int packetSz = getRecvPacketSize(buf.b.remaining()); try { _readCallback = callback; _readResult = _sslStream.BeginRead(buf.b.rawBytes(), buf.b.position(), packetSz, readCompleted, state); return(_readResult.CompletedSynchronously); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public bool startRead(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state) { if (!_isConnected) { return(_delegate.startRead(buf, callback, state)); } Debug.Assert(_sslStream != null && _sslStream.IsAuthenticated); int packetSz = getRecvPacketSize(buf.b.remaining()); try { _readResult = _sslStream.ReadAsync(buf.b.rawBytes(), buf.b.position(), packetSz); _readResult.ContinueWith(task => callback(state), TaskScheduler.Default); return(false); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public InputStream(Communicator communicator, IceInternal.Buffer buf, bool adopt) { initialize(communicator); _buf = new IceInternal.Buffer(buf, adopt); }
/// <summary> /// This constructor uses the given encoding version. /// </summary> /// <param name="encoding">The desired encoding version.</param> /// <param name="data">The byte array containing encoded Slice types.</param> public InputStream(EncodingVersion encoding, byte[] data) { initialize(encoding); _buf = new IceInternal.Buffer(data); }
public InputStream(EncodingVersion encoding, IceInternal.ByteBuffer buf) { initialize(encoding); _buf = new IceInternal.Buffer(buf); }
public InputStream(EncodingVersion encoding, IceInternal.Buffer buf, bool adopt) { initialize(encoding); _buf = new IceInternal.Buffer(buf, adopt); }
public void CheckSendSize(IceInternal.Buffer buf) => _delegate.CheckSendSize(buf);
public InputStream(Communicator communicator, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt) { initialize(communicator, encoding); _buf = new IceInternal.Buffer(buf, adopt); }
public void finishRead(IceInternal.Buffer buf) { if (_fd == null) // Transceiver was closed { _readResult = null; return; } Debug.Assert(_fd != null && _readResult != null); try { int ret = _stream != null?_stream.EndRead(_readResult) : _fd.EndReceive(_readResult); _readResult = null; if (ret == 0) { throw new Ice.ConnectionLostException(); } Debug.Assert(ret > 0); if (_instance.networkTraceLevel() >= 3) { int packetSize = buf.b.remaining(); if (_maxReceivePacketSize > 0 && packetSize > _maxReceivePacketSize) { packetSize = _maxReceivePacketSize; } string s = "received " + ret + " of " + packetSize + " bytes via ssl\n" + ToString(); _logger.trace(_instance.networkTraceCategory(), s); } if (_stats != null) { #pragma warning disable 618 _stats.bytesReceived(type(), ret); #pragma warning restore 618 } buf.b.position(buf.b.position() + ret); if (_state == StateProxyConnectRequestPending) { _proxy.endReadConnectRequestResponse(buf); } } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (Ice.LocalException) { throw; } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
/// <summary> /// Swaps the contents of one stream with another. /// </summary> /// <param name="other">The other stream.</param> public void swap(InputStream other) { Debug.Assert(instance_ == other.instance_); IceInternal.Buffer tmpBuf = other._buf; other._buf = _buf; _buf = tmpBuf; EncodingVersion tmpEncoding = other._encoding; other._encoding = _encoding; _encoding = tmpEncoding; bool tmpTraceSlicing = other._traceSlicing; other._traceSlicing = _traceSlicing; _traceSlicing = tmpTraceSlicing; object tmpClosure = other._closure; other._closure = _closure; _closure = tmpClosure; bool tmpSliceValues = other._sliceValues; other._sliceValues = _sliceValues; _sliceValues = tmpSliceValues; // // Swap is never called for InputStreams that have encapsulations being read. However, // encapsulations might still be set in case un-marshalling failed. We just // reset the encapsulations if there are still some set. // resetEncapsulation(); other.resetEncapsulation(); int tmpStartSeq = other._startSeq; other._startSeq = _startSeq; _startSeq = tmpStartSeq; int tmpMinSeqSize = other._minSeqSize; other._minSeqSize = _minSeqSize; _minSeqSize = tmpMinSeqSize; ValueFactoryManager tmpVfm = other._valueFactoryManager; other._valueFactoryManager = _valueFactoryManager; _valueFactoryManager = tmpVfm; Logger tmpLogger = other._logger; other._logger = _logger; _logger = tmpLogger; CompactIdResolver tmpCompactIdResolver = other._compactIdResolver; other._compactIdResolver = _compactIdResolver; _compactIdResolver = tmpCompactIdResolver; ClassResolver tmpClassResolver = other._classResolver; other._classResolver = _classResolver; _classResolver = tmpClassResolver; }
public InputStream(IceInternal.Instance instance, EncodingVersion encoding, byte[] data) { initialize(instance, encoding); _buf = new IceInternal.Buffer(data); }
public InputStream(Communicator communicator, IceInternal.ByteBuffer buf) { initialize(communicator); _buf = new IceInternal.Buffer(buf); }
public InputStream(IceInternal.Instance instance, EncodingVersion encoding, IceInternal.Buffer buf, bool adopt) { initialize(instance, encoding); _buf = new IceInternal.Buffer(buf, adopt); }
/// <summary> /// Constructing an InputStream without providing a communicator means the stream will /// use the default encoding version. A communicator is required in order to unmarshal /// proxies. You can supply a communicator later by calling initialize(). /// </summary> /// <param name="data">The byte array containing encoded Slice types.</param> public InputStream(byte[] data) { initialize(Util.currentEncoding); _buf = new IceInternal.Buffer(data); }
public int initialize(IceInternal.Buffer readBuffer, IceInternal.Buffer writeBuffer, ref bool hasMoreData) { if (!_isConnected) { int status = _delegate.initialize(readBuffer, writeBuffer, ref hasMoreData); if (status != IceInternal.SocketOperation.None) { return(status); } _isConnected = true; } IceInternal.Network.setBlock(fd(), true); // SSL requires a blocking socket // // For timeouts to work properly, we need to receive/send // the data in several chunks. Otherwise, we would only be // notified when all the data is received/written. The // connection timeout could easily be triggered when // receiging/sending large messages. // _maxSendPacketSize = Math.Max(512, IceInternal.Network.getSendBufferSize(fd())); _maxRecvPacketSize = Math.Max(512, IceInternal.Network.getRecvBufferSize(fd())); if (_sslStream == null) { _sslStream = new SslStream(new NetworkStream(_delegate.fd(), false), false, new RemoteCertificateValidationCallback(validationCallback), new LocalCertificateSelectionCallback(selectCertificate)); return(IceInternal.SocketOperation.Connect); } Debug.Assert(_sslStream.IsAuthenticated); _authenticated = true; _cipher = _sslStream.CipherAlgorithm.ToString(); List <string> certs = new List <string>(); if (_chain.ChainElements != null && _chain.ChainElements.Count > 0) { _nativeCerts = new X509Certificate2[_chain.ChainElements.Count]; for (int i = 0; i < _chain.ChainElements.Count; ++i) { X509Certificate2 cert = _chain.ChainElements[i].Certificate; _nativeCerts[i] = cert; StringBuilder s = new StringBuilder(); s.Append("-----BEGIN CERTIFICATE-----\n"); s.Append(Convert.ToBase64String(cert.Export(X509ContentType.Cert))); s.Append("\n-----END CERTIFICATE-----"); certs.Add(s.ToString()); } } _certs = certs.ToArray(); _instance.verifyPeer(_host, (NativeConnectionInfo)getInfo(), ToString()); if (_instance.securityTraceLevel() >= 1) { _instance.traceStream(_sslStream, ToString()); } return(IceInternal.SocketOperation.None); }
/// <summary> /// This constructor uses the given encoding version. /// </summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="encoding">The desired encoding version.</param> /// <param name="data">The byte array containing encoded Slice types.</param> public InputStream(Communicator communicator, EncodingVersion encoding, byte[] data) { initialize(communicator, encoding); _buf = new IceInternal.Buffer(data); }
public bool startWrite(IceInternal.Buffer buf, IceInternal.AsyncCallback callback, object state, out bool completed) { Debug.Assert(_fd != null); if (_state < StateConnected) { completed = false; if (_state == StateConnectPending) { try { EndPoint addr = _proxy != null?_proxy.getAddress() : _addr; _writeResult = IceInternal.Network.doConnectAsync(_fd, addr, callback, state); return(_writeResult.CompletedSynchronously); } catch (Exception ex) { throw new Ice.SocketException(ex); } } else if (_state == StateProxyConnectRequest) { _proxy.beginWriteConnectRequest(_addr, buf); } else if (_state == StateAuthenticatePending) { return(beginAuthenticate(callback, state)); } } // // We limit the packet size for beingWrite to ensure connection timeouts are based // on a fixed packet size. // int packetSize = buf.b.remaining(); if (_maxSendPacketSize > 0 && packetSize > _maxSendPacketSize) { packetSize = _maxSendPacketSize; } try { _writeCallback = callback; if (_stream != null) { _writeResult = _stream.BeginWrite(buf.b.rawBytes(), buf.b.position(), packetSize, writeCompleted, state); } else { _writeResult = _fd.BeginSend(buf.b.rawBytes(), buf.b.position(), packetSize, SocketFlags.None, writeCompleted, state); } completed = packetSize == buf.b.remaining(); return(_writeResult.CompletedSynchronously); } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (Ice.LocalException) { throw; } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
public bool read(IceInternal.Buffer buf) { Debug.Assert(_fd != null); return(false); // Caller will use async read. }
public void checkSendSize(IceInternal.Buffer buf) { }
public InputStream(IceInternal.Buffer buf, bool adopt) { initialize(Util.currentEncoding); _buf = new IceInternal.Buffer(buf, adopt); }
public void finishWrite(IceInternal.Buffer buf) { if (_fd == null) // Transceiver was closed { if (buf.size() - buf.b.position() < _maxSendPacketSize) { buf.b.position(buf.size()); // Assume all the data was sent for at-most-once semantics. } _writeResult = null; return; } if (_state < StateConnected && _state != StateProxyConnectRequest) { return; } Debug.Assert(_fd != null && _writeResult != null); try { if (_stream != null) { _stream.EndWrite(_writeResult); } else { _fd.EndSend(_writeResult); } _writeResult = null; int packetSize = buf.b.remaining(); if (_maxSendPacketSize > 0 && packetSize > _maxSendPacketSize) { packetSize = _maxSendPacketSize; } if (_instance.networkTraceLevel() >= 3) { string s = "sent " + packetSize + " of " + packetSize + " bytes via ssl\n" + ToString(); _logger.trace(_instance.networkTraceCategory(), s); } if (_stats != null) { #pragma warning disable 618 _stats.bytesSent(type(), packetSize); #pragma warning restore 618 } buf.b.position(buf.b.position() + packetSize); if (_state == StateProxyConnectRequest) { _proxy.endWriteConnectRequest(buf); } } catch (IOException ex) { if (IceInternal.Network.connectionLost(ex)) { throw new Ice.ConnectionLostException(ex); } if (IceInternal.Network.timeout(ex)) { throw new Ice.TimeoutException(); } throw new Ice.SocketException(ex); } catch (Ice.LocalException) { throw; } catch (ObjectDisposedException ex) { throw new Ice.ConnectionLostException(ex); } catch (Exception ex) { throw new Ice.SyscallException(ex); } }
/// <summary> /// This constructor uses the communicator's default encoding version. /// </summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="data">The byte array containing encoded Slice types.</param> public InputStream(Communicator communicator, byte[] data) { initialize(communicator); _buf = new IceInternal.Buffer(data); }
public void checkSendSize(IceInternal.Buffer buf) { _delegate.checkSendSize(buf); }
public InputStream(IceInternal.ByteBuffer buf) { initialize(Util.currentEncoding); _buf = new IceInternal.Buffer(buf); }