本文整理汇总了C#中PayloadData类的典型用法代码示例。如果您正苦于以下问题:C# PayloadData类的具体用法?C# PayloadData怎么用?C# PayloadData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PayloadData类属于命名空间,在下文中一共展示了PayloadData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CloseEventArgs
internal CloseEventArgs(PayloadData data)
: base(Opcode.CLOSE, data)
{
_code = getCodeFrom (data);
_reason = getReasonFrom (data);
_clean = false;
}
示例2: CloseEventArgs
internal CloseEventArgs(PayloadData payload)
{
var data = payload.ApplicationData;
_code = getCodeFrom (data);
_reason = getReasonFrom (data);
_clean = false;
}
示例3: CloseEventArgs
internal CloseEventArgs ()
{
_payloadData = new PayloadData ();
_rawData = _payloadData.ApplicationData;
_code = (ushort) CloseStatusCode.NoStatusCode;
_reason = String.Empty;
}
示例4: Create
public static OkPayload Create(PayloadData payload)
{
var reader = new ByteArrayReader(payload.ArraySegment);
reader.ReadByte(Signature);
var affectedRowCount = checked((int) reader.ReadLengthEncodedInteger());
var lastInsertId = checked((long) reader.ReadLengthEncodedInteger());
var serverStatus = (ServerStatus) reader.ReadUInt16();
var warningCount = (int) reader.ReadUInt16();
return new OkPayload(affectedRowCount, lastInsertId, serverStatus, warningCount);
}
示例5: CloseEventArgs
internal CloseEventArgs (PayloadData payload)
{
var data = payload.ApplicationData;
var len = data.Length;
_code = len > 1
? data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) CloseStatusCode.NoStatusCode;
_reason = len > 2
? Encoding.UTF8.GetString (data.SubArray (2, len - 2))
: String.Empty;
}
示例6: CloseEventArgs
internal CloseEventArgs (PayloadData payloadData)
{
_payloadData = payloadData;
_rawData = payloadData.ApplicationData;
var len = _rawData.Length;
_code = len > 1
? _rawData.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) CloseStatusCode.NoStatus;
_reason = len > 2
? _rawData.SubArray (2, len - 2).UTF8Decode ()
: String.Empty;
}
示例7: CloseEventArgs
public CloseEventArgs(PayloadData data)
: base(Opcode.CLOSE, data)
{
_code = (ushort)CloseStatusCode.NO_STATUS_CODE;
_reason = String.Empty;
_wasClean = false;
if (data.Length >= 2)
_code = Ext.To<ushort>(Ext.SubArray(data.ToBytes(), 0, 2), ByteOrder.BIG);
if (data.Length > 2)
{
var buffer = Ext.SubArray(data.ToBytes(), 2, (int)(data.Length - 2));
_reason = Encoding.UTF8.GetString(buffer);
}
}
示例8: SetPayloadData
internal virtual void SetPayloadData(System.String field, byte[] data, int offset, int length)
{
fieldToData[field] = new PayloadData(0, data, offset, length);
}
示例9: close
private void close(PayloadData data)
{
_logger.Debug ("Is this thread background?: " + Thread.CurrentThread.IsBackground);
var sent = false;
CloseEventArgs args = null;
lock (_forClose)
{
if (_readyState == WebSocketState.CLOSING || _readyState == WebSocketState.CLOSED)
return;
var current = _readyState;
_readyState = WebSocketState.CLOSING;
args = new CloseEventArgs (data);
if (current == WebSocketState.CONNECTING)
{
if (!_client)
{
close (HttpStatusCode.BadRequest);
return;
}
}
else
{
if (!data.ContainsReservedCloseStatusCode)
sent = send (createControlFrame (Opcode.CLOSE, data, _client));
}
}
var received = Thread.CurrentThread.IsBackground ||
(_exitReceiving != null && _exitReceiving.WaitOne (5 * 1000));
var released = closeResources ();
args.WasClean = sent && received && released;
_logger.Debug ("Was clean?: " + args.WasClean);
_readyState = WebSocketState.CLOSED;
OnClose.Emit (this, args);
_logger.Trace ("Exit close method.");
}
示例10: pong
private void pong(PayloadData data)
{
var frame = createFrame(Fin.FINAL, Opcode.PONG, data);
send(frame);
}
示例11: close
private void close(PayloadData payload, bool send, bool wait)
{
lock (_forClose)
{
if (_readyState == WebSocketState.CLOSING || _readyState == WebSocketState.CLOSED)
return;
_readyState = WebSocketState.CLOSING;
}
_logger.Trace ("Start closing handshake.");
var args = new CloseEventArgs (payload);
args.WasClean = _client
? close (
send ? WsFrame.CreateCloseFrame (Mask.MASK, payload).ToByteArray () : null,
wait ? 5000 : 0,
closeClientResources)
: close (
send ? WsFrame.CreateCloseFrame (Mask.UNMASK, payload).ToByteArray () : null,
wait ? 1000 : 0,
closeServerResources);
_readyState = WebSocketState.CLOSED;
OnClose.Emit (this, args);
_logger.Trace ("End closing handshake.");
}
示例12: close
private void close(PayloadData payload, bool send, bool wait)
{
lock (_forConn) {
if (_readyState == WebSocketState.Closing || _readyState == WebSocketState.Closed) {
_logger.Info ("Closing the WebSocket connection has already been done.");
return;
}
_readyState = WebSocketState.Closing;
}
_logger.Trace ("Start closing handshake.");
var args = new CloseEventArgs (payload);
args.WasClean =
_client
? closeHandshake (
send ? WsFrame.CreateCloseFrame (Mask.Mask, payload).ToByteArray () : null,
wait ? 5000 : 0,
closeClientResources)
: closeHandshake (
send ? WsFrame.CreateCloseFrame (Mask.Unmask, payload).ToByteArray () : null,
wait ? 1000 : 0,
closeServerResources);
_logger.Trace ("End closing handshake.");
_readyState = WebSocketState.Closed;
try {
OnClose.Emit (this, args);
}
catch (Exception ex) {
_logger.Fatal (ex.ToString ());
error ("An exception has occurred while OnClose.");
}
}
示例13: close
private void close(ushort code, string reason)
{
var data = new List<byte>(Ext.ToBytes(code, ByteOrder.BIG));
if (!Ext.IsNullOrEmpty(reason))
{
var buffer = Encoding.UTF8.GetBytes(reason);
data.AddRange(buffer);
}
var payloadData = new PayloadData(data.ToArray());
if (payloadData.Length > 125)
{
var msg = "A Close frame must have a payload length of 125 bytes or less.";
onError(msg);
return;
}
close(payloadData);
}
示例14: getCodeFrom
private static ushort getCodeFrom(PayloadData data)
{
var appData = data.ApplicationData;
return appData.Length >= 2
? appData.SubArray (0, 2).To<ushort> (ByteOrder.BIG)
: (ushort) CloseStatusCode.NO_STATUS_CODE;
}
示例15: close
private void close(PayloadData data)
{
#if DEBUG
Console.WriteLine("WS: [email protected]: Current thread IsBackground?: {0}", Thread.CurrentThread.IsBackground);
#endif
lock(_forClose)
{
// Whether the closing handshake has been started already?
if (_readyState == WsState.CLOSING || _readyState == WsState.CLOSED)
return;
// Whether the closing handshake on server is started before the connection has been established?
if (_readyState == WsState.CONNECTING && !_client)
{
sendResponseHandshake(HttpStatusCode.BadRequest);
onClose(new CloseEventArgs(data));
return;
}
_readyState = WsState.CLOSING;
}
// Whether a payload data contains the close status code which must not be set for send?
if (data.ContainsReservedCloseStatusCode)
{
onClose(new CloseEventArgs(data));
return;
}
closeHandshake(data);
#if DEBUG
Console.WriteLine("WS: [email protected]: Exit close method.");
#endif
}