示例#1
0
        public void EndSend(IAsyncResult asyncResult)
        {
            AsyncSendDataResult asyncSendResult = (AsyncSendDataResult)asyncResult;

            if (!asyncSendResult.IsCompleted)
            {
                asyncSendResult.AsyncWaitHandle.WaitOne();
            }

            if (asyncSendResult.CompletedWithException)
            {
                throw asyncSendResult.AsyncException;
            }
        }
示例#2
0
        private void SendDataCallback(IAsyncResult asyncResult)
        {
            AsyncSendDataResult asyncSendDataResult = (AsyncSendDataResult)asyncResult.AsyncState;

            try {
                _recordStream.EndSend(asyncResult);
                asyncSendDataResult.SetComplete();
            } catch (AlertException ae) {
                ProcessSendFatalAlert(new Alert(ae.AlertDescription, _handshakeSession.NegotiatedVersion));
                asyncSendDataResult.SetComplete(new Exception("Connection closed because of local alert", ae));
            } catch (IOException) {
                asyncSendDataResult.SetComplete(new EndOfStreamException("Connection closed unexpectedly"));
            } catch (Exception e) {
                ProcessSendFatalAlert(new Alert(AlertDescription.InternalError, _handshakeSession.NegotiatedVersion));
                asyncSendDataResult.SetComplete(new Exception("Connection closed because of local error", e));
            }
        }
示例#3
0
        public IAsyncResult BeginSend(byte[] buffer, int offset, int count,
                                      AsyncCallback asyncCallback,
                                      Object asyncState)
        {
            AsyncSendDataResult asyncSendResult = new AsyncSendDataResult(asyncCallback, asyncState);

            lock (_handshakeLock) {
                if (!_isAuthenticated)
                {
                    Exception e = new InvalidOperationException("Trying to send on an unauthenticated session");
                    asyncSendResult.SetComplete(e);
                    return(asyncSendResult);
                }
                if (_isHandshaking)
                {
                    // Queue requests to send data during renegotiation
                    // TODO: implement this when renegotiation is implemented
                    Exception e = new InvalidOperationException("Sending data during renegotiation not implemented");
                    asyncSendResult.SetComplete(e);
                    return(asyncSendResult);
                }
            }

            // Copy the bytes to send into own buffer
            byte[] outputBuffer = new byte[count];
            Buffer.BlockCopy(buffer, offset, outputBuffer, 0, count);

            // Create and encrypt the data output record
            Record[] records = _handshakePacketizer.ProcessOutputData(_handshakeSession.NegotiatedVersion,
                                                                      RecordType.Data, outputBuffer,
                                                                      _recordStream.MaximumFragmentLength);
            for (int i = 0; i < records.Length; i++)
            {
                _recordHandler.ProcessOutputRecord(records[i]);
            }

            // Send the data output record
            _recordStream.BeginSend(records, new AsyncCallback(SendDataCallback), asyncSendResult);
            return(asyncSendResult);
        }
示例#4
0
        public IAsyncResult BeginSend(byte[] buffer, int offset, int count,
		                              AsyncCallback asyncCallback,
		                              Object asyncState)
        {
            AsyncSendDataResult asyncSendResult = new AsyncSendDataResult(asyncCallback, asyncState);
            lock (_handshakeLock) {
                if (!_isAuthenticated) {
                    Exception e = new InvalidOperationException("Trying to send on an unauthenticated session");
                    asyncSendResult.SetComplete(e);
                    return asyncSendResult;
                }
                if (_isHandshaking) {
                    // Queue requests to send data during renegotiation
                    // TODO: implement this when renegotiation is implemented
                    Exception e = new InvalidOperationException("Sending data during renegotiation not implemented");
                    asyncSendResult.SetComplete(e);
                    return asyncSendResult;
                }
            }

            // Copy the bytes to send into own buffer
            byte[] outputBuffer = new byte[count];
            Buffer.BlockCopy(buffer, offset, outputBuffer, 0, count);

            // Create and encrypt the data output record
            Record[] records = _handshakePacketizer.ProcessOutputData(_handshakeSession.NegotiatedVersion,
                                                                      RecordType.Data, outputBuffer,
                                                                      _recordStream.MaximumFragmentLength);
            for (int i=0; i<records.Length; i++) {
                _recordHandler.ProcessOutputRecord(records[i]);
            }

            // Send the data output record
            _recordStream.BeginSend(records, new AsyncCallback(SendDataCallback), asyncSendResult);
            return asyncSendResult;
        }