Ejemplo n.º 1
0
        public override bool Done()
        {
            lock (SocketUdpNativeStatic.syncer)
            {
                if (this.GotResult || pConnectionHandler == IntPtr.Zero)
                {
                    return(true);
                }

                int available = SocketUdpNativeStatic.egservice(pConnectionHandler);
                if (available < PingLength)
                {
                    return(false);
                }

                int pingBytesLength           = PingBytes.Length;
                int bytesInRemainginDatagrams =
                    SocketUdpNativeStatic.egread(pConnectionHandler, PingBytes, ref pingBytesLength);
                this.Successful = (PingBytes != null && PingBytes[PingBytes.Length - 1] == PingId);
                //Debug.Log("Successful: " + this.Successful + " bytesInRemainginDatagrams: " + bytesInRemainginDatagrams + " PingId: " + PingId);

                this.GotResult = true;
                return(true);
            }
        }
Ejemplo n.º 2
0
        public override bool StartPing(string ip)
        {
            base.Init();

            lock (SocketUdpNativeStatic.syncer)
            {
                if (pConnectionHandler == IntPtr.Zero)
                {
                    pConnectionHandler = SocketUdpNativeStatic.egconnect(ip);
                    SocketUdpNativeStatic.egservice(pConnectionHandler);
                    byte state = SocketUdpNativeStatic.eggetState(pConnectionHandler);
                    while (state == (byte)NativeSocketState.Connecting)
                    {
                        SocketUdpNativeStatic.egservice(pConnectionHandler);
                        state = SocketUdpNativeStatic.eggetState(pConnectionHandler);
                        Thread.Sleep(0);                         // suspending execution for a moment is critical on Switch for the OS to update the socket
                    }
                }

                PingBytes[PingBytes.Length - 1] = PingId;
                SocketUdpNativeStatic.egsend(pConnectionHandler, PingBytes, PingBytes.Length);
                SocketUdpNativeStatic.egservice(pConnectionHandler);

                PingBytes[PingBytes.Length - 1] = (byte)(PingId - 1);
                return(true);
            }
        }
Ejemplo n.º 3
0
 public override void Dispose()
 {
     lock (SocketUdpNativeStatic.syncer)
     {
         if (pConnectionHandler != IntPtr.Zero)
             SocketUdpNativeStatic.egdisconnect(pConnectionHandler);
         pConnectionHandler = IntPtr.Zero;
     }
     GC.SuppressFinalize(this);
 }