CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/Utilities/StorageFactory/src/IOInput.cc

Go to the documentation of this file.
00001 #include "Utilities/StorageFactory/interface/IOInput.h"
00002 #include "FWCore/Utilities/interface/EDMException.h"
00003 #include <cassert>
00004 
00006 IOInput::~IOInput (void)
00007 {}
00008 
00012 
00053 int
00054 IOInput::read (void)
00055 {
00056   unsigned char byte;
00057   IOSize n = read (&byte, 1);
00058   return n == 0 ? -1 : byte;
00059 }
00060 
00083 IOSize
00084 IOInput::read (IOBuffer into)
00085 { return read (into.data (), into.size ()); }
00086 
00116 IOSize
00117 IOInput::readv (IOBuffer *into, IOSize buffers)
00118 {
00119   assert (! buffers || into);
00120 
00121   // Keep reading as long as possible; ignore errors if we have read
00122   // something, otherwise pass it on.
00123   IOSize status;
00124   IOSize done = 0;
00125   try
00126   {
00127     for (IOSize i = 0; i < buffers; done += status, ++i)
00128       if ((status = read (into [i])) == 0)
00129         break;
00130   }
00131   catch (cms::Exception &)
00132   {
00133     if (! done)
00134       throw;
00135   }
00136 
00137   return done;
00138 }
00139 
00143 
00165 IOSize
00166 IOInput::xread (IOBuffer into)
00167 { return xread (into.data (), into.size ()); }
00168 
00190 IOSize
00191 IOInput::xread (void *into, IOSize n)
00192 {
00193   assert (into);
00194 
00195   // Keep reading as long as possible.  Let system errors fly over
00196   // us, they are a hard error.
00197   IOSize x;
00198   IOSize done = 0;
00199   while (done < n && (x = read ((char *) into + done, n - done)))
00200     done += x;
00201 
00202   return done;
00203 }
00204 
00228 IOSize
00229 IOInput::xreadv (IOBuffer *into, IOSize buffers)
00230 {
00231   // FIXME: Use read(into, buffers) and then sort out in case of
00232   // failure, the readv probably succeed directly with much less
00233   // overhead.
00234 
00235   assert (! buffers || into);
00236 
00237   // Keep reading as long as possible.  Let system errors fly
00238   // over us, they are a hard error.
00239   IOSize x;
00240   IOSize done = 0;
00241   for (IOSize i = 0; i < buffers; ++i)
00242   {
00243     done += (x = xread (into [i]));
00244     if (x < into [i].size ())
00245       break;
00246   }
00247   return done;
00248 }