Modified WebSocketSessionManager.cs

This commit is contained in:
sta 2013-09-17 16:36:43 +09:00
parent 42a44226d5
commit 903a5bf46b

View File

@ -154,7 +154,7 @@ namespace WebSocketSharp.Server
/// otherwise, <see langword="null"/>. /// otherwise, <see langword="null"/>.
/// </value> /// </value>
/// <param name="id"> /// <param name="id">
/// A <see cref="string"/> that contains a session ID to find. /// A <see cref="string"/> that contains the ID of the session information to get.
/// </param> /// </param>
public IWebSocketSession this [string id] { public IWebSocketSession this [string id] {
get { get {
@ -165,17 +165,11 @@ namespace WebSocketSharp.Server
return null; return null;
} }
lock (_sync) WebSocketService session;
{ if (!TryGetServiceInstance (id, out session))
try { _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
return _sessions [id];
} return session;
catch {
_logger.Error (
"The WebSocket session with the specified ID not found.\nID: " + id);
return null;
}
}
} }
} }
@ -468,8 +462,7 @@ namespace WebSocketSharp.Server
WebSocketService session; WebSocketService session;
if (!TryGetServiceInstance (id, out session)) if (!TryGetServiceInstance (id, out session))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return; return;
} }
@ -501,8 +494,7 @@ namespace WebSocketSharp.Server
WebSocketService session; WebSocketService session;
if (!TryGetServiceInstance (id, out session)) if (!TryGetServiceInstance (id, out session))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return; return;
} }
@ -534,8 +526,7 @@ namespace WebSocketSharp.Server
WebSocketService session; WebSocketService session;
if (!TryGetServiceInstance (id, out session)) if (!TryGetServiceInstance (id, out session))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return; return;
} }
@ -564,8 +555,7 @@ namespace WebSocketSharp.Server
WebSocketService session; WebSocketService session;
if (!TryGetServiceInstance (id, out session)) if (!TryGetServiceInstance (id, out session))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return false; return false;
} }
@ -598,8 +588,7 @@ namespace WebSocketSharp.Server
WebSocketService session; WebSocketService session;
if (!TryGetServiceInstance (id, out session)) if (!TryGetServiceInstance (id, out session))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return false; return false;
} }
@ -631,8 +620,7 @@ namespace WebSocketSharp.Server
WebSocketService service; WebSocketService service;
if (!TryGetServiceInstance (id, out service)) if (!TryGetServiceInstance (id, out service))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return false; return false;
} }
@ -665,8 +653,7 @@ namespace WebSocketSharp.Server
WebSocketService service; WebSocketService service;
if (!TryGetServiceInstance (id, out service)) if (!TryGetServiceInstance (id, out service))
{ {
_logger.Error ( _logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
"The WebSocket session with the specified ID not found.\nID: " + id);
return false; return false;
} }
@ -692,12 +679,12 @@ namespace WebSocketSharp.Server
if (_stopped) if (_stopped)
break; break;
WebSocketService service; WebSocketService session;
if (_sessions.TryGetValue (id, out service)) if (_sessions.TryGetValue (id, out session))
{ {
var state = service.State; var state = session.State;
if (state == WebSocketState.OPEN) if (state == WebSocketState.OPEN)
service.Context.WebSocket.Close (CloseStatusCode.ABNORMAL); session.Context.WebSocket.Close (CloseStatusCode.ABNORMAL);
else if (state == WebSocketState.CLOSING) else if (state == WebSocketState.CLOSING)
continue; continue;
else else
@ -718,18 +705,30 @@ namespace WebSocketSharp.Server
/// otherwise, <c>false</c>. /// otherwise, <c>false</c>.
/// </returns> /// </returns>
/// <param name="id"> /// <param name="id">
/// A <see cref="string"/> that contains a session ID to find. /// A <see cref="string"/> that contains the ID of the session information to get.
/// </param> /// </param>
/// <param name="session"> /// <param name="session">
/// When this method returns, a <see cref="IWebSocketSession"/> instance that contains the session /// When this method returns, a <see cref="IWebSocketSession"/> instance that contains the session
/// information if it is successfully found; otherwise, <see langword="null"/>. /// information if it is successfully found; otherwise, <see langword="null"/>.
/// This parameter is passed uninitialized.
/// </param> /// </param>
public bool TryGetSession (string id, out IWebSocketSession session) public bool TryGetSession (string id, out IWebSocketSession session)
{ {
var msg = id.CheckIfValidSessionID ();
if (msg != null)
{
_logger.Error (msg);
session = null;
return false;
}
WebSocketService service; WebSocketService service;
var result = TryGetServiceInstance (id, out service); var result = TryGetServiceInstance (id, out service);
session = service; if (!result)
_logger.Error ("The WebSocket session with the specified ID not found.\nID: " + id);
session = service;
return result; return result;
} }