File Conn.c changed (mode: 100644) (index cc5689d..38cc411) |
... |
... |
static void Conn_accept(struct Conn *C) |
771 |
771 |
return; |
return; |
772 |
772 |
} |
} |
773 |
773 |
|
|
774 |
|
err = getsockname(fd, psa, &sax_len); |
|
775 |
|
|
|
776 |
|
switch (C->sock_domain) { |
|
777 |
|
case PF_INET: |
|
778 |
|
/* remote */ |
|
779 |
|
inet_ntop(C->sock_domain, &ca4.sin_addr, X->addr, sizeof(X->addr)); |
|
780 |
|
X->port = ntohs(ca4.sin_port); |
|
781 |
|
/* local */ |
|
782 |
|
if (err == 0) { |
|
783 |
|
inet_ntop(C->sock_domain, &sa4.sin_addr, X->bind_addr, sizeof(X->bind_addr)); |
|
784 |
|
X->bind_port = ntohs(sa4.sin_port); |
|
785 |
|
} |
|
786 |
|
break; |
|
787 |
|
|
|
788 |
|
case PF_INET6: |
|
789 |
|
/* remote */ |
|
790 |
|
inet_ntop(C->sock_domain, &ca6.sin6_addr, X->addr, sizeof(X->addr)); |
|
791 |
|
X->port = ntohs(ca6.sin6_port); |
|
792 |
|
/* local */ |
|
793 |
|
if (err == 0) { |
|
794 |
|
inet_ntop(C->sock_domain, &sa6.sin6_addr, X->bind_addr, sizeof(X->addr)); |
|
795 |
|
X->bind_port = ntohs(sa6.sin6_port); |
|
796 |
|
} |
|
797 |
|
break; |
|
798 |
|
} |
|
799 |
|
|
|
|
774 |
|
X->fd = fd; |
800 |
775 |
X->type = CONN_TYPE_P2P; |
X->type = CONN_TYPE_P2P; |
801 |
776 |
X->state = CONN_STATE_OPEN; |
X->state = CONN_STATE_OPEN; |
802 |
777 |
X->via = C->id; |
X->via = C->id; |
803 |
|
X->fd = fd; |
|
804 |
778 |
X->events = CONN_POLLIN; |
X->events = CONN_POLLIN; |
805 |
779 |
|
|
806 |
780 |
Conn_set_socket_domain(X, C->sock_domain); |
Conn_set_socket_domain(X, C->sock_domain); |
|
... |
... |
static void Conn_accept(struct Conn *C) |
809 |
783 |
|
|
810 |
784 |
Conn_setnonblock(X->fd); |
Conn_setnonblock(X->fd); |
811 |
785 |
|
|
|
786 |
|
Conn_set_address(X, 0); |
|
787 |
|
Conn_set_address(X, 1); |
|
788 |
|
|
812 |
789 |
err = Conn_engine_add_obj(X); |
err = Conn_engine_add_obj(X); |
813 |
790 |
if (err != 0) { |
if (err != 0) { |
814 |
791 |
Conn_error_raise(C, err); |
Conn_error_raise(C, err); |
|
... |
... |
static void Conn_poll_cb(struct Conn *C, int revents) |
1194 |
1171 |
|
|
1195 |
1172 |
C->state = CONN_STATE_OPEN; |
C->state = CONN_STATE_OPEN; |
1196 |
1173 |
|
|
|
1174 |
|
Conn_set_address(C, 0); |
|
1175 |
|
|
1197 |
1176 |
if (C->cb_connected != NULL) |
if (C->cb_connected != NULL) |
1198 |
1177 |
C->cb_connected(C); |
C->cb_connected(C); |
1199 |
1178 |
else if (Conn_connected_cb) |
else if (Conn_connected_cb) |
File Conn_engine_core.c changed (mode: 100644) (index f7e4747..3b1eab4) |
... |
... |
void Conn_queue_destroy(struct Conn_queue *q) |
1030 |
1030 |
} |
} |
1031 |
1031 |
|
|
1032 |
1032 |
/* Misc */ |
/* Misc */ |
|
1033 |
|
/* |
|
1034 |
|
* Returns the string representation of an socket address |
|
1035 |
|
* @flags: bit0==0 => local address, bit0==1 => peer address |
|
1036 |
|
*/ |
|
1037 |
|
int Conn_set_address(struct Conn *C, const int flags) |
|
1038 |
|
{ |
|
1039 |
|
int err; |
|
1040 |
|
struct sockaddr *psa; |
|
1041 |
|
struct sockaddr_in sa4; |
|
1042 |
|
struct sockaddr_in6 sa6; |
|
1043 |
|
socklen_t sa_len; |
|
1044 |
|
char *paddr; |
|
1045 |
|
size_t addr_size; |
|
1046 |
|
int *pport; |
|
1047 |
|
|
|
1048 |
|
switch (C->sock_domain) { |
|
1049 |
|
case PF_INET: |
|
1050 |
|
psa = (struct sockaddr *) &sa4; |
|
1051 |
|
sa_len = sizeof(struct sockaddr_in); |
|
1052 |
|
break; |
|
1053 |
|
case PF_INET6: |
|
1054 |
|
psa = (struct sockaddr *) &sa6; |
|
1055 |
|
sa_len = sizeof(struct sockaddr_in6); |
|
1056 |
|
break; |
|
1057 |
|
default: |
|
1058 |
|
return -1; |
|
1059 |
|
} |
|
1060 |
|
|
|
1061 |
|
if (flags & 1) { |
|
1062 |
|
/* peer */ |
|
1063 |
|
paddr = C->addr; |
|
1064 |
|
addr_size = sizeof(C->addr); |
|
1065 |
|
pport = &C->port; |
|
1066 |
|
err = getpeername(C->fd, psa, &sa_len); |
|
1067 |
|
} else { |
|
1068 |
|
/* local */ |
|
1069 |
|
paddr = C->bind_addr; |
|
1070 |
|
addr_size = sizeof(C->bind_addr); |
|
1071 |
|
pport = &C->bind_port; |
|
1072 |
|
err = getsockname(C->fd, psa, &sa_len); |
|
1073 |
|
} |
|
1074 |
|
|
|
1075 |
|
if (err != 0) |
|
1076 |
|
return -1; |
|
1077 |
|
|
|
1078 |
|
switch (C->sock_domain) { |
|
1079 |
|
case PF_INET: |
|
1080 |
|
inet_ntop(C->sock_domain, &sa4.sin_addr, |
|
1081 |
|
paddr, addr_size); |
|
1082 |
|
*pport = ntohs(sa4.sin_port); |
|
1083 |
|
break; |
|
1084 |
|
case PF_INET6: |
|
1085 |
|
inet_ntop(C->sock_domain, &sa6.sin6_addr, |
|
1086 |
|
paddr, addr_size); |
|
1087 |
|
*pport = ntohs(sa6.sin6_port); |
|
1088 |
|
break; |
|
1089 |
|
default: |
|
1090 |
|
return -1; |
|
1091 |
|
} |
|
1092 |
|
|
|
1093 |
|
return 0; |
|
1094 |
|
} |
|
1095 |
|
|
1033 |
1096 |
/* |
/* |
1034 |
1097 |
* Returns the address family for address stored in @addr. |
* Returns the address family for address stored in @addr. |
1035 |
1098 |
*/ |
*/ |
File Conn_engine_core.h changed (mode: 100644) (index 63d17ac..d5ee6e5) |
... |
... |
extern void Conn_error_raise(struct Conn *C, const int err); |
316 |
316 |
|
|
317 |
317 |
extern void Conn_stop(void); |
extern void Conn_stop(void); |
318 |
318 |
|
|
|
319 |
|
extern int Conn_set_address(struct Conn *C, const int flags); |
|
320 |
|
|
319 |
321 |
/* queue stuff */ |
/* queue stuff */ |
320 |
322 |
extern void Conn_queue_init(struct Conn_queue *q); |
extern void Conn_queue_init(struct Conn_queue *q); |
321 |
323 |
extern int Conn_queue_add(struct Conn_queue *q, |
extern int Conn_queue_add(struct Conn_queue *q, |