Skip to content

Commit

Permalink
Fixed some error logging, add from-address to state struct so
Browse files Browse the repository at this point in the history
correct addresses go to log on heavy load.
  • Loading branch information
stealth committed Dec 20, 2011
1 parent 23d8545 commit 0f32fa9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ int tcp_connect_nb(const struct sockaddr_in &to, const struct sockaddr_in &from,

int f;
if ((f = fcntl(sock, F_GETFL, 0)) < 0) {
close(sock);
error = "NS_Socket::tcp_connect_nb::fcntl:";
error += strerror(errno);
close(sock);
return -1;
}
if (fcntl(sock, F_SETFL, f|O_NONBLOCK) < 0) {
close(sock);
error = "NS_Socket::tcp_connect_nb::fcntl:";
error += strerror(errno);
close(sock);
return -1;
}

Expand All @@ -173,9 +173,9 @@ int tcp_connect_nb(const struct sockaddr_in &to, const struct sockaddr_in &from,
#else
if (transparent && setsockopt(sock, IPPROTO_IP, IP_BINDANY, &one, sizeof(one)) < 0) {
#endif
close(sock);
error = "NS_Socket::tcp_connect_nb::setsockopt:";
error += strerror(errno);
close(sock);
return -1;
}
if (bind_local(sock, from, 0) < 0) {
Expand All @@ -187,7 +187,7 @@ int tcp_connect_nb(const struct sockaddr_in &to, const struct sockaddr_in &from,
if (connect(sock, (struct sockaddr *)&to, sizeof(to)) < 0 &&
errno != EINPROGRESS) {
close(sock);
error = "NS_Socket::tcp_connect_nb::fcntl:";
error = "NS_Socket::tcp_connect_nb::connect:";
error += strerror(errno);
return -1;
}
Expand Down
5 changes: 3 additions & 2 deletions sshttp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ int sshttp::loop()
// We dont know yet which protocol is coming
fd2state[afd]->peer_fd = -1;
fd2state[afd]->state = STATE_DECIDING;
fd2state[afd]->from = sin;

if (afd > max_fd)
max_fd = afd;
Expand All @@ -242,12 +243,12 @@ int sshttp::loop()

// error?
if (dst.sin_port == 0) {
err = "sshttp::loop: dest port is 0?!";
err = "sshttp::loop: dst port is 0?!";
cleanup(i);
continue;
}

peer_fd = tcp_connect_nb(dst, sin, 1);
peer_fd = tcp_connect_nb(dst, fd2state[i]->from, 1);
if (peer_fd < 0) {
err = "sshttp::loop::";
err += NS_Socket::why();
Expand Down
2 changes: 1 addition & 1 deletion sshttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct status {
time_t last_t;
char buf[1024];
uint16_t blen;

struct sockaddr_in from;
status() { memset(buf, 0, sizeof(buf)); blen = 0; };
};

Expand Down

0 comments on commit 0f32fa9

Please sign in to comment.