Beispiel #1
0
        internal bool PostSend()
        {
            bool         haveDataSend = false;
            IAsyncResult ar           = null;
            SocketError  socketError  = SocketError.SocketError;
            HandlerParam handlerParam = null;

            try
            {
                if (SUCCESS(IsClosed))
                {
                    goto Exit1;
                }
                if (SUCCESS(IsSending))
                {
                    goto Exit1;
                }

                if (SendBuf.GetOnceReadableLen() > 0)
                {
                    IsSending    = true;
                    haveDataSend = true;

                    handlerParam = new HandlerParam(EHandlerType.Socker, this);
                    if (LOG_ERROR(handlerParam != null))
                    {
                        goto Exit0;
                    }

                    ar = Sock.BeginSend(SendBuf.BufBytes, SendBuf.ReadInx, SendBuf.GetOnceReadableLen(), SocketFlags.None, out socketError,
                                        LP.NetModule.Reactor.OnSend, handlerParam);
                    if (socketError != SocketError.Success)
                    {
                        Close(ESockerCloseType.PostSendFail, 1, true);
                        goto Exit0;
                    }
                    if (LOG_ERROR(ar != null))
                    {
                        goto Exit0;
                    }
                }
            }
            catch (Exception e)
            {
                LPMiniDump.GenerateNormalDump(e);
            }

Exit1:
Exit0:
            return(haveDataSend);
        }
Beispiel #2
0
 public void SendData(Packet packet, Action success = null, Action error = null)
 {
     Sock.BeginSend(packet, 0, packet.Size, SocketFlags.None, (ar) =>
     {
         if (ar.IsCompleted)
         {
             success?.Invoke();
         }
         else
         {
             error?.Invoke();
         }
     }, null);
 }
Beispiel #3
0
        public void SendAsync(byte[] buff, int offset, int count)
        {
            try
            {
                if (!IsConnected())
                {
                    Disconnect();
                    return;
                }

                Sock.BeginSend(buff, offset, count, SocketFlags.None, DataSent, Sock);
            }
            catch (Exception ex)
            {
                #if DEBUG
                Console.WriteLine(ex.ToString());
                #endif
                Disconnect();
            }
        }