summaryrefslogtreecommitdiff
path: root/src/httpget.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/httpget.cpp76
1 files changed, 51 insertions, 25 deletions
diff --git a/src/httpget.cpp b/src/httpget.cpp
index 529d814..ee1f29c 100644
--- a/src/httpget.cpp
+++ b/src/httpget.cpp
@@ -156,8 +156,8 @@ SBuffer *HttpGet::get()
156 //printf("Connection content:\n\n%s\n\n", sData.c_str() ); 156 //printf("Connection content:\n\n%s\n\n", sData.c_str() );
157 157
158 Connection con; 158 Connection con;
159 //printf("Opening connection...\n");
159 con.open( sHost.c_str(), nPort ); 160 con.open( sHost.c_str(), nPort );
160 //printf("Connected, sending request.\n");
161 { 161 {
162 int nSocket = con.getSocket(); 162 int nSocket = con.getSocket();
163 fd_set rfds, wfds, efds; 163 fd_set rfds, wfds, efds;
@@ -170,50 +170,74 @@ SBuffer *HttpGet::get()
170 FD_ZERO(&efds); 170 FD_ZERO(&efds);
171 FD_SET(nSocket, &efds); 171 FD_SET(nSocket, &efds);
172 172
173 retval = select( nSocket+1, &rfds, &wfds, &efds, NULL ); 173 struct timeval tv;
174 printf("About to write: sock=%d, r=%d, w=%d, e=%d, ret=%d\n", 174 tv.tv_sec = 4;
175 tv.tv_usec = 0;
176
177 //printf("Selecting on socket, can we read, write, etc?\n");
178 retval = select( nSocket+1, &rfds, &wfds, &efds, &tv );
179 /*printf("About to write: sock=%d, r=%d, w=%d, e=%d, ret=%d\n",
175 nSocket, 180 nSocket,
176 FD_ISSET( nSocket, &rfds ), 181 FD_ISSET( nSocket, &rfds ),
177 FD_ISSET( nSocket, &wfds ), 182 FD_ISSET( nSocket, &wfds ),
178 FD_ISSET( nSocket, &efds ), 183 FD_ISSET( nSocket, &efds ),
179 retval 184 retval
180 ); 185 );*/
186
187 if( retval == 0 )
188 {
189 //printf("Timeout on connection.\n");
190 con.close();
191 throw ExceptionBase("Connection Timeout on open.\n");
192 }
181 193
182 } 194 }
183 con.appendOutput( sData.c_str(), sData.size() ); 195 con.appendOutput( sData.c_str(), sData.size() );
196 //printf("Writing to socket...\n");
184 con.writeOutput(); 197 con.writeOutput();
198 //printf("Data written...\n");
185 int nSec = 5; 199 int nSec = 5;
186 int nUSec = 0; 200 int nUSec = 0;
187 int nLastAmnt = con.getInputAmnt(); 201 int nLastAmnt = con.getInputAmnt();
188 try 202 try
189 { 203 {
190 double dTotTime = 0.0; 204 double dTotTime = 0.0;
191 while( con.readInput( nSec, nUSec, &nSec, &nUSec ) ) 205 //printf("About to read input...\n");
192 { 206 while( con.readInput( nSec, nUSec, &nSec, &nUSec ) )
193 if( nLastAmnt == con.getInputAmnt() )
194 {
195 if( nSec <= 0 && nUSec <= 0 )
196 throw ExceptionBase("Connection Timeout.\n");
197 if( nSec == 5 && nUSec == 0 )
198 break;
199 }
200 else
201 { 207 {
202 dTotTime += (5.0-(nSec+nUSec/1000000.0)); 208 if( nLastAmnt == con.getInputAmnt() )
203 printf("\rRead %db at %.2fkb/sec", 209 {
204 con.getInputAmnt(), 210 if( nSec <= 0 && nUSec <= 0 )
205 ((double)(con.getInputAmnt())/1024.0) / dTotTime 211 {
206 ); 212 //printf("out of time, closing up.\n");
207 fflush( stdout ); 213 con.close();
208 nSec = 5; 214 throw ExceptionBase("Connection Timeout.\n");
209 nUSec = 0; 215 }
210 nLastAmnt = con.getInputAmnt(); 216 if( nSec == 5 && nUSec == 0 )
217 {
218 //printf("No new data, breaking.\n");
219 break;
220 }
221 }
222 else
223 {
224 dTotTime += (5.0-(nSec+nUSec/1000000.0));
225 printf("\rRead %db at %.2fkb/sec",
226 con.getInputAmnt(),
227 ((double)(con.getInputAmnt())/1024.0) / dTotTime
228 );
229 fflush( stdout );
230 nSec = 5;
231 nUSec = 0;
232 nLastAmnt = con.getInputAmnt();
233 }
211 } 234 }
212 } 235 }
213 }
214 catch( ConnectionException &e ) 236 catch( ConnectionException &e )
215 { 237 {
216 printf("ConnectionException: %s\n", e.what() ); 238 //con.close();
239 if( strcmp( e.what(), "Connection closed" ) )
240 printf("\nConnectionException: %s\n", e.what() );
217 } 241 }
218 242
219 int total = con.getInputAmnt(); 243 int total = con.getInputAmnt();
@@ -232,6 +256,8 @@ SBuffer *HttpGet::get()
232 } 256 }
233 con.close(); 257 con.close();
234 258
259 //printf("\n\n%s\n\n", dat );
260
235 throw ExceptionBase("Something went wrong, incomplete response? fix this.\n"); 261 throw ExceptionBase("Something went wrong, incomplete response? fix this.\n");
236} 262}
237 263