// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: http.cc,v 1.23 1999/01/28 06:32:31 jgg Exp $
+// $Id: http.cc,v 1.28 1999/03/15 06:01:00 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the HTTP aquire method for APT.
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
+#include <errno.h>
// Internet stuff
#include <netinet/in.h>
/* This implements a timeout for connect by opening the connection
nonblocking */
- fd_set wfds;
- FD_ZERO(&wfds);
- FD_SET(ServerFd,&wfds);
- struct timeval tv;
- tv.tv_sec = TimeOut;
- tv.tv_usec = 0;
- int Res = 0;
- if ((Res = select(ServerFd+1,0,&wfds,0,&tv)) < 0)
- return _error->Errno("select","Select failed");
- if (Res == 0)
+ if (WaitFd(ServerFd,true,TimeOut) == false)
return _error->Error("Could not connect, connection timed out");
- unsigned int Err,Len=sizeof(Err);
+ unsigned int Err;
+ unsigned int Len = sizeof(Err);
if (getsockopt(ServerFd,SOL_SOCKET,SO_ERROR,&Err,&Len) != 0)
return _error->Errno("getsockopt","Failed");
if (Err != 0)
while ((Last = Owner->Go(false,this)) == true);
if (Last == false)
return false;
- return true;
+ return !_error->PendingError();
}
// Transfer the block
continue;
In.Limit(-1);
- return true;
+ return !_error->PendingError();
}
while (Owner->Go(true,this) == true);
}
- return Owner->Flush(this);
+ return Owner->Flush(this) && !_error->PendingError();
}
/*}}}*/
// ServerState::HeaderLine - Process a header line /*{{{*/
/* */
bool HttpMethod::ServerDie(ServerState *Srv)
{
+ unsigned int LErrno = errno;
+
// Dump the buffer to the file
if (Srv->State == ServerState::Data)
{
Srv->Encoding != ServerState::Closes)
{
Srv->Close();
- if (errno == 0)
+ if (LErrno == 0)
return _error->Error("Error reading from server Remote end closed connection");
+ errno = LErrno;
return _error->Errno("read","Error reading from server");
}
else
return 5;
FailFile = Queue->DestFile;
- FailFile.c_str(); // Make sure we don't do a malloc in the signal handler
+ FailFile.c_str(); // Make sure we dont do a malloc in the signal handler
FailFd = File->Fd();
FailTime = Srv->Date;
int FailCounter = 0;
while (1)
- {
- if (FailCounter >= 2)
- {
- Fail("Massive Server Brain Damage");
- FailCounter = 0;
- }
-
+ {
// We have no commands, wait for some to arrive
if (Queue == 0)
{
// Connnect to the host
if (Server->Open() == false)
{
- Fail();
+ Fail(true);
delete Server;
Server = 0;
continue;
case 2:
{
_error->Error("Bad header Data");
- Fail();
+ Fail(true);
continue;
}
FailCounter++;
_error->Discard();
Server->Close();
+
+ if (FailCounter >= 2)
+ {
+ Fail("Connection timed out",true);
+ FailCounter = 0;
+ }
+
continue;
}
};
URIDone(Res);
}
else
- Fail();
+ Fail(true);
break;
}