Example #1
0
            public ENetRet Proc()
            {
                if (_HBRcvPeriod != null)
                {
                    if (_HBRcvPeriod.CheckAndNextLoose())
                    {
                        return(ENetRet.HeartBeatFail);
                    }
                }

                if (_HBSndPeriod != null && _HBSndPeriod.CheckAndNextLoose())
                {
                    if (!_SendPing())
                    {
                        return(ENetRet.SystemError);
                    }
                }

                if (DoesWillClose() && _CloseTime < DateTime.Now)
                {
                    return(_WillCloseNetRet);
                }

                return(ENetRet.Ok);
            }
Example #2
0
            public void Proc()
            {
                for (var pLFIOCP = _LFIOCPs.GetPopBuf();
                     pLFIOCP != null;
                     pLFIOCP = _LFIOCPs.GetPopBuf())
                {
                    var Peer = _Peers[pLFIOCP.Key.PeerNum];

                    switch (pLFIOCP.Op)
                    {
                    case _EAsyncOp.Link:
                        Peer.Linked(pLFIOCP.Key);
                        break;

                    case _EAsyncOp.LinkFail:
                        Peer.LinkFailed(pLFIOCP.Key);
                        break;

                    case _EAsyncOp.UnLink:
                        Peer.UnLink(pLFIOCP.Key, ENetState.Normal);
                        break;

                    case _EAsyncOp.Recv:
                        Peer.Recved(pLFIOCP.Key);
                        break;

                    case _EAsyncOp.Send:
                        Peer.Sended(pLFIOCP.Key);
                        break;

                    default:
                        break;
                    }

                    _LFIOCPs.Pop();
                }

                if (_ProcPeriod.CheckAndNextLoose())
                {
                    foreach (var Peer in _Peers)
                    {
                        Peer.Proc();
                    }
                }
            }
Example #3
0
            public void Proc()
            {
                if (_Socket == null)
                {
                    return;
                }

                if (_Socket.Connected)
                {
                    if (_HBRcvPeriod != null)
                    {
                        if (_HBRcvPeriod.CheckAndNextLoose())
                        {
                            _UnLink(ENetState.Normal);
                        }
                    }

                    if (_HBSndPeriod != null)
                    {
                        if (_HBSndPeriod.CheckAndNextLoose())
                        {
                            _Send();
                        }
                    }
                }

                // Connecting Check
                if (_Socket != null)
                {
                    if (!_Socket.Connected &&
                        _Connecting &&
                        (Environment.TickCount - _ConnectTime) > _ConnectTimeOut)
                    {
                        _LinkFailed();
                    }
                }
            }
Example #4
0
            public new void Proc()
            {
                base.Proc();

                for (var it = _Connectings.Begin(); it != _Connectings.End();)
                {
                    var itCheck = it;
                    it.MoveNext();

                    var itPeer   = _PeersAndConnectings.Get(itCheck.Index);
                    var PeerNum  = itPeer.Data.PeerNum;
                    var NamePort = itCheck.Data;
                    _Connectings.Remove(itCheck);

                    try
                    {
                        Socket Sock = null;

                        AddressFamily[] AddressFamilies = { AddressFamily.InterNetwork, AddressFamily.InterNetworkV6 };

                        foreach (var i in NamePort.GetIPAddresses())
                        {
                            if (i.AddressFamily != AddressFamily.InterNetwork)
                            {
                                continue;
                            }

                            foreach (var a in AddressFamilies)
                            {
                                Sock = new Socket(a, SocketType.Stream, ProtocolType.Tcp)
                                {
                                    NoDelay           = _NoDelay,
                                    SendBufferSize    = _SendBuffSize,
                                    ReceiveBufferSize = _RecvBuffSize
                                };

                                var RecvEvent = new SocketAsyncEventArgs();
                                RecvEvent.Completed     += new EventHandler <SocketAsyncEventArgs>(_Worker);
                                RecvEvent.UserToken      = new _SConnectingInfo(itPeer.Data, Sock);
                                RecvEvent.RemoteEndPoint = new IPEndPoint(i, NamePort.Port);

                                bool ConnRet = false;

                                try
                                {
                                    ConnRet = Sock.ConnectAsync(RecvEvent);
                                }
                                catch
                                {
                                    Sock = null;
                                    continue;
                                }

                                if (!ConnRet)
                                {
                                    if (!RecvEvent.ConnectSocket.Connected) // Android(iOS는 미확인)에서 Wifi, Data 모두 끈 상태에서 여기에 들어오므로 여기서 연결여부 체크
                                    {
                                        Sock = null;
                                        continue;
                                    }

                                    _Link(itPeer.Data, Sock, RecvEvent);
                                }
                                else
                                {
                                    _ConnectTimeOut.Add((Int32)PeerNum, Sock);
                                }

                                break; // Success
                            }

                            if (Sock != null)
                            {
                                break; // Success
                            }
                        }

                        if (Sock == null)
                        {
                            throw new Exception("Can not new Socket");
                        }
                    }
                    catch (ExceptionNet Exception_)
                    {
                        if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null)
                        {
                            throw Exception_.InnerException;
                        }
                        else
                        {
                            _PeersAndConnectings.Remove(itPeer);
                            _LinkFail(PeerNum, Exception_.GetRet());
                            continue;
                        }
                    }
                    catch
                    {
                        _PeersAndConnectings.Remove(itPeer);
                        _LinkFail(PeerNum, ENetRet.SocketError);
                        continue;
                    }
                }

                for (var LFConnect = _Connects.GetPopBuf();
                     LFConnect != null;
                     LFConnect = _Connects.GetPopBuf())
                {
                    var ConnectInfo = (_SConnectingInfo)LFConnect.Event.UserToken;
                    var itPeer      = _PeersAndConnectings.Get((Int32)ConnectInfo.Key.PeerNum);
                    if (itPeer && itPeer.Data.Equals(ConnectInfo.Key))
                    {
                        if (LFConnect.NetRet == ENetRet.Ok)
                        {
                            try
                            {
                                _Link(ConnectInfo.Key, ConnectInfo.socket, LFConnect.Event);
                            }
                            catch (ExceptionNet Exception_)
                            {
                                if (Exception_.GetRet() == ENetRet.ExceptionExternal && Exception_.InnerException != null)
                                {
                                    throw Exception_.InnerException;
                                }
                                else
                                {
                                    LFConnect.NetRet = Exception_.GetRet();
                                }
                            }
                            catch
                            {
                                LFConnect.NetRet = ENetRet.SystemError;
                            }
                        }

                        if (LFConnect.NetRet != ENetRet.Ok)
                        {
                            _ConnectTimeOut.Remove(itPeer.Index);
                            _PeersAndConnectings.Remove(itPeer);
                            _LinkFail(ConnectInfo.Key.PeerNum, LFConnect.NetRet);
                        }
                    }

                    _Connects.Pop();
                }

                if (_ProcPeriod.CheckAndNextLoose())
                {
                    _ConnectTimeOut.Proc();
                }
            }