// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: ftp.cc,v 1.3 1999/03/15 08:10:26 jgg Exp $
+// $Id: ftp.cc,v 1.6 1999/04/11 21:23:10 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the FTP aquire method for APT.
/* This performs a very simple buffered read. */
bool FTPConn::ReadLine(string &Text)
{
+ if (ServerFd == -1)
+ return false;
+
// Suck in a line
while (Len < sizeof(Buffer))
{
}
// Suck it back
- int Res = read(ServerFd,Buffer,sizeof(Buffer) - Len);
+ int Res = read(ServerFd,Buffer + Len,sizeof(Buffer) - Len);
if (Res <= 0)
{
Close();
}
// Port mode :<
- if (DataListenFd == -1)
- {
- // Get a socket
- if ((DataListenFd = socket(AF_INET,SOCK_STREAM,0)) < 0)
- return _error->Errno("socket","Could not create a socket");
-
- // Bind and listen
- sockaddr_in Addr;
- memset(&Addr,0,sizeof(Addr));
- if (bind(DataListenFd,(sockaddr *)&Addr,sizeof(Addr)) < 0)
- return _error->Errno("bind","Could not bind a socket");
- if (listen(DataListenFd,1) < 0)
- return _error->Errno("listen","Could not listen on the socket");
- SetNonBlock(DataListenFd,true);
- }
+ close(DataListenFd);
+ DataListenFd = -1;
+
+ // Get a socket
+ if ((DataListenFd = socket(AF_INET,SOCK_STREAM,0)) < 0)
+ return _error->Errno("socket","Could not create a socket");
- // Determine the name to send to the remote
+ // Bind and listen
sockaddr_in Addr;
+ memset(&Addr,0,sizeof(Addr));
+ if (bind(DataListenFd,(sockaddr *)&Addr,sizeof(Addr)) < 0)
+ return _error->Errno("bind","Could not bind a socket");
+ if (listen(DataListenFd,1) < 0)
+ return _error->Errno("listen","Could not listen on the socket");
+ SetNonBlock(DataListenFd,true);
+
+ // Determine the name to send to the remote
sockaddr_in Addr2;
socklen_t Jnk = sizeof(Addr);
if (getsockname(DataListenFd,(sockaddr *)&Addr,&Jnk) < 0)
if (DataFd < 0)
return _error->Errno("accept","Unable to accept connection");
+ close(DataListenFd);
+ DataListenFd = -1;
+
return true;
}
/*}}}*/
}
// Get the files information
+ Status("Query");
unsigned long Size;
if (Server->Size(File,Size) == false ||
Server->ModTime(File,FailTime) == false)