00001 #include "Utilities/StorageFactory/interface/IOOutput.h" 00002 #include "FWCore/Utilities/interface/EDMException.h" 00003 #include <cassert> 00004 00006 IOOutput::~IOOutput (void) 00007 {} 00008 00012 00040 IOSize 00041 IOOutput::write (unsigned char byte) 00042 { return write (&byte, 1); } 00043 00062 IOSize 00063 IOOutput::write (IOBuffer from) 00064 { return write (from.data (), from.size ()); } 00065 00089 IOSize 00090 IOOutput::writev (const IOBuffer *from, IOSize buffers) 00091 { 00092 assert (! buffers || from); 00093 00094 // Keep writing as long as possible; ignore errors if we have 00095 // written something, otherwise pass it on. 00096 IOSize x; 00097 IOSize done = 0; 00098 try 00099 { 00100 for (IOSize i = 0; i < buffers; ++i) 00101 { 00102 done += (x = write (from [i].data (), from [i].size ())); 00103 if (x < from [i].size ()) 00104 break; 00105 } 00106 } 00107 catch (cms::Exception &) 00108 { 00109 if (! done) 00110 throw; 00111 } 00112 00113 return done; 00114 } 00115 00119 00145 IOSize 00146 IOOutput::xwrite (IOBuffer from) 00147 { return xwrite (from.data (), from.size ()); } 00148 00175 IOSize 00176 IOOutput::xwrite (const void *from, IOSize n) 00177 { 00178 // Keep writing until we've written it all. Let errors fly over. 00179 IOSize done = 0; 00180 while (done < n) 00181 done += write ((const char *) from + done, n - done); 00182 00183 return done; 00184 } 00185 00214 IOSize 00215 IOOutput::xwritev (const IOBuffer *from, IOSize buffers) 00216 { 00217 // Keep writing until we've written it all. Let errors fly over. 00218 // FIXME: Use writev(from, buffers) and then sort out in case of 00219 // failure, the writev probably succeed directly with much less 00220 // overhead. 00221 assert (! buffers || from); 00222 00223 IOSize done = 0; 00224 for (IOSize i = 0; i < buffers; ++i) 00225 done += xwrite (from [i].data (), from [i].size ()); 00226 00227 return done; 00228 }