Exemplo n.º 1
0
 /// <summary>
 /// Initializes an event based on a native C event.
 /// </summary>
 /// <param name="event">The native C event.</param>
 public Event(ENetEvent @event)
 {
     this = new Event()
     {
         NativeData = @event
     };
 }
Exemplo n.º 2
0
        protected int CheckEvents(out Event e)
        {
            var enetEv = new ENetEvent();
            int ret    = NativeMethods.enet_host_check_events(this.host, enetEv);

            e = new Event(enetEv);
            return(ret);
        }
Exemplo n.º 3
0
        private EEvent GetEvent()
        {
            var enetEv = new ENetEvent();
            int ret    = NativeMethods.EnetHostCheckEvents(this.host, enetEv);

            if (ret <= 0)
            {
                return(null);
            }
            var e = new EEvent(enetEv);

            return(e);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends queued outgoing packets, receives incoming packets, and handles connection events.
        /// </summary>
        /// <param name="timeout">Timeout in milliseconds to wait for an event. For polling, use 0.</param>
        /// <param name="event">The event.</param>
        /// <returns>True if an event occured, otherwise false.</returns>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="timeout"/> is negative.</exception>
        /// <exception cref="InvalidOperationException">The host is not initialized.</exception>
        /// <exception cref="ENetException">An error occured.</exception>
        public bool Service(int timeout, out Event @event)
        {
            if (timeout < 0)
            {
                throw new ArgumentOutOfRangeException("timeout");
            }
            CheckInitialized(); ENetEvent nativeEvent = new ENetEvent();

            // As of 1.3.6, ENet is not signal safe, and Mono uses signals for garbage collection.
            //
            // So, there's really nothing better we can do than retry. Luckily the cases that return -1
            // are cases that return immediately or this could cause lockups.
            //
            // The entire situation is still very dicey with MonoDevelop.
            // A proper fix really has to be done in the ENet native library.
            // If you want to eliminate this entirely and don't care about these spurious
            // failures of enet_host_service, try/catch the ENetException and just ignore it.
            // That's essentially what I am doing here, except with an upper limit so real errors
            // can get through...
            int ret = -1;

            for (int nretries = 0; nretries < 1000 && ret == -1; nretries++)
            {
                ret = ENetApi.enet_host_service(NativeData, out nativeEvent, (uint)timeout);
            }

            if (ret < 0)
            {
                throw new ENetException(string.Format("Service failed (native data {0}).", (IntPtr)NativeData));
            }
            if (ret == 0)
            {
                @event = new Event(); return(false);
            }
            @event = new Event(nativeEvent); return(true);
        }
Exemplo n.º 5
0
 internal Event(ENetEvent @event)
 {
     nativeEvent = @event;
 }
Exemplo n.º 6
0
 internal static extern int enet_host_check_events(IntPtr host, out ENetEvent @event);
Exemplo n.º 7
0
 internal static extern int enet_host_service(IntPtr host, out ENetEvent @event, uint timeout);
Exemplo n.º 8
0
 public static extern int enet_host_check_events(ENetHost *host, out ENetEvent @event);
Exemplo n.º 9
0
 public static extern int enet_host_service(ENetHost *host, out ENetEvent @event, uint timeout);
Exemplo n.º 10
0
 public Event(ENetEvent @event)
 {
     nativeEvent = @event;
 }
Exemplo n.º 11
0
 public Event(ENetEvent ev)
 {
     this.ev = ev;
 }
Exemplo n.º 12
0
		internal static extern int EnetHostService(IntPtr host, ENetEvent ev, uint timeout);
Exemplo n.º 13
0
		internal static extern int EnetHostCheckEvents(IntPtr host, ENetEvent ev);
Exemplo n.º 14
0
 internal static extern int enet_host_check_events(IntPtr host, ENetEvent ev);