Changed IsConnected to IsKeepAlive in WebSocket.cs

This commit is contained in:
sta
2012-09-03 11:55:52 +09:00
parent 3ef6d58f31
commit 85ef38084d
53 changed files with 52 additions and 57 deletions

View File

@@ -149,48 +149,36 @@ namespace WebSocketSharp
return subArray;
}
public static void Times<T>(this T n, Action act)
where T : struct
public static void Times(this int n, Action act)
{
if (typeof(T) != typeof(byte) &&
typeof(T) != typeof(Int16) &&
typeof(T) != typeof(Int32) &&
typeof(T) != typeof(Int64) &&
typeof(T) != typeof(UInt16) &&
typeof(T) != typeof(UInt32) &&
typeof(T) != typeof(UInt64))
{
throw new NotSupportedException("Not supported Struct type: " + typeof(T).ToString());
}
ulong m = (ulong)(object)n;
for (ulong i = 0; i < m; i++)
{
act();
}
((ulong)n).Times(act);
}
public static void Times<T>(this T n, Action<ulong> act)
where T : struct
public static void Times(this uint n, Action act)
{
if (typeof(T) != typeof(byte) &&
typeof(T) != typeof(Int16) &&
typeof(T) != typeof(Int32) &&
typeof(T) != typeof(Int64) &&
typeof(T) != typeof(UInt16) &&
typeof(T) != typeof(UInt32) &&
typeof(T) != typeof(UInt64))
{
throw new NotSupportedException("Not supported Struct type: " + typeof(T).ToString());
}
((ulong)n).Times(act);
}
ulong m = (ulong)(object)n;
public static void Times(this ulong n, Action act)
{
for (ulong i = 0; i < n; i++)
act();
}
for (ulong i = 0; i < m; i++)
{
public static void Times(this int n, Action<ulong> act)
{
((ulong)n).Times(act);
}
public static void Times(this uint n, Action<ulong> act)
{
((ulong)n).Times(act);
}
public static void Times(this ulong n, Action<ulong> act)
{
for (ulong i = 0; i < n; i++)
act(i);
}
}
public static T To<T>(this byte[] src, ByteOrder srcOrder)

View File

@@ -51,7 +51,7 @@ namespace WebSocketSharp.Server {
#endregion
#region Constructor
#region Constructors
public WebSocketServer(string url)
{
@@ -83,6 +83,11 @@ namespace WebSocketSharp.Server {
_services = new Dictionary<string, WebSocketService>();
}
public WebSocketServer(int port)
: this("/", port)
{
}
public WebSocketServer(string absPath, int port)
{
_uri = new Uri(absPath, UriKind.Relative);
@@ -177,7 +182,7 @@ namespace WebSocketSharp.Server {
private void startService(TcpClient client)
{
WaitCallback startCb = (state) =>
WaitCallback startSv = (state) =>
{
try {
var socket = new WebSocket(_uri, client);
@@ -188,7 +193,7 @@ namespace WebSocketSharp.Server {
error(ex.Message);
}
};
ThreadPool.QueueUserWorkItem(startCb);
ThreadPool.QueueUserWorkItem(startSv);
}
#endregion

View File

@@ -69,6 +69,7 @@ namespace WebSocketSharp
private Object _forSend;
private int _fragmentLen;
private bool _isClient;
private bool _isSecure;
private Thread _msgThread;
private NetworkStream _netStream;
private string _protocol;
@@ -109,6 +110,7 @@ namespace WebSocketSharp
_tcpClient = tcpClient;
_endPoint = (IPEndPoint)_tcpClient.Client.LocalEndPoint;
_isClient = false;
_isSecure = _endPoint.Port == 443 ? true : false;
}
#endregion
@@ -119,7 +121,6 @@ namespace WebSocketSharp
: this()
{
_uri = new Uri(url);
if (!isValidScheme(_uri))
{
var msg = "Unsupported WebSocket URI scheme: " + _uri.Scheme;
@@ -128,6 +129,7 @@ namespace WebSocketSharp
_protocols = protocols.ToString(", ");
_isClient = true;
_isSecure = _uri.Scheme == "wss" ? true : false;
}
public WebSocket(
@@ -179,7 +181,7 @@ namespace WebSocketSharp
get { return _extensions; }
}
public bool IsConnected {
public bool IsKeepAlive {
get {
if (_readyState != WsState.OPEN)
return false;
@@ -190,10 +192,7 @@ namespace WebSocketSharp
public bool IsSecure {
get {
if (_endPoint.Port == 443)
return true;
return false;
return _isSecure;
}
}
@@ -360,21 +359,19 @@ namespace WebSocketSharp
private void createClientStream()
{
string scheme = _uri.Scheme;
string host = _uri.DnsSafeHost;
int port = _uri.Port;
var host = _uri.DnsSafeHost;
var port = _uri.Port;
if (port <= 0)
{
port = 80;
if (scheme == "wss")
if (IsSecure)
port = 443;
}
_tcpClient = new TcpClient(host, port);
_netStream = _tcpClient.GetStream();
if (scheme == "wss")
if (IsSecure)
{
RemoteCertificateValidationCallback validation = (sender, certificate, chain, sslPolicyErrors) =>
{

Binary file not shown.