コード例 #1
0
        void OnEventClose(UdpEvent ev)
        {
            if (ChangeState(UdpSocketState.Running, UdpSocketState.Shutdown))
            {
                for (int i = 0; i < connList.Count; ++i)
                {
                    UdpConnection cn = connList[i];
                    cn.SendCommand(UdpCommandType.Disconnected);
                    cn.ChangeState(UdpConnectionState.Disconnected);
                }

                if (platform.Close() == false)
                {
                    UdpLog.Error("failed to shutdown socket interface, platform code: {0}", platform.PlatformError.ToString());
                }

                connList.Clear();
                connLookup.Clear();
                eventQueueIn.Clear();
                pendingConnections.Clear();

                GetReadStream().Data      = null;
                GetWriteStream(0, 0).Data = null;
                UdpLog.Error("OnEventClose: {0}", ev.EndPoint.ToString());
            }
        }
コード例 #2
0
        void ProcessTimeouts()
        {
            if ((frame & 3) == 3)
            {
                uint now = GetCurrentTime();

                for (int i = 0; i < connList.Count; ++i)
                {
                    UdpConnection cn = connList[i];

                    switch (cn.state)
                    {
                    case UdpConnectionState.Connecting:
                        cn.ProcessConnectingTimeouts(now);
                        break;

                    case UdpConnectionState.Connected:
                        cn.ProcessConnectedTimeouts(now);
                        break;

                    case UdpConnectionState.Disconnected:
                        cn.ChangeState(UdpConnectionState.Destroy);
                        break;

                    case UdpConnectionState.Destroy:
                        if (DestroyConnection(cn))
                        {
                            --i;
                        }
                        break;
                    }
                }
            }
        }
コード例 #3
0
        internal void Raise(int eventType, UdpConnection connection)
        {
            UdpEvent ev = new UdpEvent();

            ev.Type       = eventType;
            ev.Connection = connection;
            Raise(ev);
        }
コード例 #4
0
        internal void Raise(int eventType, UdpConnection connection, object obj)
        {
            UdpEvent ev = new UdpEvent();

            ev.Type       = eventType;
            ev.Connection = connection;
            ev.Object     = obj;
            Raise(ev);
        }
コード例 #5
0
        internal void Raise(int eventType, UdpConnection connection, UdpConnectionOption option, int value)
        {
            UdpEvent ev = new UdpEvent();

            ev.Type           = eventType;
            ev.Connection     = connection;
            ev.Option         = option;
            ev.OptionIntValue = value;
            Raise(ev);
        }
コード例 #6
0
        internal void Raise(int eventType, UdpConnection connection, object obj, UdpSendFailReason reason)
        {
            UdpEvent ev = new UdpEvent();

            ev.Type         = eventType;
            ev.Connection   = connection;
            ev.FailedReason = reason;
            ev.Object       = obj;
            Raise(ev);
        }
コード例 #7
0
ファイル: udpSocket.cs プロジェクト: wuzhen/udpkit
        void OnEventConnect(UdpEvent ev)
        {
            if (CheckState(udpSocketState.Running))
            {
                UdpConnection cn = CreateConnection(ev.EndPoint, UdpConnectionMode.Client);

                if (cn == null)
                {
                    UdpLog.Error("could not create connection for endpoint {0}", ev.EndPoint.ToString());
                }
            }
        }
コード例 #8
0
ファイル: udpSocket.cs プロジェクト: wuzhen/udpkit
        bool DestroyConnect(UdpConnection cn)
        {
            for (int i = 0; i < connList.Count; ++i)
            {
                if (connList[i] == cn)
                {
                    connList.RemoveAt(i);
                    return(true);
                }
            }

            return(false);
        }
コード例 #9
0
        UdpConnection CreateConnection(UdpEndPoint endpoint, UdpConnectionMode mode)
        {
            if (connLookup.ContainsKey(endpoint))
            {
                UdpLog.Warn("connection for {0} already exists", endpoint);
                return(default(UdpConnection));
            }

            UdpConnection cn = new UdpConnection(this, mode, endpoint);

            connLookup.Add(endpoint, cn);
            connList.Add(cn);

            return(cn);
        }
コード例 #10
0
        bool DestroyConnection(UdpConnection cn)
        {
            for (int i = 0; i < connList.Count; ++i)
            {
                if (connList[i] == cn)
                {
                    connList.RemoveAt(i);
                    connLookup.Remove(cn.RemoteEndPoint);

                    cn.Destroy();

                    return(true);
                }
            }

            return(false);
        }
コード例 #11
0
        void AcceptConnection(UdpEndPoint ep)
        {
            UdpConnection cn = CreateConnection(ep, UdpConnectionMode.Server);

            cn.ChangeState(UdpConnectionState.Connected);
        }
コード例 #12
0
        void AcceptConnection(UdpEndPoint ep, object replyObj)
        {
            UdpConnection cn = CreateConnection(ep, UdpConnectionMode.Server, replyObj);

            cn.ChangeState(UdpConnectionState.Connected);
        }
コード例 #13
0
 public BoltConnectionEx(UdpKit.UdpConnection c) : base(c)
 {
 }