本文整理汇总了C#中WebSocketCloseStatus类的典型用法代码示例。如果您正苦于以下问题:C# WebSocketCloseStatus类的具体用法?C# WebSocketCloseStatus怎么用?C# WebSocketCloseStatus使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebSocketCloseStatus类属于命名空间,在下文中一共展示了WebSocketCloseStatus类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: OnClose
public override void OnClose(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
if (this.SocketDisconnected != null)
this.SocketDisconnected(this, this);
base.OnClose(closeStatus, closeStatusDescription);
}
开发者ID:meungblut,项目名称:Websockets,代码行数:7,代码来源:OwinWebSocketConnection.cs
示例2: CloseAsync
public Task CloseAsync(
WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken)
{
throw new PlatformNotSupportedException(SR.net_WebSockets_UnsupportedPlatform);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:WebSocketHandle.Unix.cs
示例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;
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:WebSocketPipe.cs
示例4: CloseAsync
public Task CloseAsync(
WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken)
{
return _webSocket.CloseAsync(closeStatus, statusDescription, cancellationToken);
}
开发者ID:noahfalk,项目名称:corefx,代码行数:7,代码来源:WebSocketHandle.Windows.cs
示例5: CloseAsync
public Task CloseAsync(
WebSocketCloseStatus webSocketCloseStatus,
string statusDescription,
CancellationToken cancellationToken)
{
return Task.Run(() => this.socket.Close(), cancellationToken);
}
开发者ID:meungblut,项目名称:Websockets,代码行数:7,代码来源:WebSocket4NetSocketClient.cs
示例6: OnClose
public override void OnClose(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
_isAvailable = false;
_context.CloseStatus = closeStatus;
_context.CloseStatusDescription = closeStatusDescription;
_connection.OnClose?.Invoke();
}
开发者ID:tdupont750,项目名称:Owin.WebSocket,代码行数:7,代码来源:FleckWebSocketConnection.cs
示例7: WebSocketReceiveResult
public WebSocketReceiveResult (int count,
WebSocketMessageType messageType,
bool endOfMessage,
WebSocketCloseStatus? closeStatus,
string closeStatusDescription)
{
throw new NotImplementedException ();
}
开发者ID:symform,项目名称:mono,代码行数:8,代码来源:WebSocketReceiveResult.cs
示例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);
}
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:WebSocketReceiveResultTests.cs
示例9: WebSocketReceiveResult
public WebSocketReceiveResult (int count,
WebSocketMessageType messageType,
bool endOfMessage,
WebSocketCloseStatus? closeStatus,
string closeStatusDescription)
{
MessageType = messageType;
CloseStatus = closeStatus;
CloseStatusDescription = closeStatusDescription;
Count = count;
EndOfMessage = endOfMessage;
}
开发者ID:Profit0004,项目名称:mono,代码行数:12,代码来源:WebSocketReceiveResult.cs
示例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;
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:17,代码来源:WebSocketReceiveResult.cs
示例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();
}
}
开发者ID:leloulight,项目名称:Hosting,代码行数:18,代码来源:TestWebSocket.cs
示例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);
}
开发者ID:Corillian,项目名称:corefx,代码行数:21,代码来源:WebSocketReceiveResultTests.cs
示例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);
}
}
开发者ID:leloulight,项目名称:Hosting,代码行数:22,代码来源:TestWebSocket.cs
示例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));
}
}
开发者ID:dotnet,项目名称:corefx,代码行数:37,代码来源:WebSocketValidate.cs
示例15: SendCloseAsync
public static Task SendCloseAsync(this WebSocket webSocket, WebSocketCloseStatus closeStatus, CancellationToken cancellationToken)
{
return webSocket.CloseAsync(closeStatus, null, cancellationToken);
}
开发者ID:tmds,项目名称:Tmds.SockJS,代码行数:4,代码来源:WebSocketExtensions.cs
示例16: ConvertCloseBuffer
internal void ConvertCloseBuffer(WebSocketProtocolComponent.Action action,
WebSocketProtocolComponent.Buffer buffer,
out WebSocketCloseStatus closeStatus,
out string reason)
{
ThrowIfDisposed();
IntPtr bufferData;
uint bufferLength;
closeStatus = (WebSocketCloseStatus)buffer.CloseStatus.CloseStatus;
UnwrapWebSocketBuffer(buffer, WebSocketProtocolComponent.BufferType.Close, out bufferData, out bufferLength);
if (bufferData == IntPtr.Zero)
{
reason = null;
}
else
{
ArraySegment<byte> reasonBlob;
if (this.IsNativeBuffer(bufferData, bufferLength))
{
reasonBlob = new ArraySegment<byte>(m_InternalBuffer.Array,
this.GetOffset(bufferData),
(int)bufferLength);
}
else
{
Contract.Assert(false, "'buffer' MUST reference a memory segment within the pinned InternalBuffer.");
// Indicates a violation in the contract with native Websocket.dll and could indicate
// memory corruption because the internal buffer is shared between managed and native code
throw new AccessViolationException();
}
// No need to wrap DecoderFallbackException for invalid UTF8 chacters, because
// Encoding.UTF8 will not throw but replace invalid characters instead.
reason = Encoding.UTF8.GetString(reasonBlob.Array, reasonBlob.Offset, reasonBlob.Count);
}
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:38,代码来源:WebSocketBuffer.cs
示例17: OnCloseAsync
public override Task OnCloseAsync(WebSocketCloseStatus? closeStatus, string closeStatusDescription)
{
Server.Stop();
return base.OnCloseAsync(closeStatus, closeStatusDescription);
}
开发者ID:modulexcite,项目名称:PowerShellEditorServices,代码行数:6,代码来源:WebsocketServerChannel.cs
示例18: CloseOutputAsync
public abstract Task CloseOutputAsync (WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken);
开发者ID:Profit0004,项目名称:mono,代码行数:3,代码来源:WebSocket.cs
示例19: CloseOutputAsync
public override Task CloseOutputAsync(
WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken)
{
_operation.InterlockedCheckAndUpdateState(WebSocketState.CloseSent, s_validCloseOutputStates);
using (CancellationTokenRegistration ctr = ThrowOrRegisterCancellation(cancellationToken))
{
lock (_operation.Lock)
{
_operation.CheckValidState(s_validCloseOutputStatesAfterUpdate);
uint ret;
_operation.TcsCloseOutput = new TaskCompletionSource<bool>();
if (!string.IsNullOrEmpty(statusDescription))
{
byte[] statusDescriptionBuffer = Encoding.UTF8.GetBytes(statusDescription);
ret = Interop.WinHttp.WinHttpWebSocketShutdown(
_operation.WebSocketHandle,
(ushort)closeStatus,
statusDescriptionBuffer,
(uint)statusDescriptionBuffer.Length);
}
else
{
ret = Interop.WinHttp.WinHttpWebSocketShutdown(
_operation.WebSocketHandle,
(ushort)closeStatus,
IntPtr.Zero,
0);
}
if (ret != Interop.WinHttp.ERROR_SUCCESS)
{
throw WinHttpException.CreateExceptionUsingError((int)ret);
}
}
return _operation.TcsCloseOutput.Task;
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:44,代码来源:WinHttpWebSocket.cs
示例20: CloseAsync
public override async Task CloseAsync(
WebSocketCloseStatus closeStatus,
string statusDescription,
CancellationToken cancellationToken)
{
_operation.InterlockedCheckAndUpdateState(WebSocketState.CloseSent, s_validCloseStates);
using (CancellationTokenRegistration ctr = ThrowOrRegisterCancellation(cancellationToken))
{
_operation.TcsClose = new TaskCompletionSource<bool>();
await InternalCloseAsync(closeStatus, statusDescription).ConfigureAwait(false);
UpdateServerCloseStatus();
}
}
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:WinHttpWebSocket.cs
注:本文中的WebSocketCloseStatus类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论