| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2016-06-01 08:38:50 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2016-06-01 08:38:50 +0200 |
| commit | d29327bdc629dfa37360465b03ef45d205e7a225 (patch) | |
| tree | 8f277e916a52978f97bdb32db7a76c6823f0bce0 | |
| parent | ecdebd8f416b803b43ce93533666599e1442f62d (diff) | |
Fixes ping timeouts causing infine loop.
| -rw-r--r-- | src/io/network.c | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/io/network.c b/src/io/network.c index d2797c9..45be5fb 100644 --- a/src/io/network.c +++ b/src/io/network.c @@ -107,6 +107,9 @@ static int reconnect (struct ZoO_network net [const restrict static 1]) memset(net->out, 0, (sizeof(ZoO_char) * 513)); memset(net->buffer, 0, (sizeof(ZoO_char) * 513)); + net->buffer_index = 0; + net->buffer_remaining = 0; + if (re_create_socket(net) < 0) { return -1; @@ -231,11 +234,19 @@ static void buffer_msg READ_MORE: in_count = read(net->connection, net->buffer, 512); - if (in_count < 0) + if (in_count <= 0) { ZoO_ERROR("Could not read from network: %s", strerror(errno)); - reconnect(net); + while (reconnect(net) < 0) + { + ZoO_S_DEBUG + ( + ZoO_DEBUG_NETWORK, + "Attempting new connection in 5s." + ); + sleep(5); + } goto READ_MORE; } @@ -289,6 +300,16 @@ void handle_ping (struct ZoO_network net [const restrict static 1]) { const int old_errno = errno; + #if ZoO_RANDOMLY_IGNORE_PING == 1 + if ((rand() % 10) < 3) + { + ZoO_S_DEBUG(ZoO_DEBUG_NETWORK, "Ping request ignored."); + + return; + } + + #endif + #if ZoO_DEBUG_NETWORK_PING == 1 net->in[net->in_length] = '\0'; @@ -309,6 +330,11 @@ void handle_ping (struct ZoO_network net [const restrict static 1]) while (reconnect(net) < 0) { + ZoO_S_DEBUG + ( + ZoO_DEBUG_NETWORK, + "Attempting new connection in 5s." + ); sleep(5); } @@ -439,6 +465,19 @@ READ_NEW_MSG: } } + if (ZoO_IS_PREFIX("ERROR", (net->in + cmd))) + { + while (reconnect(net) < 0) + { + ZoO_S_DEBUG + ( + ZoO_DEBUG_NETWORK, + "Attempting new connection in 5s." + ); + sleep(5); + } + } + goto READ_NEW_MSG; } |


