some bug fixes

origin
steffen 7 years ago
parent 228ff862b2
commit 5f77b45d24

@ -1,3 +1,7 @@
2019-03-04:
- fixed: TCP connect set up the sock struct too fast so threaded applications had some
problem if the connect went into a time out.
2019-02-21: 2019-02-21:
- fixed: TCP::Accept needed to set up the lenght of the sockaddr structure - fixed: TCP::Accept needed to set up the lenght of the sockaddr structure

@ -167,8 +167,8 @@ int TCP::Connect() {
hints.ai_flags = 0; hints.ai_flags = 0;
hints.ai_protocol = 0; hints.ai_protocol = 0;
s = getaddrinfo(remote_host.c_str(), remote_port.c_str(), &hints, &res); err = getaddrinfo(remote_host.c_str(), remote_port.c_str(), &hints, &res);
if (s != 0) { if (err != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s)); fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
return 0; return 0;
} }
@ -177,11 +177,13 @@ int TCP::Connect() {
// walk through all results until we could connect // walk through all results until we could connect
// //
for (rp = res; rp != NULL; rp = rp->ai_next) { for (rp = res; rp != NULL; rp = rp->ai_next) {
sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol); s = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sock == -1) continue; if (s == -1) continue;
if (connect(sock, rp->ai_addr, rp->ai_addrlen) != -1) break; if (connect(s, rp->ai_addr, rp->ai_addrlen) != -1) {
close(sock); sock = s;
sock = -1; break;
}
close(s);
} }
freeaddrinfo(res); freeaddrinfo(res);

Loading…
Cancel
Save