public static async Task<byte[]> ReadAsync(this IDataLayer layer, int length, CancellationToken cancellationToken, WebSocketErrorCode errorCode) { var buffer = new byte[length]; var read = await layer.ReadAsync(buffer, 0, buffer.Length, cancellationToken); if (read != buffer.Length) throw new WebSocketException(errorCode); return buffer; }
public static string GetDescription(this WebSocketErrorCode errorCode) { var description = ErrorCodes.ResourceManager.GetString(errorCode.ToString()); if (!string.IsNullOrEmpty(description)) { return(description); } description = errorCode.ToString(); return(description); }
public static async Task<byte[]> ReadAsync(this IDataLayer layer, int length, CancellationToken cancellationToken, WebSocketErrorCode errorCode) { var buffer = new byte[length]; var read = 0; while (read < length && !cancellationToken.IsCancellationRequested) { var chunkOffset = read; var chunkLength = length - chunkOffset; var chunkSize = await layer.ReadAsync(buffer, chunkOffset, chunkLength, cancellationToken); if (chunkSize == 0) { break; } read += chunkSize; } if (read != buffer.Length) throw new WebSocketException(errorCode); return buffer; }
public Task CloseAsync(WebSocketErrorCode errorCode) { return TaskAsyncHelper.Empty; }
public static async Task <byte[]> ReadAsync(this IDataLayer layer, int length, CancellationToken cancellationToken, WebSocketErrorCode errorCode) { var buffer = new byte[length]; var read = 0; while (read < length && !cancellationToken.IsCancellationRequested) { var chunkOffset = read; var chunkLength = length - chunkOffset; var chunkSize = await layer.ReadAsync(buffer, chunkOffset, chunkLength, cancellationToken); if (chunkSize == 0) { break; } read += chunkSize; } if (read != buffer.Length) { throw new WebSocketException(errorCode); } return(buffer); }
public virtual Task CloseAsync(WebSocketErrorCode errorCode) { _state = WebSocketState.Closed; _tcp.Dispose(); return(TaskAsyncHelper.Empty); }
public WebSocketException(WebSocketErrorCode code) : this(code, (string)null) { _errorCode = code; }
public WebSocketException(WebSocketErrorCode code, string message, Exception innerException) : base(message ?? code.GetDescription(), innerException) { _errorCode = code; }
public WebSocketException(WebSocketErrorCode code, Exception innerException) : this(code, null, innerException) { _errorCode = code; }
public virtual Task CloseAsync(WebSocketErrorCode errorCode) { _state = WebSocketState.Closed; _tcp.Dispose(); return TaskAsyncHelper.Empty; }