mirror of
https://oauth2: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@github.com/m1ngsama/TNT.git
synced 2026-05-10 19:00:57 +08:00
Merge pull request #20 from m1ngsama/fix/edge-cases-and-robustness
Fix edge cases in message loading and network I/O
This commit is contained in:
commit
83e964028a
2 changed files with 8 additions and 4 deletions
|
|
@ -61,7 +61,7 @@ int message_load(message_t **messages, int max_messages) {
|
|||
}
|
||||
|
||||
long file_size = ftell(fp);
|
||||
if (file_size == 0) {
|
||||
if (file_size <= 0) {
|
||||
fclose(fp);
|
||||
*messages = msg_array;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -195,8 +195,10 @@ static ip_rate_limit_t* get_rate_limit_entry(const char *ip) {
|
|||
oldest_idx = i;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "Warning: rate-limit table full, evicting active IP %s\n",
|
||||
g_rate_limits[oldest_idx].ip);
|
||||
fprintf(stderr, "Warning: rate-limit table full, evicting active IP %s "
|
||||
"(%d active connections lost)\n",
|
||||
g_rate_limits[oldest_idx].ip,
|
||||
g_rate_limits[oldest_idx].active_connections);
|
||||
}
|
||||
|
||||
/* Reset and reuse */
|
||||
|
|
@ -488,7 +490,9 @@ int client_send(client_t *client, const char *data, size_t len) {
|
|||
}
|
||||
|
||||
while (total < len) {
|
||||
int sent = ssh_channel_write(client->channel, data + total, len - total);
|
||||
size_t remaining = len - total;
|
||||
uint32_t chunk = (remaining > 32768) ? 32768 : (uint32_t)remaining;
|
||||
int sent = ssh_channel_write(client->channel, data + total, chunk);
|
||||
if (sent <= 0) {
|
||||
pthread_mutex_unlock(&client->io_lock);
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Reference in a new issue