Browse Source

Modified MessageEventArgs.cs, WsFrame.cs

pull/21/merge
sta 12 years ago
parent
commit
db9be84e85
  1. BIN
      Example/bin/Debug/example.exe
  2. BIN
      Example/bin/Debug/websocket-sharp.dll
  3. BIN
      Example/bin/Debug_Ubuntu/example.exe
  4. BIN
      Example/bin/Debug_Ubuntu/websocket-sharp.dll
  5. BIN
      Example/bin/Release/example.exe
  6. BIN
      Example/bin/Release/websocket-sharp.dll
  7. BIN
      Example/bin/Release_Ubuntu/example.exe
  8. BIN
      Example/bin/Release_Ubuntu/websocket-sharp.dll
  9. BIN
      Example1/bin/Debug/example1.exe
  10. BIN
      Example1/bin/Debug/websocket-sharp.dll
  11. BIN
      Example1/bin/Debug_Ubuntu/example1.exe
  12. BIN
      Example1/bin/Debug_Ubuntu/websocket-sharp.dll
  13. BIN
      Example1/bin/Release/example1.exe
  14. BIN
      Example1/bin/Release/websocket-sharp.dll
  15. BIN
      Example1/bin/Release_Ubuntu/example1.exe
  16. BIN
      Example1/bin/Release_Ubuntu/websocket-sharp.dll
  17. BIN
      Example2/bin/Debug/example2.exe
  18. BIN
      Example2/bin/Debug/websocket-sharp.dll
  19. BIN
      Example2/bin/Debug_Ubuntu/example2.exe
  20. BIN
      Example2/bin/Debug_Ubuntu/websocket-sharp.dll
  21. BIN
      Example2/bin/Release/example2.exe
  22. BIN
      Example2/bin/Release/websocket-sharp.dll
  23. BIN
      Example2/bin/Release_Ubuntu/example2.exe
  24. BIN
      Example2/bin/Release_Ubuntu/websocket-sharp.dll
  25. BIN
      Example3/bin/Debug/Example3.exe
  26. BIN
      Example3/bin/Debug/websocket-sharp.dll
  27. BIN
      Example3/bin/Debug_Ubuntu/Example3.exe
  28. BIN
      Example3/bin/Debug_Ubuntu/websocket-sharp.dll
  29. BIN
      Example3/bin/Release/Example3.exe
  30. BIN
      Example3/bin/Release/websocket-sharp.dll
  31. BIN
      Example3/bin/Release_Ubuntu/Example3.exe
  32. BIN
      Example3/bin/Release_Ubuntu/websocket-sharp.dll
  33. 5
      websocket-sharp/MessageEventArgs.cs
  34. 109
      websocket-sharp/WsFrame.cs
  35. BIN
      websocket-sharp/bin/Debug/websocket-sharp.dll
  36. BIN
      websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll
  37. BIN
      websocket-sharp/bin/Release/websocket-sharp.dll
  38. BIN
      websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll
  39. 2
      websocket-sharp/doc/mdoc/index.xml

BIN
Example/bin/Debug/example.exe

BIN
Example/bin/Debug/websocket-sharp.dll

BIN
Example/bin/Debug_Ubuntu/example.exe

BIN
Example/bin/Debug_Ubuntu/websocket-sharp.dll

BIN
Example/bin/Release/example.exe

BIN
Example/bin/Release/websocket-sharp.dll

BIN
Example/bin/Release_Ubuntu/example.exe

BIN
Example/bin/Release_Ubuntu/websocket-sharp.dll

BIN
Example1/bin/Debug/example1.exe

BIN
Example1/bin/Debug/websocket-sharp.dll

BIN
Example1/bin/Debug_Ubuntu/example1.exe

BIN
Example1/bin/Debug_Ubuntu/websocket-sharp.dll

BIN
Example1/bin/Release/example1.exe

BIN
Example1/bin/Release/websocket-sharp.dll

BIN
Example1/bin/Release_Ubuntu/example1.exe

BIN
Example1/bin/Release_Ubuntu/websocket-sharp.dll

BIN
Example2/bin/Debug/example2.exe

BIN
Example2/bin/Debug/websocket-sharp.dll

BIN
Example2/bin/Debug_Ubuntu/example2.exe

BIN
Example2/bin/Debug_Ubuntu/websocket-sharp.dll

BIN
Example2/bin/Release/example2.exe

BIN
Example2/bin/Release/websocket-sharp.dll

BIN
Example2/bin/Release_Ubuntu/example2.exe

BIN
Example2/bin/Release_Ubuntu/websocket-sharp.dll

BIN
Example3/bin/Debug/Example3.exe

BIN
Example3/bin/Debug/websocket-sharp.dll

BIN
Example3/bin/Debug_Ubuntu/Example3.exe

BIN
Example3/bin/Debug_Ubuntu/websocket-sharp.dll

BIN
Example3/bin/Release/Example3.exe

BIN
Example3/bin/Release/websocket-sharp.dll

BIN
Example3/bin/Release_Ubuntu/Example3.exe

BIN
Example3/bin/Release_Ubuntu/websocket-sharp.dll

5
websocket-sharp/MessageEventArgs.cs

@ -78,9 +78,8 @@ namespace WebSocketSharp {
/// </value>
public string Data {
get {
_data = _data != null
? _data
: _rawData.LongLength == 0
if (_data == null)
_data = _rawData.LongLength == 0
? String.Empty
: _opcode == Opcode.TEXT
? Encoding.UTF8.GetString(_rawData)

109
websocket-sharp/WsFrame.cs

@ -113,13 +113,13 @@ namespace WebSocketSharp {
internal bool IsBinary {
get {
return isBinary(Opcode);
return Opcode == Opcode.BINARY;
}
}
internal bool IsClose {
get {
return isClose(Opcode);
return Opcode == Opcode.CLOSE;
}
}
@ -131,55 +131,64 @@ namespace WebSocketSharp {
internal bool IsContinuation {
get {
return isContinuation(Opcode);
return Opcode == Opcode.CONT;
}
}
internal bool IsControl {
get {
return isControl(Opcode);
var opcode = Opcode;
return opcode == Opcode.CLOSE || opcode == Opcode.PING || opcode == Opcode.PONG;
}
}
internal bool IsData {
get {
return isData(Opcode);
var opcode = Opcode;
return opcode == Opcode.BINARY || opcode == Opcode.TEXT;
}
}
internal bool IsFinal {
get {
return isFinal(Fin);
return Fin == Fin.FINAL;
}
}
internal bool IsFragmented {
get {
return !IsFinal || IsContinuation;
return Fin == Fin.MORE || Opcode == Opcode.CONT;
}
}
internal bool IsMasked {
get {
return isMasked(Mask);
return Mask == Mask.MASK;
}
}
internal bool IsPerMessageCompressed {
get {
var opcode = Opcode;
return (opcode == Opcode.BINARY || opcode == Opcode.TEXT) && Rsv1 == Rsv.ON;
}
}
internal bool IsPing {
get {
return isPing(Opcode);
return Opcode == Opcode.PING;
}
}
internal bool IsPong {
get {
return isPong(Opcode);
return Opcode == Opcode.PONG;
}
}
internal bool IsText {
get {
return isText(Opcode);
return Opcode == Opcode.TEXT;
}
}
@ -189,19 +198,6 @@ namespace WebSocketSharp {
}
}
internal bool PerMessageCompressed {
get {
return IsData && IsCompressed;
}
set {
if (value && !IsData)
return;
Rsv1 = value ? Rsv.ON : Rsv.OFF;
}
}
#endregion
#region Public Properties
@ -230,24 +226,20 @@ namespace WebSocketSharp {
#region Private Methods
private static WsFrame createCloseFrame(WebSocketException exception)
private static WsFrame createCloseFrame(CloseStatusCode code, string message)
{
using (var buffer = new MemoryStream())
{
var code = (ushort)exception.Code;
var msg = exception.Message;
buffer.Write(code.ToByteArray(ByteOrder.BIG), 0, 2);
if (msg.Length != 0)
var tmp = ((ushort)code).ToByteArray(ByteOrder.BIG);
buffer.Write(tmp, 0, 2);
if (message.Length != 0)
{
var tmp = Encoding.UTF8.GetBytes(msg);
tmp = Encoding.UTF8.GetBytes(message);
buffer.Write(tmp, 0, tmp.Length);
}
buffer.Close();
var payload = new PayloadData(buffer.ToArray());
var frame = new WsFrame(Fin.FINAL, Opcode.CLOSE, Mask.UNMASK, payload);
return frame;
return new WsFrame(Fin.FINAL, Opcode.CLOSE, Mask.UNMASK, new PayloadData(buffer.ToArray()));
}
}
@ -382,9 +374,6 @@ namespace WebSocketSharp {
private static WsFrame parse(byte[] header, Stream stream, bool unmask)
{
if (header == null || header.Length != 2)
return null;
/* Header */
// FIN
@ -403,7 +392,7 @@ namespace WebSocketSharp {
var payloadLen = (byte)(header[1] & 0x7f);
if (isControl(opcode) && payloadLen > 125)
throw new WebSocketException(CloseStatusCode.INCONSISTENT_DATA,
return createCloseFrame(CloseStatusCode.INCONSISTENT_DATA,
"The payload length of a control frame must be 125 bytes or less.");
var frame = new WsFrame {
@ -429,7 +418,8 @@ namespace WebSocketSharp {
: new byte[]{};
if (extLen > 0 && extPayloadLen.Length != extLen)
throw new IOException();
return createCloseFrame(CloseStatusCode.ABNORMAL,
"'Extended Payload Length' of a frame cannot be read from the data stream.");
frame.ExtPayloadLen = extPayloadLen;
@ -441,7 +431,8 @@ namespace WebSocketSharp {
: new byte[]{};
if (masked && maskingKey.Length != 4)
throw new IOException();
return createCloseFrame(CloseStatusCode.ABNORMAL,
"'Masking Key' of a frame cannot be read from the data stream.");
frame.MaskingKey = maskingKey;
@ -457,14 +448,18 @@ namespace WebSocketSharp {
if (dataLen > 0)
{
if (payloadLen > 126 && dataLen > PayloadData.MaxLength)
throw new WebSocketException(CloseStatusCode.TOO_BIG);
{
var code = CloseStatusCode.TOO_BIG;
return createCloseFrame(code, code.GetMessage());
}
data = dataLen > 1024
? stream.ReadBytesInternal((long)dataLen, 1024)
: stream.ReadBytesInternal((int)dataLen);
if (data.LongLength != (long)dataLen)
throw new IOException();
return createCloseFrame(CloseStatusCode.ABNORMAL,
"'Payload Data' of a frame cannot be read from the data stream.");
}
else
{
@ -559,11 +554,10 @@ namespace WebSocketSharp {
try
{
var header = stream.ReadBytesInternal(2);
frame = parse(header, stream, unmask);
}
catch (WebSocketException ex)
{
frame = createCloseFrame(ex);
frame = header.Length == 2
? parse(header, stream, unmask)
: createCloseFrame(CloseStatusCode.ABNORMAL,
"'Header' of a frame cannot be read from the data stream.");
}
catch (Exception ex)
{
@ -594,17 +588,20 @@ namespace WebSocketSharp {
try
{
var readLen = stream.EndRead(ar);
if (readLen > 0)
if (readLen == 1)
{
if (readLen == 1)
header[1] = (byte)stream.ReadByte();
frame = parse(header, stream, unmask);
var tmp = stream.ReadByte();
if (tmp > -1)
{
header[1] = (byte)tmp;
readLen++;
}
}
}
catch (WebSocketException ex)
{
frame = createCloseFrame(ex);
frame = readLen == 2
? parse(header, stream, unmask)
: createCloseFrame(CloseStatusCode.ABNORMAL,
"'Header' of a frame cannot be read from the data stream.");
}
catch (Exception ex)
{

BIN
websocket-sharp/bin/Debug/websocket-sharp.dll

BIN
websocket-sharp/bin/Debug_Ubuntu/websocket-sharp.dll

BIN
websocket-sharp/bin/Release/websocket-sharp.dll

BIN
websocket-sharp/bin/Release_Ubuntu/websocket-sharp.dll

2
websocket-sharp/doc/mdoc/index.xml

@ -1,6 +1,6 @@
<Overview>
<Assemblies>
<Assembly Name="websocket-sharp" Version="1.0.2.41351">
<Assembly Name="websocket-sharp" Version="1.0.2.2226">
<AssemblyPublicKey>[00 24 00 00 04 80 00 00 94 00 00 00 06 02 00 00 00 24 00 00 52 53 41 31 00 04 00 00 11 00 00 00 29 17 fb 89 fe c3 91 f7 2b cb 8b e2 61 d2 3f 05 93 6d 65 a8 9e 63 72 a6 f5 d5 2c f2 9d 20 fa 0b c0 70 6a f6 88 7e 8b 90 3f 39 f5 76 c8 48 e0 bb 7b b2 7b ed d3 10 a7 1a 0f 70 98 0f 7f f4 4b 53 09 d2 a5 ef 36 c3 56 b4 aa f0 91 72 63 25 07 89 e0 93 3e 3f 2e f2 b9 73 0e 12 15 5d 43 56 c3 f4 70 a5 89 fe f7 f6 ac 3e 77 c2 d8 d0 84 91 f4 0c d1 f3 8e dc c3 c3 b8 38 3d 0c bf 17 de 20 78 c1 ]</AssemblyPublicKey>
<Attributes>
<Attribute>

Loading…
Cancel
Save