Some fixes in network
This commit is contained in:
parent
433ce1459a
commit
a064540223
19
net.c
19
net.c
@ -44,15 +44,20 @@ extern struct connection_methods auth_methods;
|
|||||||
|
|
||||||
void fail_connection (struct connection *c);
|
void fail_connection (struct connection *c);
|
||||||
|
|
||||||
|
#define PING_TIMEOUT 10
|
||||||
|
|
||||||
void start_ping_timer (struct connection *c);
|
void start_ping_timer (struct connection *c);
|
||||||
int ping_alarm (struct connection *c) {
|
int ping_alarm (struct connection *c) {
|
||||||
if (verbosity > 2) {
|
if (verbosity > 2) {
|
||||||
logprintf ("ping alarm\n");
|
logprintf ("ping alarm\n");
|
||||||
}
|
}
|
||||||
if (get_double_time () - c->last_receive_time > 20) {
|
if (get_double_time () - c->last_receive_time > 20 * PING_TIMEOUT) {
|
||||||
|
if (verbosity) {
|
||||||
|
logprintf ( "fail connection: reason: ping timeout\n");
|
||||||
|
}
|
||||||
c->state = conn_failed;
|
c->state = conn_failed;
|
||||||
fail_connection (c);
|
fail_connection (c);
|
||||||
} else if (get_double_time () - c->last_receive_time > 5 && c->state == conn_ready) {
|
} else if (get_double_time () - c->last_receive_time > 5 * PING_TIMEOUT && c->state == conn_ready) {
|
||||||
int x[3];
|
int x[3];
|
||||||
x[0] = CODE_ping;
|
x[0] = CODE_ping;
|
||||||
*(long long *)(x + 1) = lrand48 () * (1ll << 32) + lrand48 ();
|
*(long long *)(x + 1) = lrand48 () * (1ll << 32) + lrand48 ();
|
||||||
@ -69,7 +74,7 @@ void stop_ping_timer (struct connection *c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void start_ping_timer (struct connection *c) {
|
void start_ping_timer (struct connection *c) {
|
||||||
c->ev.timeout = get_double_time () + 1;
|
c->ev.timeout = get_double_time () + PING_TIMEOUT;
|
||||||
c->ev.alarm = (void *)ping_alarm;
|
c->ev.alarm = (void *)ping_alarm;
|
||||||
c->ev.self = c;
|
c->ev.self = c;
|
||||||
insert_event_timer (&c->ev);
|
insert_event_timer (&c->ev);
|
||||||
@ -358,6 +363,9 @@ void try_write (struct connection *c) {
|
|||||||
delete_connection_buffer (b);
|
delete_connection_buffer (b);
|
||||||
} else {
|
} else {
|
||||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||||
|
if (verbosity) {
|
||||||
|
logprintf ("fail_connection: write_error %m\n");
|
||||||
|
}
|
||||||
fail_connection (c);
|
fail_connection (c);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -459,6 +467,9 @@ void try_read (struct connection *c) {
|
|||||||
c->in_tail = b;
|
c->in_tail = b;
|
||||||
} else {
|
} else {
|
||||||
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
if (errno != EAGAIN && errno != EWOULDBLOCK) {
|
||||||
|
if (verbosity) {
|
||||||
|
logprintf ("fail_connection: read_error %m\n");
|
||||||
|
}
|
||||||
fail_connection (c);
|
fail_connection (c);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
@ -512,7 +523,7 @@ void connections_poll_result (struct pollfd *fds, int max) {
|
|||||||
}
|
}
|
||||||
if (fds[i].revents & (POLLHUP | POLLERR | POLLRDHUP)) {
|
if (fds[i].revents & (POLLHUP | POLLERR | POLLRDHUP)) {
|
||||||
if (verbosity) {
|
if (verbosity) {
|
||||||
logprintf ( "fail connection\n");
|
logprintf ("fail_connection: events_mask=0x%08x\n", fds[i].revents);
|
||||||
}
|
}
|
||||||
fail_connection (c);
|
fail_connection (c);
|
||||||
} else if (fds[i].revents & POLLOUT) {
|
} else if (fds[i].revents & POLLOUT) {
|
||||||
|
@ -56,7 +56,7 @@ long long cur_downloading_bytes;
|
|||||||
long long cur_downloaded_bytes;
|
long long cur_downloaded_bytes;
|
||||||
|
|
||||||
void out_peer_id (peer_id_t id);
|
void out_peer_id (peer_id_t id);
|
||||||
#define QUERY_TIMEOUT 0.3
|
#define QUERY_TIMEOUT 6.0
|
||||||
|
|
||||||
#define memcmp8(a,b) memcmp ((a), (b), 8)
|
#define memcmp8(a,b) memcmp ((a), (b), 8)
|
||||||
DEFINE_TREE (query, struct query *, memcmp8, 0) ;
|
DEFINE_TREE (query, struct query *, memcmp8, 0) ;
|
||||||
@ -80,6 +80,10 @@ int alarm_query (struct query *q) {
|
|||||||
q->ev.timeout = get_double_time () + QUERY_TIMEOUT;
|
q->ev.timeout = get_double_time () + QUERY_TIMEOUT;
|
||||||
insert_event_timer (&q->ev);
|
insert_event_timer (&q->ev);
|
||||||
|
|
||||||
|
if (q->session->c->out_bytes >= 100000) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
clear_packet ();
|
clear_packet ();
|
||||||
out_int (CODE_msg_container);
|
out_int (CODE_msg_container);
|
||||||
out_int (1);
|
out_int (1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user