コード例 #1
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
        public IAsyncResult BeginSend(
            byte[] buffer,
            int offset,
            int size,
            AsyncCallback callback,
            object state
            )
        {
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.BeginSend(" + size.ToString() + " bytes) {}");
#endif
            if (!opened)
            {
                throw new InvalidOperationException("Connection not opened");
            }
            if (closed)
            {
                throw new InvalidOperationException("Connection already closed");
            }

            transport.Blocking = false;
            if (offset > 0 || size != buffer.Length)
            {
                byte[] buf = new byte[size];
                Buffer.BlockCopy(buffer, offset, buf, 0, size);
                buffer = buf;
                offset = 0;
            }
            SSLSocketAsyncSendResult ret = new SSLSocketAsyncSendResult(size, callback, state);
            SetSendAsyncResult(ret);
            SendData(buffer);
            CompleteSendAsyncResult();
            return(ret);
        }
コード例 #2
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
        protected void CompleteSendAsyncResult()
        {
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.CompleteSendAsyncResult() {}");
#endif
            lock (this)
            {
                SSLSocketAsyncResult res = beginSendAsyncResult;
                if (res != null)
                {
                    beginSendAsyncResult = null;
                    res.Completed(innerException);
                    res            = null;
                    innerException = null;
                }
                else if (beginConnectAsyncResult != null)
                {
                    res = beginConnectAsyncResult;
                    beginConnectAsyncResult = null;
                    res.Completed(innerException);
                    res            = null;
                    innerException = null;
                }
                else if (beginOpenSSLSessionAsyncResult != null)
                {
                    res = beginOpenSSLSessionAsyncResult;
                    beginOpenSSLSessionAsyncResult = null;
                    res.Completed(innerException);
                    res            = null;
                    innerException = null;
                }
            }
        }
コード例 #3
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
        protected void SetSendAsyncResult(SSLSocketAsyncSendResult ar)
        {
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.SetSendAsyncResult() {}");
#endif
            lock (this)
            {
                beginSendAsyncResult = ar;
            }
        }
コード例 #4
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
        public int EndSend(IAsyncResult asyncResult)
        {
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.EndSend() {}");
#endif
            SSLSocketAsyncSendResult asr = (SSLSocketAsyncSendResult)asyncResult;
            asr.AsyncWaitHandle.WaitOne();
            if (asr.Exception != null)
            {
                throw asr.Exception;
            }
            return(asr.SendDataLen);
        }
コード例 #5
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
        private void OnSocketSendCallback(IAsyncResult asyncResult)
        {
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.OnSocketSendCallback() {}");
#endif
            SSLSocketBeginSendStateObject state = (SSLSocketBeginSendStateObject)asyncResult.AsyncState;
            SSLSocketAsyncSendResult      asr   = (SSLSocketAsyncSendResult)state.AsyncSendResult;
            try
            {
                int sent = transport.EndSend(asyncResult);
#if SECURE_BLACKBOX_DEBUG
                LowLevelDump("ElSSLSocket.OnSocketSendCallback(): " + sent.ToString() + " bytes sent to socket");
#endif
                byte[] oldbuf = state.Buffer;
                if (sent < oldbuf.Length)
                {
                    byte[] newbuf = new byte[oldbuf.Length - sent];
                    Buffer.BlockCopy(oldbuf, sent, newbuf, 0, newbuf.Length);
                    if (asr != null)
                    {
                        asr.ReplaceBufferForSend(oldbuf, newbuf);
                    }
                    transport.BeginSend(newbuf, 0, newbuf.Length, transportFlags,
                                        socketSendCallback,
                                        new SSLSocketBeginSendStateObject(asr, newbuf));
                }
                else
                {
                    if (asr != null)
                    {
                        asr.RemoveBufferForSend(oldbuf);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionOccured(ex);
                CompleteSendAsyncResult();
            }
        }
コード例 #6
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
        virtual protected void Reset()
        {
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.Reset() {");
#endif
            lock (this)
            {
                innerException              = null;
                opened                      = false;
                closed                      = false;
                inBufferDataPresent         = false;
                inBufferIndex               = 0;
                transportBeginReceiveCalled = false;

                beginConnectAsyncResult = null;
                beginSendAsyncResult    = null;
                beginReceiveAsyncResult = null;
            }
#if SECURE_BLACKBOX_DEBUG
            LowLevelDump("ElSSLSocket.Reset() }");
#endif
        }
コード例 #7
0
ファイル: ElSSLSocket.cs プロジェクト: simondixey/padarn
 public SSLSocketBeginSendStateObject(SSLSocketAsyncSendResult asr, byte[] buffer)
 {
     this.asr    = asr;
     this.buffer = buffer;
 }