本文整理汇总了C#中WebSocketCloseStatus类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketCloseStatus类的具体用法?C# WebSocketCloseStatus怎么用?C# WebSocketCloseStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketCloseStatus类属于命名空间,在下文中一共展示了WebSocketCloseStatus类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnClose
public override void OnClose(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
if (this.SocketDisconnected != null)
this.SocketDisconnected(this, this);
base.OnClose(closeStatus, closeStatusDescription);
}
示例2: CloseAsync
public Task CloseAsync(
WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken)
{
throw new PlatformNotSupportedException(SR.net_WebSockets_UnsupportedPlatform);
}
示例3: WriteCloseFragmentAsync
public Task WriteCloseFragmentAsync(WebSocketCloseStatus closeStatus, string statusDescription) {
TaskCompletionSource<object> tcs = new TaskCompletionSource<object>();
// Callback will always be called (since it is responsible for cleanup), even if completed synchronously
CompletionCallback callback = (hrError, cbIO, fUtf8Encoded, fFinalFragment, fClose) => {
try {
ThrowExceptionForHR(hrError);
tcs.TrySetResult(null); // regular completion
}
catch (Exception ex) {
tcs.TrySetException(ex); // exceptional completion
}
};
IntPtr completionContext = GCUtil.RootObject(callback);
// Call the underlying implementation; SendConnectionClose should never throw an exception
bool completionExpected;
int hr = _context.SendConnectionClose(
fAsync: true,
uStatusCode: (ushort)closeStatus,
szReason: statusDescription, // don't need to pin string: CLR marshaler handles managed to unmanaged conversion, and IIS makes local copy for duration of async operation
pfnCompletion: _asyncThunkAddress,
pvCompletionContext: completionContext,
pfCompletionExpected: out completionExpected);
if (!completionExpected) {
// Completed synchronously or error; the thunk and callback together handle cleanup
AsyncCallbackThunk(hr, completionContext, cbIO: 0, fUtf8Encoded: true, fFinalFragment: true, fClose: false);
}
return tcs.Task;
}
示例4: CloseAsync
public Task CloseAsync(
WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken)
{
return _webSocket.CloseAsync(closeStatus, statusDescription, cancellationToken);
}
示例5: CloseAsync
public Task CloseAsync(
WebSocketCloseStatus webSocketCloseStatus,
string statusDescription,
CancellationToken cancellationToken)
{
return Task.Run(() => this.socket.Close(), cancellationToken);
}
示例6: OnClose
public override void OnClose(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
_isAvailable = false;
_context.CloseStatus = closeStatus;
_context.CloseStatusDescription = closeStatusDescription;
_connection.OnClose?.Invoke();
}
示例7: WebSocketReceiveResult
public WebSocketReceiveResult (int count,
WebSocketMessageType messageType,
bool endOfMessage,
WebSocketCloseStatus? closeStatus,
string closeStatusDescription)
{
throw new NotImplementedException ();
}
示例8: ConstructorTest_Success
public void ConstructorTest_Success(int count, WebSocketMessageType messageType, bool endOfMessage, WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
var wsrr = new WebSocketReceiveResult(count, messageType, endOfMessage, closeStatus, closeStatusDescription);
Assert.Equal(wsrr.Count, count);
Assert.Equal(wsrr.MessageType, messageType);
Assert.Equal(wsrr.EndOfMessage, endOfMessage);
Assert.Equal(wsrr.CloseStatus, closeStatus);
Assert.Equal(wsrr.CloseStatusDescription, closeStatusDescription);
}
示例9: WebSocketReceiveResult
public WebSocketReceiveResult (int count,
WebSocketMessageType messageType,
bool endOfMessage,
WebSocketCloseStatus? closeStatus,
string closeStatusDescription)
{
MessageType = messageType;
CloseStatus = closeStatus;
CloseStatusDescription = closeStatusDescription;
Count = count;
EndOfMessage = endOfMessage;
}
示例10: WebSocketReceiveResult
public WebSocketReceiveResult(int count,
WebSocketMessageType messageType,
bool endOfMessage,
WebSocketCloseStatus? closeStatus,
string closeStatusDescription)
{
if (count < 0)
{
throw new ArgumentOutOfRangeException("count");
}
Count = count;
EndOfMessage = endOfMessage;
MessageType = messageType;
CloseStatus = closeStatus;
CloseStatusDescription = closeStatusDescription;
}
示例11: CloseOutputAsync
public async override Task CloseOutputAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken)
{
ThrowIfDisposed();
ThrowIfOutputClosed();
var message = new Message(closeStatus, statusDescription);
await _sendBuffer.SendAsync(message, cancellationToken);
if (State == WebSocketState.Open)
{
_state = WebSocketState.CloseSent;
}
else if (State == WebSocketState.CloseReceived)
{
_state = WebSocketState.Closed;
Close();
}
}
示例12: ConstructorTest_Success
public void ConstructorTest_Success(int count, WebSocketMessageType messageType, bool endOfMessage, WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
WebSocketReceiveResult wsrr;
if (closeStatus == null && closeStatusDescription == null)
{
wsrr = new WebSocketReceiveResult(count, messageType, endOfMessage);
Assert.Equal(count, wsrr.Count);
Assert.Equal(messageType, wsrr.MessageType);
Assert.Equal(endOfMessage, wsrr.EndOfMessage);
Assert.Equal(null, wsrr.CloseStatus);
Assert.Equal(null, wsrr.CloseStatusDescription);
}
wsrr = new WebSocketReceiveResult(count, messageType, endOfMessage, closeStatus, closeStatusDescription);
Assert.Equal(count, wsrr.Count);
Assert.Equal(messageType, wsrr.MessageType);
Assert.Equal(endOfMessage, wsrr.EndOfMessage);
Assert.Equal(closeStatus, wsrr.CloseStatus);
Assert.Equal(closeStatusDescription, wsrr.CloseStatusDescription);
}
示例13: CloseAsync
public async override Task CloseAsync(WebSocketCloseStatus closeStatus, string statusDescription, CancellationToken cancellationToken)
{
ThrowIfDisposed();
if (State == WebSocketState.Open || State == WebSocketState.CloseReceived)
{
// Send a close message.
await CloseOutputAsync(closeStatus, statusDescription, cancellationToken);
}
if (State == WebSocketState.CloseSent)
{
// Do a receiving drain
var data = new byte[1024];
WebSocketReceiveResult result;
do
{
result = await ReceiveAsync(new ArraySegment<byte>(data), cancellationToken);
}
while (result.MessageType != WebSocketMessageType.Close);
}
}
示例14: ValidateCloseStatus
internal static void ValidateCloseStatus(WebSocketCloseStatus closeStatus, string statusDescription)
{
if (closeStatus == WebSocketCloseStatus.Empty && !string.IsNullOrEmpty(statusDescription))
{
throw new ArgumentException(SR.Format(SR.net_WebSockets_ReasonNotNull,
statusDescription,
WebSocketCloseStatus.Empty),
nameof(statusDescription));
}
int closeStatusCode = (int)closeStatus;
if ((closeStatusCode >= InvalidCloseStatusCodesFrom &&
closeStatusCode <= InvalidCloseStatusCodesTo) ||
closeStatusCode == CloseStatusCodeAbort ||
closeStatusCode == CloseStatusCodeFailedTLSHandshake)
{
// CloseStatus 1006 means Aborted - this will never appear on the wire and is reflected by calling WebSocket.Abort
throw new ArgumentException(SR.Format(SR.net_WebSockets_InvalidCloseStatusCode,
closeStatusCode),
nameof(closeStatus));
}
int length = 0;
if (!string.IsNullOrEmpty(statusDescription))
{
length = Encoding.UTF8.GetByteCount(statusDescription);
}
if (length > MaxControlFramePayloadLength)
{
throw new ArgumentException(SR.Format(SR.net_WebSockets_InvalidCloseStatusDescription,
statusDescription,
MaxControlFramePayloadLength),
nameof(statusDescription));
}
}
示例15: SendCloseAsync
public static Task SendCloseAsync(this WebSocket webSocket, WebSocketCloseStatus closeStatus, CancellationToken cancellationToken)
{
return webSocket.CloseAsync(closeStatus, null, cancellationToken);
}