From 551d4aa1be9f4d256df3fadca9a005a0f316adf8 Mon Sep 17 00:00:00 2001 From: bertho Date: Thu, 5 Feb 2009 01:26:26 +0000 Subject: Add a flexible debug interface. Please read the documentation. --- server/src/tcpsocket.cc | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'server/src/tcpsocket.cc') diff --git a/server/src/tcpsocket.cc b/server/src/tcpsocket.cc index 9d481ff..f72d7b6 100644 --- a/server/src/tcpsocket.cc +++ b/server/src/tcpsocket.cc @@ -24,10 +24,11 @@ * along with Artefact; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#include + #include "tcpsocket.h" #include "debug.h" -#include //#define WITH_DEBUG @@ -89,16 +90,12 @@ TCPSocket::TCPSocket(std::string name, int sock) isconnected = false; this->sock = sock; -#ifdef WITH_DEBUG - printf("TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid()); -#endif/*WITH_DEBUG*/ + PRACRO_DEBUG(socket, "TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid()); } TCPSocket::~TCPSocket() { -#ifdef WITH_DEBUG - printf("~TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid()); -#endif/*WITH_DEBUG*/ + PRACRO_DEBUG(socket, "~TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid()); disconnect(); } @@ -155,7 +152,7 @@ TCPSocket *TCPSocket::accept() FD_SET(sock, &fset); if( (ret = select (sock+1, &fset, NULL, NULL, NULL)) < 0) { if(errno == EINTR) { - printf("Accept got interrupt!\n"); + PRACRO_DEBUG(socket, "Accept got interrupt!\n"); return NULL; // a signal caused select to return. That is OK with me } else { throw TCPAcceptException("Select on socket failed."); @@ -171,7 +168,7 @@ TCPSocket *TCPSocket::accept() child->isconnected = true; return child; } else { - printf("Accept returned with no socket - This should not happen!\n"); + PRACRO_ERR_LOG(socket, "Accept returned with no socket - This should not happen!\n"); return NULL; } } @@ -222,9 +219,7 @@ void TCPSocket::connect(std::string addr, unsigned short int port) void TCPSocket::disconnect() { if(sock != -1) { -#ifdef WITH_DEBUG - printf("Closing TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid()); -#endif/*WITH_DEBUG*/ + PRACRO_DEBUG(socket, "Closing TCPSocket %s: %p %d (%d)\n", name.c_str(), this, sock, getpid()); int ret = close(sock); if(ret == -1) { perror(name.c_str()); @@ -274,7 +269,7 @@ int TCPSocket::read(char *buf, int size, long timeout) switch(ret) { case -1: if(errno == EINTR) { - printf("EINTR - got interrupt\n"); + PRACRO_DEBUG(socket, "EINTR - got interrupt\n"); return -1; // a signal caused select to return. That is OK with me } else { throw TCPReadException("Select on socket (read) failed."); @@ -283,7 +278,7 @@ int TCPSocket::read(char *buf, int size, long timeout) case 0: // timeout - printf("Timeout\n"); + PRACRO_DEBUG(socket, "Timeout\n"); break; default: @@ -293,7 +288,7 @@ int TCPSocket::read(char *buf, int size, long timeout) throw TCPReadException(strerror(errno)); } } else { - printf("FD_ISSET failed (timeout?)\n"); + PRACRO_DEBUG(socket, "FD_ISSET failed (timeout?)\n"); return 0; } } -- cgit v1.2.3