1 #include <lib/base/buffer.h>
2 #include <lib/base/eerror.h>
7 void eIOBuffer::removeblock()
9 ASSERT(!buffer.empty());
10 eIOBufferData &b=buffer.front();
16 eIOBuffer::eIOBufferData &eIOBuffer::addblock()
19 s.data=new __u8[allocationsize];
25 eIOBuffer::~eIOBuffer()
30 void eIOBuffer::clear()
32 while (!buffer.empty())
36 int eIOBuffer::size() const
39 for (std::list<eIOBufferData>::const_iterator i(buffer.begin()); i != buffer.end(); ++i)
45 int eIOBuffer::empty() const
47 return buffer.empty();
50 int eIOBuffer::peek(void *dest, int len) const
52 __u8 *dst=(__u8*)dest;
53 std::list<eIOBufferData>::const_iterator i(buffer.begin());
58 if (i == buffer.end())
64 memcpy(dst, i->data+p, tc);
76 void eIOBuffer::skip(int len)
80 ASSERT(! buffer.empty());
82 if (tn > (buffer.front().len-ptr))
83 tn=buffer.front().len-ptr;
86 if (ptr == buffer.front().len)
92 int eIOBuffer::read(void *dest, int len)
94 __u8 *dst=(__u8*)dest;
100 void eIOBuffer::write(const void *source, int len)
102 const __u8 *src=(const __u8*)source;
106 if (buffer.empty() || (allocationsize == buffer.back().len))
108 if (tc > allocationsize-buffer.back().len)
109 tc=allocationsize-buffer.back().len;
110 memcpy(buffer.back().data+buffer.back().len, src, tc);
112 buffer.back().len+=tc;
117 int eIOBuffer::fromfile(int fd, int len)
124 if (buffer.empty() || (allocationsize == buffer.back().len))
126 if (tc > allocationsize-buffer.back().len)
127 tc=allocationsize-buffer.back().len;
128 r=::read(fd, buffer.back().data+buffer.back().len, tc);
129 buffer.back().len+=r;
133 if (errno != EWOULDBLOCK)
144 int eIOBuffer::tofile(int fd, int len)
148 while (len && !buffer.empty())
150 if (buffer.begin() == buffer.end())
152 int tc=buffer.front().len-ptr;
156 w=::write(fd, buffer.front().data+ptr, tc);
159 if (errno != EWOULDBLOCK)
164 if (ptr == buffer.front().len)
175 int eIOBuffer::searchchr(char ch) const
177 std::list<eIOBufferData>::const_iterator i(buffer.begin());
182 if (i == buffer.end())
186 if (i->data[p] == ch)