From cc4604c1e22e01c31d25923ed76d1518693b7faa Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 2 Apr 2007 15:56:17 +0000 Subject: This constitutes a test version...there's a chance this should have been a branch, but it's so small...I'll just see if bugs arise, and if they do, then we'll fix 'em. --- src/connection.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/connection.cpp') diff --git a/src/connection.cpp b/src/connection.cpp index f042705..9d8b02c 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "exceptions.h" // Read buffer size...maybe fix wierd issues... @@ -137,10 +138,12 @@ bool Connection::isActive() void Connection::close() { + //printf("Close called, socket is: %s\n", bActive?"Active":"Inactive" ); if( bActive ) { fsync( nSocket ); ::close( nSocket ); + //printf("Socket closed.\n"); } bActive = false; //nSocket = -1; @@ -175,8 +178,18 @@ bool Connection::open( const char *sAddr, int nPort ) bActive = false; return false; } + + // These lines set the socket to non-blocking, a good thing? + int flags; + flags = fcntl(nSocket, F_GETFL, 0); + flags |= O_NONBLOCK; + if (fcntl(nSocket, F_SETFL, flags) < 0) + { + return false; + } /* Connect to the server. */ + //printf("Resolving hostname (%s)...\n", sAddr ); { struct hostent *hostinfo; @@ -190,16 +203,20 @@ bool Connection::open( const char *sAddr, int nPort ) xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr; } + //printf("Making actual connection..."); + fflush( stdout ); int ret = connect( nSocket, (struct sockaddr *)&xServerName, sizeof(xServerName) ); + //printf("Connected.\n"); + /* if( ret < 0 ) { return false; - } + }*/ bActive = true; bDisconnectMe = false; @@ -220,7 +237,7 @@ int Connection::readInput() nbytes = read( nSocket, buffer, RBS ); if( nbytes < 0 && errno != 0 && errno != EAGAIN ) { - printf("errno: %d, %s\n", errno, strerror( errno ) ); + //printf("errno: %d, %s\n", errno, strerror( errno ) ); /* Read error. */ //perror("readInput"); throw ConnectionException( excodeReadError, "Read error: %s", strerror( errno ) ); -- cgit v1.2.3