public void Start(string host, ushort port) { _eventBase = Event.EventBaseNew(); if (_eventBase.IsInvalid) throw new IOException("Unable to create event_base"); _evHttp = Event.EvHttpNew(_eventBase); if (_evHttp.IsInvalid) { Dispose(); throw new IOException ("Unable to create evhttp"); } _socket = Event.EvHttpBindSocketWithHandle(_evHttp, host, port); if (_socket.IsInvalid) { Dispose(); throw new IOException("Unable to bind to the specified address"); } _thread = new Thread(MainCycle) {Priority = ThreadPriority.Highest}; _thread.Start(); }
public Task StopListeningAsync() { return SyncTask(() => { if (_socket == null || _socket.IsInvalid) throw new InvalidOperationException("Server isn't listening"); Event.EvHttpDelAcceptSocket(_evHttp, _socket); _socket = null; }); }
void Start(EvHttpBoundSocket boundSocket) { _socket = boundSocket; if (_socket.IsInvalid) { Dispose(); throw new IOException("Unable to bind to the specified address"); } var tcs = new TaskCompletionSource<object>(); _thread = new Thread(() => MainCycle(tcs)) { Priority = ThreadPriority.Highest }; _thread.Start(); tcs.Task.Wait(); }