Commit da893bf61f1f4a379a4acf155232afdd1bae4df5
1 parent
f4c630f6
fix retrieval of remote socket information
Showing
2 changed files
with
8 additions
and
7 deletions
@@ -43,7 +43,8 @@ TR_socketAccept(TR_TcpSocket this) | @@ -43,7 +43,8 @@ TR_socketAccept(TR_TcpSocket this) | ||
43 | TR_Socket remote = TR_new(TR_TcpSocket, TR_socketLog(this), NULL, 0, 0); | 43 | TR_Socket remote = TR_new(TR_TcpSocket, TR_socketLog(this), NULL, 0, 0); |
44 | //int flags; | 44 | //int flags; |
45 | 45 | ||
46 | - remote->handle = accept( | 46 | + remote->addrlen = ((TR_Socket)this)->addrlen; |
47 | + remote->handle = accept( | ||
47 | TR_socketHandle(this), | 48 | TR_socketHandle(this), |
48 | (struct sockaddr *)&(remote->addr), | 49 | (struct sockaddr *)&(remote->addr), |
49 | &(remote->addrlen)); | 50 | &(remote->addrlen)); |
@@ -51,14 +52,14 @@ TR_socketAccept(TR_TcpSocket this) | @@ -51,14 +52,14 @@ TR_socketAccept(TR_TcpSocket this) | ||
51 | //flags = fcntl(remote->handle, F_GETFL, 0); | 52 | //flags = fcntl(remote->handle, F_GETFL, 0); |
52 | //fcntl(remote->handle, F_SETFL, flags | O_NONBLOCK); | 53 | //fcntl(remote->handle, F_SETFL, flags | O_NONBLOCK); |
53 | 54 | ||
54 | - remote->host = TR_strdup(inet_ntoa(remote->addr.sin_addr)); | ||
55 | - remote->port = ntohs(remote->addr.sin_port); | ||
56 | - remote->type = TR_socketType(this); | ||
57 | - remote->flags = TR_socketFlags(this); | ||
58 | - | ||
59 | if (-1 == remote->handle) { | 55 | if (-1 == remote->handle) { |
60 | perror("accept"); | 56 | perror("accept"); |
61 | TR_delete(remote); | 57 | TR_delete(remote); |
58 | + } else { | ||
59 | + remote->host = TR_strdup(inet_ntoa(remote->addr.sin_addr)); | ||
60 | + remote->port = ntohs(remote->addr.sin_port); | ||
61 | + remote->type = TR_socketType(this); | ||
62 | + remote->flags = TR_socketFlags(this); | ||
62 | } | 63 | } |
63 | 64 | ||
64 | return (TR_TcpSocket)remote; | 65 | return (TR_TcpSocket)remote; |
@@ -61,7 +61,7 @@ tcpSocketBind(void * _this) | @@ -61,7 +61,7 @@ tcpSocketBind(void * _this) | ||
61 | return -1; | 61 | return -1; |
62 | } | 62 | } |
63 | 63 | ||
64 | - if (listen(TR_socketHandle(this), 128) != 0) { | 64 | + if (listen(TR_socketHandle(this), SOMAXCONN) != 0) { |
65 | // error | 65 | // error |
66 | return -1; | 66 | return -1; |
67 | } | 67 | } |
Please
register
or
login
to post a comment