Skip to content
Snippets Groups Projects
Commit fc8f514c authored by slevy's avatar slevy
Browse files

Mollify g++ 4.0.

parent 242a6f44
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,17 @@
#include <ext/stdio_filebuf.h>
using namespace std;
static const char *serr() {
return strerror(errno);
}
bool TCPsocket::mksock( const char *name, bool nb ) {
fd_ = socket( PF_INET, SOCK_STREAM, IPPROTO_TCP );
if(fd_ < 0) {
fprintf(stderr, "TCPsocket(\"%s\"): %s\n", name, strerror(errno));
fprintf(stderr, "TCPsocket(\"%s\"): %s\n", name, serr());
return false;
}
nonblock( nb );
......@@ -62,7 +68,7 @@ void TCPsocket::connectwith( const char *name, int port, bool nonblock )
}
if(port <= 0 || port >= 65536) {
fprintf(stderr, "TCPsocket(): port %d out of range\n", port);
::fprintf(stderr, "TCPsocket(): port %d out of range\n", port);
return;
}
......@@ -75,7 +81,8 @@ void TCPsocket::connectwith( const char *name, int port, bool nonblock )
} else {
struct hostent *hp = gethostbyname( name );
if(hp == NULL) {
fprintf(stderr, "TCPsocket(\"%s\") -- %s\n", name, hstrerror(h_errno));
const char *s = hstrerror(h_errno);
fprintf(stderr, "TCPsocket(\"%s\") -- %s\n", name, s);
return;
}
memcpy(&sin_.sin_addr, &hp->h_addr, sizeof(struct in_addr));
......@@ -91,7 +98,7 @@ void TCPsocket::connectwith( const char *name, int port, bool nonblock )
} else {
fprintf(stderr, "TCPsocket(\"%s\"[%s], %d): %s\n",
name, inet_ntoa(sin_.sin_addr),
port, strerror(errno));
port, serr());
state_ = INVALID;
}
}
......@@ -129,18 +136,18 @@ void TCPsocket::listenwith( int listenport, bool await_first_contact, int backlo
static int one = 1;
if(setsockopt( fd_, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one) ) < 0) {
fprintf(stderr, "TCPsocket(%d): setsockopt: %s\n", listenport, strerror(errno));
fprintf(stderr, "TCPsocket(%d): setsockopt: %s\n", listenport, serr());
/* non-fatal */
}
if(bind(fd_, (struct sockaddr *)&sin_, sizeof(sin_)) < 0) {
fprintf(stderr, "TCPsocket(%d): bind: %s\n", listenport, strerror(errno));
fprintf(stderr, "TCPsocket(%d): bind: %s\n", listenport, serr());
return;
}
backlog_ = backlog && !await_first_contact;
if(listen(fd_, backlog_) < 0) {
fprintf(stderr, "TCPsocket(%d): listen: %s\n", listenport, strerror(errno));
fprintf(stderr, "TCPsocket(%d): listen: %s\n", listenport, serr());
return;
}
state_ = LISTENING;
......@@ -161,7 +168,7 @@ bool TCPsocket::do_accept() {
} while(newfd < 0 && errno == EINTR);
if(newfd < 0) {
fprintf(stderr, "TCPsocket(%d, true): accept: %s\n", ntohs(sin_.sin_port), strerror(errno));
fprintf(stderr, "TCPsocket(%d, true): accept: %s\n", ntohs(sin_.sin_port), serr());
state_ = INVALID;
return false;
}
......@@ -233,7 +240,7 @@ TCPsocket::TCPsocket( TCPsocket & listener, bool nonblock )
if(fd_ < 0) {
fprintf(stderr, "TCPsocket(listening(%d)): accept: %s\n",
ntohs(listener.sin_.sin_port), strerror(errno));
ntohs(listener.sin_.sin_port), serr());
return;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment