File Conn.c changed (mode: 100644) (index 615b446..60b95db) |
... |
... |
static void Conn_free_intern(struct Conn *C) |
256 |
256 |
|
|
257 |
257 |
Conn_pending++; |
Conn_pending++; |
258 |
258 |
} else { |
} else { |
259 |
|
C->type = Conn_type_UNK; |
|
|
259 |
|
C->type = CONN_TYPE_UNK; |
260 |
260 |
C->state = CONN_STATE_FREE; |
C->state = CONN_STATE_FREE; |
261 |
261 |
|
|
262 |
262 |
/* Allow connections */ |
/* Allow connections */ |
|
... |
... |
struct Conn *Conn_alloc(void) |
333 |
333 |
C = &Conns[Conn_no]; |
C = &Conns[Conn_no]; |
334 |
334 |
C->slot = Conn_no; |
C->slot = Conn_no; |
335 |
335 |
|
|
336 |
|
C->type = Conn_type_UNK; |
|
|
336 |
|
C->type = CONN_TYPE_UNK; |
337 |
337 |
C->state = CONN_STATE_EMPTY; |
C->state = CONN_STATE_EMPTY; |
338 |
338 |
|
|
339 |
339 |
if (C->ibuf_size < Conn_default_ibuf) { |
if (C->ibuf_size < Conn_default_ibuf) { |
|
... |
... |
int Conn_commit(struct Conn *C) |
462 |
462 |
int first_state; |
int first_state; |
463 |
463 |
|
|
464 |
464 |
/* Try to figure what kind of socket is: client or master */ |
/* Try to figure what kind of socket is: client or master */ |
465 |
|
if (C->type == Conn_type_UNK) { |
|
|
465 |
|
if (C->type == CONN_TYPE_UNK) { |
466 |
466 |
if (strlen(C->addr) > 0) { |
if (strlen(C->addr) > 0) { |
467 |
|
C->type = Conn_type_CLIENT; |
|
|
467 |
|
C->type = CONN_TYPE_P2P; |
468 |
468 |
do_listen = 0; |
do_listen = 0; |
469 |
469 |
do_connect = 1; |
do_connect = 1; |
470 |
470 |
} else { |
} else { |
471 |
|
C->type = Conn_type_MASTER; |
|
|
471 |
|
C->type = CONN_TYPE_MASTER; |
472 |
472 |
if (strlen(C->bind_addr) == 0) { |
if (strlen(C->bind_addr) == 0) { |
473 |
473 |
switch (C->sock_domain) { |
switch (C->sock_domain) { |
474 |
474 |
case PF_INET: |
case PF_INET: |
|
... |
... |
struct Conn *Conn_connect(const int domain, const int type, const char *addr, |
697 |
697 |
if (!X) |
if (!X) |
698 |
698 |
return NULL; |
return NULL; |
699 |
699 |
|
|
700 |
|
X->type = Conn_type_CLIENT; |
|
|
700 |
|
X->type = CONN_TYPE_P2P; |
701 |
701 |
X->state = CONN_STATE_CONNECT_a; |
X->state = CONN_STATE_CONNECT_a; |
702 |
702 |
|
|
703 |
703 |
Conn_set_socket_domain(X, domain); |
Conn_set_socket_domain(X, domain); |
|
... |
... |
static void Conn_accept(struct Conn *C) |
777 |
777 |
break; |
break; |
778 |
778 |
} |
} |
779 |
779 |
|
|
780 |
|
X->type = Conn_type_CLIENT; |
|
|
780 |
|
X->type = CONN_TYPE_P2P; |
781 |
781 |
X->state = CONN_STATE_OPEN; |
X->state = CONN_STATE_OPEN; |
782 |
782 |
X->via = C->id; |
X->via = C->id; |
783 |
783 |
X->fd = fd; |
X->fd = fd; |
|
... |
... |
static void Conn_accept_allow(void) |
816 |
816 |
Conn_accept_is_allowed); |
Conn_accept_is_allowed); |
817 |
817 |
|
|
818 |
818 |
for (i = 0; i < Conn_no; i++) { |
for (i = 0; i < Conn_no; i++) { |
819 |
|
if (Conns[i].type != Conn_type_MASTER) |
|
|
819 |
|
if (Conns[i].type != CONN_TYPE_MASTER) |
820 |
820 |
continue; |
continue; |
821 |
821 |
|
|
822 |
822 |
if (Conn_accept_is_allowed == 0) |
if (Conn_accept_is_allowed == 0) |
|
... |
... |
static void Conn_trytoconnect(void) |
898 |
898 |
__FUNCTION__, Conn_pending); |
__FUNCTION__, Conn_pending); |
899 |
899 |
|
|
900 |
900 |
for (i = Conn_no - 1; i >= 0; i--) { |
for (i = Conn_no - 1; i >= 0; i--) { |
901 |
|
if (Conns[i].type != Conn_type_CLIENT) |
|
|
901 |
|
if (Conns[i].type != CONN_TYPE_P2P) |
902 |
902 |
continue; |
continue; |
903 |
903 |
|
|
904 |
904 |
if ((Conns[i].state == CONN_STATE_CONNECT_0) |
if ((Conns[i].state == CONN_STATE_CONNECT_0) |
|
... |
... |
static void Conn_poll_cb(struct Conn *C, int revents) |
1185 |
1185 |
/* Second, test for error or input */ |
/* Second, test for error or input */ |
1186 |
1186 |
if ((revents & CONN_POLLIN) |
if ((revents & CONN_POLLIN) |
1187 |
1187 |
&& (Conn_ignore(C) == 0)) { |
&& (Conn_ignore(C) == 0)) { |
1188 |
|
if (C->type == Conn_type_MASTER) { |
|
|
1188 |
|
if (C->type == CONN_TYPE_MASTER) { |
1189 |
1189 |
/* C pointer can change under us in Conn_accept->Conn_grow */ |
/* C pointer can change under us in Conn_accept->Conn_grow */ |
1190 |
1190 |
slot = C->slot; |
slot = C->slot; |
1191 |
1191 |
Conn_accept(C); |
Conn_accept(C); |
File Conn_engine_core.c changed (mode: 100644) (index 2ab17ce..c6b82f9) |
... |
... |
char *Conn_protocol(const struct Conn *C) |
375 |
375 |
static char *Conn_socktype(const struct Conn *C) |
static char *Conn_socktype(const struct Conn *C) |
376 |
376 |
{ |
{ |
377 |
377 |
switch (C->type) { |
switch (C->type) { |
378 |
|
case Conn_type_MASTER: return "master"; |
|
379 |
|
case Conn_type_CLIENT: return "client"; |
|
380 |
|
case Conn_type_UNK: return "unk"; |
|
|
378 |
|
case CONN_TYPE_UNK: return "unk"; |
|
379 |
|
case CONN_TYPE_MASTER: return "master"; |
|
380 |
|
case CONN_TYPE_P2P: return "p2p"; |
381 |
381 |
default: return "?"; |
default: return "?"; |
382 |
382 |
} |
} |
383 |
383 |
} |
} |
|
... |
... |
char *Conn_status(const unsigned int flags) |
568 |
568 |
if (C->state == CONN_STATE_FREE) |
if (C->state == CONN_STATE_FREE) |
569 |
569 |
continue; |
continue; |
570 |
570 |
|
|
571 |
|
if (C->type == Conn_type_CLIENT) { |
|
|
571 |
|
if (C->type == CONN_TYPE_P2P) { |
572 |
572 |
bi += C->bi; |
bi += C->bi; |
573 |
573 |
bo += C->bo; |
bo += C->bo; |
574 |
574 |
dT += Conn_now.tv_sec - C->start; |
dT += Conn_now.tv_sec - C->start; |