/// <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 }; }
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); }
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); }
/// <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); }
internal Event(ENetEvent @event) { nativeEvent = @event; }
internal static extern int enet_host_check_events(IntPtr host, out ENetEvent @event);
internal static extern int enet_host_service(IntPtr host, out ENetEvent @event, uint timeout);
public static extern int enet_host_check_events(ENetHost *host, out ENetEvent @event);
public static extern int enet_host_service(ENetHost *host, out ENetEvent @event, uint timeout);
public Event(ENetEvent @event) { nativeEvent = @event; }
public Event(ENetEvent ev) { this.ev = ev; }
internal static extern int EnetHostService(IntPtr host, ENetEvent ev, uint timeout);
internal static extern int EnetHostCheckEvents(IntPtr host, ENetEvent ev);
internal static extern int enet_host_check_events(IntPtr host, ENetEvent ev);