Esempio n. 1
0
        private void SendCallback(IAsyncResult ar)
        {
            SendingContext sc = (SendingContext)ar.AsyncState;
            Int32          written;

            try
            {
                written = sc.socket.EndSend(ar);
            }
            catch (ObjectDisposedException)
            {
                // do nothing
                return;
            }
            catch (SocketException ex)
            {
                EndSend(ex);
                return;
            }
            catch (Exception ex)
            {
                EndSend(ex);
                return;
            }

            sc.buffer.Position += written;
            EndSend(written);
        }
Esempio n. 2
0
        private void SendFileCallback(IAsyncResult ar)
        {
            SendingContext sc = (SendingContext)ar.AsyncState;

            try
            {
                sc.socket.EndSendFile(ar);
            }
            catch (ObjectDisposedException)
            {
                // do nothing
                return;
            }
            catch (SocketException ex)
            {
                EndSend(ex);
                return;
            }
            catch (Exception ex)
            {
                EndSend(ex);
                return;
            }

            // TODO change written bytes to long?
            EndSend((Int32)sc.file.Length);
        }
Esempio n. 3
0
        private void ProcessSend(SocketAsyncEventArgs e)
        {
            SendingContext sctx = null;

            try {
                sctx = (SendingContext)e.UserToken;
                if (e.SocketError != SocketError.Success)
                {
                    var err = e.SocketError;
                    ProcessSendFailed(sctx.SendingBatch, RpcErrorCode.SendFailed, new Exception("Send Body Failed: " + err));
                    Disconnect(e.SocketError);
                    RpcTcpBufferManager.Release(e);
                    e = null;
                }
                else
                {
                    _tracing.InfoFmt("Socket Send {0} Bytes", e.Count);
                    RpcTcpBufferManager.Release(e);
                    e = null;
                    SendPackets(sctx.NextPacket);
                }
            } catch (Exception ex) {
                _tracing.ErrorFmt(ex, "ProcessSend Failed {0}:{1}", e, e.Buffer.Length);
                Disconnect(ex, "ProcessSend");
            } finally {
                //
                // 保护,如果出现了异常,则在此处释放
                if (e != null)
                {
                    RpcTcpBufferManager.Release(e);
                }
            }
        }