summaryrefslogtreecommitdiff
path: root/server/src/tcpsocket.cc
diff options
context:
space:
mode:
authorbertho <bertho>2009-02-05 01:26:26 +0000
committerbertho <bertho>2009-02-05 01:26:26 +0000
commit551d4aa1be9f4d256df3fadca9a005a0f316adf8 (patch)
treeb3cae7ee51d5dc64d0d07ae7deffdd67d4f3f371 /server/src/tcpsocket.cc
parent3ad20fdd0c8d5c20f0c02e3d1ad2e1e6b0f2a078 (diff)
Add a flexible debug interface. Please read the documentation.
Diffstat (limited to 'server/src/tcpsocket.cc')
-rw-r--r--server/src/tcpsocket.cc25
1 files changed, 10 insertions, 15 deletions
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 <config.h>
+
#include "tcpsocket.h"
#include "debug.h"
-#include <config.h>
//#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;
}
}