Browse Source

use a static FileFd::Write overload to reduce duplication of write()-retry code

debian/1.8.y
David Kalnischkies 10 years ago
parent
commit
d68d65ad63
  1. 27
      apt-pkg/acquire-worker.cc
  2. 16
      apt-pkg/acquire.cc
  3. 22
      apt-pkg/contrib/fileutl.cc
  4. 1
      apt-pkg/contrib/fileutl.h
  5. 34
      apt-pkg/deb/dpkgpm.cc
  6. 1
      debian/libapt-pkg4.12.symbols

27
apt-pkg/acquire-worker.cc

@ -433,21 +433,7 @@ bool pkgAcquire::Worker::MediaChange(string Message)
<< endl;
std::string const dlstatus = status.str();
size_t done = 0;
size_t todo = dlstatus.size();
errno = 0;
int res = 0;
do
{
res = write(status_fd, dlstatus.c_str() + done, todo);
if (res < 0 && errno == EINTR)
continue;
if (res < 0)
break;
done += res;
todo -= res;
}
while (res > 0 && todo > 0);
FileFd::Write(status_fd, dlstatus.c_str(), dlstatus.size());
}
if (Log == 0 || Log->MediaChange(LookupTag(Message,"Media"),
@ -546,17 +532,10 @@ bool pkgAcquire::Worker::QueueItem(pkgAcquire::Queue::QItem *Item)
/* */
bool pkgAcquire::Worker::OutFdReady()
{
int Res;
do
{
Res = write(OutFd,OutQueue.c_str(),OutQueue.length());
}
while (Res < 0 && errno == EINTR);
if (Res <= 0)
if (FileFd::Write(OutFd,OutQueue.c_str(),OutQueue.length()) == false)
return MethodFailure();
OutQueue.erase(0,Res);
OutQueue.clear();
if (OutQueue.empty() == true)
OutReady = false;

16
apt-pkg/acquire.cc

@ -874,21 +874,7 @@ bool pkgAcquireStatus::Pulse(pkgAcquire *Owner)
<< endl;
std::string const dlstatus = status.str();
size_t done = 0;
size_t todo = dlstatus.size();
errno = 0;
int res = 0;
do
{
res = write(fd, dlstatus.c_str() + done, todo);
if (res < 0 && errno == EINTR)
continue;
if (res < 0)
break;
done += res;
todo -= res;
}
while (res > 0 && todo > 0);
FileFd::Write(fd, dlstatus.c_str(), dlstatus.size());
}
return true;

22
apt-pkg/contrib/fileutl.cc

@ -1301,6 +1301,28 @@ bool FileFd::Write(const void *From,unsigned long long Size)
Flags |= Fail;
return _error->Error(_("write, still have %llu to write but couldn't"), Size);
}
bool FileFd::Write(int Fd, const void *From, unsigned long long Size)
{
int Res;
errno = 0;
do
{
Res = write(Fd,From,Size);
if (Res < 0 && errno == EINTR)
continue;
if (Res < 0)
return _error->Errno("write",_("Write error"));
From = (char *)From + Res;
Size -= Res;
}
while (Res > 0 && Size > 0);
if (Size == 0)
return true;
return _error->Error(_("write, still have %llu to write but couldn't"), Size);
}
/*}}}*/
// FileFd::Seek - Seek in the file /*{{{*/

1
apt-pkg/contrib/fileutl.h

@ -78,6 +78,7 @@ class FileFd
bool Read(void *To,unsigned long long Size,unsigned long long *Actual = 0);
char* ReadLine(char *To, unsigned long long const Size);
bool Write(const void *From,unsigned long long Size);
bool static Write(int Fd, const void *From, unsigned long long Size);
bool Seek(unsigned long long To);
bool Skip(unsigned long long To);
bool Truncate(unsigned long long To);

34
apt-pkg/deb/dpkgpm.cc

@ -163,26 +163,6 @@ pkgCache::VerIterator FindNowVersion(const pkgCache::PkgIterator &Pkg)
return Ver;
}
/*}}}*/
static ssize_t
retry_write(int fd, const void *buf, size_t count)
{
int Res;
ssize_t i = 0;
errno = 0;
do
{
Res = write(fd, buf, count);
if (Res < 0 && errno == EINTR)
continue;
if (Res < 0)
break;
buf = (char *)buf + Res;
count -= Res;
i += Res;
}
while (Res > 0 && count > 0);
return i;
}
// DPkgPM::pkgDPkgPM - Constructor /*{{{*/
// ---------------------------------------------------------------------
@ -445,7 +425,7 @@ void pkgDPkgPM::DoStdin(int master)
unsigned char input_buf[256] = {0,};
ssize_t len = read(0, input_buf, sizeof(input_buf));
if (len)
retry_write(master, input_buf, len);
FileFd::Write(master, input_buf, len);
else
d->stdin_is_dev_null = true;
}
@ -471,7 +451,7 @@ void pkgDPkgPM::DoTerminalPty(int master)
}
if(len <= 0)
return;
retry_write(1, term_buf, len);
FileFd::Write(1, term_buf, len);
if(d->term_out)
fwrite(term_buf, len, sizeof(char), d->term_out);
}
@ -546,7 +526,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << s
<< endl;
if(OutStatusFd > 0)
retry_write(OutStatusFd, status.str().c_str(), status.str().size());
FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
@ -570,7 +550,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << list[3]
<< endl;
if(OutStatusFd > 0)
retry_write(OutStatusFd, status.str().c_str(), status.str().size());
FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
pkgFailures++;
@ -584,7 +564,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << list[3]
<< endl;
if(OutStatusFd > 0)
retry_write(OutStatusFd, status.str().c_str(), status.str().size());
FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
return;
@ -612,7 +592,7 @@ void pkgDPkgPM::ProcessDpkgStatusLine(int OutStatusFd, char *line)
<< ":" << s
<< endl;
if(OutStatusFd > 0)
retry_write(OutStatusFd, status.str().c_str(), status.str().size());
FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
if (Debug == true)
std::clog << "send: '" << status.str() << "'" << endl;
}
@ -1257,7 +1237,7 @@ bool pkgDPkgPM::Go(int OutStatusFd)
<< (PackagesDone/float(PackagesTotal)*100.0)
<< ":" << _("Running dpkg")
<< endl;
retry_write(OutStatusFd, status.str().c_str(), status.str().size());
FileFd::Write(OutStatusFd, status.str().c_str(), status.str().size());
}
Child = ExecFork();

1
debian/libapt-pkg4.12.symbols

@ -1524,6 +1524,7 @@ libapt-pkg.so.4.12 libapt-pkg4.12 #MINVER#
(c++)"GetListOfFilesInDir(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool)@Base" 0.8.16~exp13
(c++)"pkgCache::DepIterator::IsIgnorable(pkgCache::PkgIterator const&) const@Base" 0.8.16~exp10
(c++)"pkgCache::DepIterator::IsIgnorable(pkgCache::PrvIterator const&) const@Base" 0.8.16~exp10
(c++)"FileFd::Write(int, void const*, unsigned long long)@Base" 0.8.16~exp14
(c++|optional=private)"pkgCacheGenerator::MergeListGroup(pkgCacheGenerator::ListParser&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)@Base" 0.8.16~exp7
(c++|optional=private)"pkgCacheGenerator::MergeListPackage(pkgCacheGenerator::ListParser&, pkgCache::PkgIterator&)@Base" 0.8.16~exp7
(c++|optional=private)"pkgCacheGenerator::MergeListVersion(pkgCacheGenerator::ListParser&, pkgCache::PkgIterator&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, pkgCache::VerIterator*&)@Base" 0.8.16~exp7

Loading…
Cancel
Save