Refactored a few for WebSocket.cs

This commit is contained in:
sta 2015-08-05 16:37:53 +09:00
parent 586a6202a2
commit 776fee9170
2 changed files with 20 additions and 20 deletions

View File

@ -366,7 +366,7 @@ namespace WebSocketSharp.Server
_websocket.OnError += onError; _websocket.OnError += onError;
_websocket.OnClose += onClose; _websocket.OnClose += onClose;
_websocket.ConnectAsServer (); _websocket.Accept ();
} }
#endregion #endregion

View File

@ -601,7 +601,7 @@ namespace WebSocketSharp
var msg = checkIfValidHandshakeRequest (_context); var msg = checkIfValidHandshakeRequest (_context);
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
error ("An error has occurred while connecting.", null); error ("An error has occurred while accepting.", null);
Close (HttpStatusCode.BadRequest); Close (HttpStatusCode.BadRequest);
return false; return false;
@ -760,7 +760,7 @@ namespace WebSocketSharp
var msg = _readyState.CheckIfConnectable (); var msg = _readyState.CheckIfConnectable ();
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
error ("An error has occurred in connecting.", null); error ("An error has occurred in handshaking.", null);
return false; return false;
} }
@ -773,7 +773,7 @@ namespace WebSocketSharp
} }
} }
catch (Exception ex) { catch (Exception ex) {
processException (ex, "An exception has occurred while connecting."); processException (ex, "An exception has occurred while handshaking.");
} }
return false; return false;
@ -1536,6 +1536,20 @@ namespace WebSocketSharp
#region Internal Methods #region Internal Methods
// As server
internal void Accept ()
{
try {
if (acceptHandshake ()) {
_readyState = WebSocketState.Open;
open ();
}
}
catch (Exception ex) {
processException (ex, "An exception has occurred while accepting.");
}
}
internal static string CheckCloseParameters (ushort code, string reason, bool client) internal static string CheckCloseParameters (ushort code, string reason, bool client)
{ {
return !code.IsCloseStatusCode () return !code.IsCloseStatusCode ()
@ -1610,20 +1624,6 @@ namespace WebSocketSharp
} }
} }
// As server
internal void ConnectAsServer ()
{
try {
if (acceptHandshake ()) {
_readyState = WebSocketState.Open;
open ();
}
}
catch (Exception ex) {
processException (ex, "An exception has occurred while connecting.");
}
}
// As client // As client
internal static string CreateBase64Key () internal static string CreateBase64Key ()
{ {
@ -2029,7 +2029,7 @@ namespace WebSocketSharp
var msg = checkIfCanConnect (); var msg = checkIfCanConnect ();
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
error ("An error has occurred in connecting.", null); error ("An error has occurred in handshaking.", null);
return; return;
} }
@ -2049,7 +2049,7 @@ namespace WebSocketSharp
var msg = checkIfCanConnect (); var msg = checkIfCanConnect ();
if (msg != null) { if (msg != null) {
_logger.Error (msg); _logger.Error (msg);
error ("An error has occurred in connecting.", null); error ("An error has occurred in handshaking.", null);
return; return;
} }