summaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2007-04-02 15:56:17 +0000
committerMike Buland <eichlan@xagasoft.com>2007-04-02 15:56:17 +0000
commitcc4604c1e22e01c31d25923ed76d1518693b7faa (patch)
treed843e1c18882298a7bad38089a24092c9ceda3cb /src/connection.cpp
parentbebc878b054a06ff8e541db695b1e586fff2b022 (diff)
downloadlibbu++-cc4604c1e22e01c31d25923ed76d1518693b7faa.tar.gz
libbu++-cc4604c1e22e01c31d25923ed76d1518693b7faa.tar.bz2
libbu++-cc4604c1e22e01c31d25923ed76d1518693b7faa.tar.xz
libbu++-cc4604c1e22e01c31d25923ed76d1518693b7faa.zip
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.
Diffstat (limited to 'src/connection.cpp')
-rw-r--r--src/connection.cpp21
1 files changed, 19 insertions, 2 deletions
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 @@
11#include <netdb.h> 11#include <netdb.h>
12#include <arpa/inet.h> 12#include <arpa/inet.h>
13#include <errno.h> 13#include <errno.h>
14#include <fcntl.h>
14#include "exceptions.h" 15#include "exceptions.h"
15 16
16// Read buffer size...maybe fix wierd issues... 17// Read buffer size...maybe fix wierd issues...
@@ -137,10 +138,12 @@ bool Connection::isActive()
137 138
138void Connection::close() 139void Connection::close()
139{ 140{
141 //printf("Close called, socket is: %s\n", bActive?"Active":"Inactive" );
140 if( bActive ) 142 if( bActive )
141 { 143 {
142 fsync( nSocket ); 144 fsync( nSocket );
143 ::close( nSocket ); 145 ::close( nSocket );
146 //printf("Socket closed.\n");
144 } 147 }
145 bActive = false; 148 bActive = false;
146 //nSocket = -1; 149 //nSocket = -1;
@@ -175,8 +178,18 @@ bool Connection::open( const char *sAddr, int nPort )
175 bActive = false; 178 bActive = false;
176 return false; 179 return false;
177 } 180 }
181
182 // These lines set the socket to non-blocking, a good thing?
183 int flags;
184 flags = fcntl(nSocket, F_GETFL, 0);
185 flags |= O_NONBLOCK;
186 if (fcntl(nSocket, F_SETFL, flags) < 0)
187 {
188 return false;
189 }
178 190
179 /* Connect to the server. */ 191 /* Connect to the server. */
192 //printf("Resolving hostname (%s)...\n", sAddr );
180 { 193 {
181 struct hostent *hostinfo; 194 struct hostent *hostinfo;
182 195
@@ -190,16 +203,20 @@ bool Connection::open( const char *sAddr, int nPort )
190 xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr; 203 xServerName.sin_addr = *(struct in_addr *) hostinfo->h_addr;
191 } 204 }
192 205
206 //printf("Making actual connection...");
207 fflush( stdout );
193 int ret = connect( 208 int ret = connect(
194 nSocket, 209 nSocket,
195 (struct sockaddr *)&xServerName, 210 (struct sockaddr *)&xServerName,
196 sizeof(xServerName) 211 sizeof(xServerName)
197 ); 212 );
213 //printf("Connected.\n");
198 214
215 /*
199 if( ret < 0 ) 216 if( ret < 0 )
200 { 217 {
201 return false; 218 return false;
202 } 219 }*/
203 220
204 bActive = true; 221 bActive = true;
205 bDisconnectMe = false; 222 bDisconnectMe = false;
@@ -220,7 +237,7 @@ int Connection::readInput()
220 nbytes = read( nSocket, buffer, RBS ); 237 nbytes = read( nSocket, buffer, RBS );
221 if( nbytes < 0 && errno != 0 && errno != EAGAIN ) 238 if( nbytes < 0 && errno != 0 && errno != EAGAIN )
222 { 239 {
223 printf("errno: %d, %s\n", errno, strerror( errno ) ); 240 //printf("errno: %d, %s\n", errno, strerror( errno ) );
224 /* Read error. */ 241 /* Read error. */
225 //perror("readInput"); 242 //perror("readInput");
226 throw ConnectionException( excodeReadError, "Read error: %s", strerror( errno ) ); 243 throw ConnectionException( excodeReadError, "Read error: %s", strerror( errno ) );