fix Ext.cs, WebSocket.cs

This commit is contained in:
sta 2010-10-27 16:07:12 +09:00
parent 5a3545e911
commit 0a07fe449c
22 changed files with 21 additions and 40 deletions

View File

@ -1,8 +1,8 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Release_Ubuntu" ctype="Workspace" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug_Ubuntu" ctype="Workspace" />
<MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs" ctype="Workbench"> <MonoDevelop.Ide.Workbench ActiveDocument="websocket-sharp/WebSocket.cs" ctype="Workbench">
<Files> <Files>
<File FileName="websocket-sharp/WebSocket.cs" Line="263" Column="2" /> <File FileName="websocket-sharp/WebSocket.cs" Line="262" Column="15" />
</Files> </Files>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>

View File

@ -83,27 +83,6 @@ namespace WebSocketSharp
return new String(secKey.ToArray()); return new String(secKey.ToArray());
} }
public static IEnumerable<int> IndexOf<T>(this T[] array, T val)
{
for (int i = 0; i < array.Length; i++)
{
if (array[i].Equals(val))
{
yield return i;
}
}
}
public static T[] InitializeWith<T>(this T[] array, T val)
{
for (int i = 0; i < array.Length; i++)
{
array[i] = val;
}
return array;
}
public static Byte[] InitializeWithPrintableASCII(this Byte[] bytes, Random rand) public static Byte[] InitializeWithPrintableASCII(this Byte[] bytes, Random rand)
{ {
for (int i = 0; i < bytes.Length; i++) for (int i = 0; i < bytes.Length; i++)
@ -114,11 +93,11 @@ namespace WebSocketSharp
return bytes; return bytes;
} }
public static void NotEqualsDo(this string a, string b, Action<string, string> action) public static void NotEqualsDo(this string expected, string actual, Action<string, string> action)
{ {
if (a != b) if (expected != actual)
{ {
action(a, b); action(expected, actual);
} }
} }
} }

View File

@ -259,7 +259,11 @@ namespace WebSocketSharp
} }
string subProtocol = protocol != String.Empty string subProtocol = protocol != String.Empty
#if !CHALLENGE
? String.Format("WebSocket-Protocol: {0}\r\n", protocol)
#else
? String.Format("Sec-WebSocket-Protocol: {0}\r\n", protocol) ? String.Format("Sec-WebSocket-Protocol: {0}\r\n", protocol)
#endif
: protocol; : protocol;
#if !CHALLENGE #if !CHALLENGE
string secKeys = String.Empty; string secKeys = String.Empty;
@ -325,17 +329,17 @@ namespace WebSocketSharp
Console.WriteLine("{0}", s); Console.WriteLine("{0}", s);
} }
#endif #endif
Action<string, string> action = (a, b) => Action<string, string> action = (e, a) =>
{ {
throw new IOException("Invalid handshake response: " + a); throw new IOException("Invalid handshake response: " + a);
}; };
#if !CHALLENGE #if !CHALLENGE
response[0].NotEqualsDo("HTTP/1.1 101 Web Socket Protocol Handshake", action); "HTTP/1.1 101 Web Socket Protocol Handshake".NotEqualsDo(response[0], action);
#else #else
response[0].NotEqualsDo("HTTP/1.1 101 WebSocket Protocol Handshake", action); "HTTP/1.1 101 WebSocket Protocol Handshake".NotEqualsDo(response[0], action);
#endif #endif
response[1].NotEqualsDo("Upgrade: WebSocket", action); "Upgrade: WebSocket".NotEqualsDo(response[1], action);
response[2].NotEqualsDo("Connection: Upgrade", action); "Connection: Upgrade".NotEqualsDo(response[2], action);
for (int i = 3; i < response.Length; i++) for (int i = 3; i < response.Length; i++)
{ {
@ -357,17 +361,15 @@ namespace WebSocketSharp
string expectedResToHexStr = BitConverter.ToString(expectedRes); string expectedResToHexStr = BitConverter.ToString(expectedRes);
string actualResToHexStr = BitConverter.ToString(actualRes); string actualResToHexStr = BitConverter.ToString(actualRes);
actualResToHexStr.NotEqualsDo(expectedResToHexStr, (a, b) => expectedResToHexStr.NotEqualsDo(actualResToHexStr, (e, a) =>
{ {
Console.WriteLine("WS: Error @doHandshake: Invalid challenge response.");
Console.WriteLine("\texpected: {0}", b);
Console.WriteLine("\tactual : {0}", a);
throw new IOException("Invalid challenge response: " + a);
}
);
#if DEBUG #if DEBUG
Console.WriteLine("WS: Info @doHandshake: challenge response: {0}", actualResToHexStr); Console.WriteLine("WS: Error @doHandshake: Invalid challenge response.");
Console.WriteLine("\texpected: {0}", e);
Console.WriteLine("\tactual : {0}", a);
#endif #endif
throw new IOException("Invalid challenge response: " + a);
});
#endif #endif
ReadyState = WsState.OPEN; ReadyState = WsState.OPEN;
} }

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.