[Modify] Add a limitation for the reconnect
This commit is contained in:
parent
d05395e155
commit
1938011fea
@ -93,6 +93,7 @@ namespace WebSocketSharp
|
|||||||
private bool _inContinuation;
|
private bool _inContinuation;
|
||||||
private volatile bool _inMessage;
|
private volatile bool _inMessage;
|
||||||
private volatile Logger _logger;
|
private volatile Logger _logger;
|
||||||
|
private static readonly int _maxRetryCountForConnect;
|
||||||
private Action<MessageEventArgs> _message;
|
private Action<MessageEventArgs> _message;
|
||||||
private Queue<MessageEventArgs> _messageEventQueue;
|
private Queue<MessageEventArgs> _messageEventQueue;
|
||||||
private uint _nonceCount;
|
private uint _nonceCount;
|
||||||
@ -105,6 +106,7 @@ namespace WebSocketSharp
|
|||||||
private Uri _proxyUri;
|
private Uri _proxyUri;
|
||||||
private volatile WebSocketState _readyState;
|
private volatile WebSocketState _readyState;
|
||||||
private AutoResetEvent _receivePong;
|
private AutoResetEvent _receivePong;
|
||||||
|
private int _retryCountForConnect;
|
||||||
private bool _secure;
|
private bool _secure;
|
||||||
private ClientSslConfiguration _sslConfig;
|
private ClientSslConfiguration _sslConfig;
|
||||||
private Stream _stream;
|
private Stream _stream;
|
||||||
@ -147,6 +149,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
static WebSocket ()
|
static WebSocket ()
|
||||||
{
|
{
|
||||||
|
_maxRetryCountForConnect = 10;
|
||||||
EmptyBytes = new byte[0];
|
EmptyBytes = new byte[0];
|
||||||
FragmentLength = 1016;
|
FragmentLength = 1016;
|
||||||
RandomNumber = new RNGCryptoServiceProvider ();
|
RandomNumber = new RNGCryptoServiceProvider ();
|
||||||
@ -1040,14 +1043,23 @@ namespace WebSocketSharp
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_retryCountForConnect > _maxRetryCountForConnect) {
|
||||||
|
_retryCountForConnect = 0;
|
||||||
|
_logger.Fatal ("A series of reconnecting has failed.");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_readyState = WebSocketState.Connecting;
|
_readyState = WebSocketState.Connecting;
|
||||||
if (!doHandshake ())
|
if (!doHandshake ())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
_retryCountForConnect = 1;
|
||||||
_readyState = WebSocketState.Open;
|
_readyState = WebSocketState.Open;
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
_retryCountForConnect++;
|
||||||
_logger.Fatal (ex.ToString ());
|
_logger.Fatal (ex.ToString ());
|
||||||
fatal ("An exception has occurred while connecting.", ex);
|
fatal ("An exception has occurred while connecting.", ex);
|
||||||
|
|
||||||
@ -1169,6 +1181,7 @@ namespace WebSocketSharp
|
|||||||
|
|
||||||
string msg;
|
string msg;
|
||||||
if (!checkHandshakeResponse (res, out msg)) {
|
if (!checkHandshakeResponse (res, out msg)) {
|
||||||
|
_retryCountForConnect++;
|
||||||
_logger.Fatal (msg);
|
_logger.Fatal (msg);
|
||||||
fatal ("An error has occurred while connecting.", CloseStatusCode.ProtocolError);
|
fatal ("An error has occurred while connecting.", CloseStatusCode.ProtocolError);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user