public virtual Task CloseAsync() { if (IsClosedOrClosedSent(WebSocket)) { return(TaskAsyncHelper.Empty); } var closeContext = new CloseContext(this); return(_sendQueue.Enqueue(async state => { var context = (CloseContext)state; if (IsClosedOrClosedSent(context.Handler.WebSocket)) { return; } try { await context.Handler.WebSocket .CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None) .PreserveCulture(); } catch (Exception ex) { // Swallow exceptions on close _logger.LogError("Error while closing the websocket: " + ex); } }, closeContext)); }
public Context(string address) { #if STATIC_BIND if (address == null || address.Length == 0) { this.handler = Native.ffi_context_create_embedded(); } else { this.handler = Native.ffi_context_connect(address); } #else // load library var libName = "libffi_domain.so"; var dataPath = Application.dataPath + "/Plugins/" + libName; libraryHandle = LoadLibrary(dataPath); // load methods this.nativeCloseContext = GetLibraryFunction <CloseContext>(libraryHandle, "ffi_context_close"); this.nativeContextPush = GetLibraryFunction <ContextPush>(libraryHandle, "ffi_context_push"); this.nativeContextTake = GetLibraryFunction <ContextTake>(libraryHandle, "ffi_context_take"); // start ffi context CreateContext createContext = GetLibraryFunction <CreateContext>(libraryHandle, "ffi_context_create_embedded"); contextHandle = createContext.Invoke(); #endif }
internal Task CloseAsync() { if (_isClosed) { return(TaskAsyncHelper.Empty); } var closeContext = new CloseContext(this); return(_sendQueue.Enqueue(state => { var context = (CloseContext)state; if (context.Handler._isClosed) { return TaskAsyncHelper.Empty; } context.Handler._isClosed = true; return context.Handler.WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); }, closeContext)); }
public virtual Task CloseAsync() { if (IsClosedOrClosedSent(WebSocket)) { return TaskAsyncHelper.Empty; } var closeContext = new CloseContext(this); return _sendQueue.Enqueue(async state => { var context = (CloseContext)state; if (IsClosedOrClosedSent(context.Handler.WebSocket)) { return; } try { await context.Handler.WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); } catch (Exception ex) { // Swallow exceptions on close Trace.TraceError("Error while closing the websocket: " + ex); } }, closeContext); }
internal Task CloseAsync() { if (_isClosed) { return TaskAsyncHelper.Empty; } var closeContext = new CloseContext(this); return _sendQueue.Enqueue(state => { var context = (CloseContext)state; if (context.Handler._isClosed) { return TaskAsyncHelper.Empty; } context.Handler._isClosed = true; return context.Handler.WebSocket.CloseOutputAsync(WebSocketCloseStatus.NormalClosure, "", CancellationToken.None); }, closeContext); }