if(s<0 || l<0)
throw invalid_argument("Slice");
+ Base::Synchronize sync(below);
mode = below.get_mode()&M_RDWR;
below.signal_flush_required.connect(sigc::mem_fun(this, &Slice::flush));
}
check_access(m);
if(sync_position)
- seek(position, S_BEG);
-
- SeekOffset remaining = start_offset+length-position;
+ {
+ SeekOffset pos = below.seek(start_offset+position, S_BEG)-start_offset;
+ if(pos!=position)
+ throw runtime_error("failed to restore position");
+ sync_position = false;
+ }
+
+ SeekOffset remaining = length-position;
if(size>remaining)
size = remaining;
if(!size && m==M_READ)
unsigned Slice::do_write(const char *data, unsigned size)
{
+ Base::Synchronize sync(below);
size = prepare_op(size, M_WRITE);
if(!size)
return 0;
unsigned Slice::do_read(char *data, unsigned size)
{
+ Base::Synchronize sync(below);
size = prepare_op(size, M_READ);
if(!size)
return 0;
unsigned Slice::put(char c)
{
+ Base::Synchronize sync(below);
if(!prepare_op(1, M_WRITE))
return 0;
int Slice::get()
{
+ Base::Synchronize sync(below);
if(!prepare_op(1, M_READ))
return 0;
SeekOffset Slice::seek(SeekOffset off, SeekType type)
{
- if(type==S_BEG)
- off += start_offset;
- else if(type==S_CUR)
+ Base::Synchronize sync(below);
+ off += start_offset;
+ if(type==S_CUR)
off += position;
else if(type==S_END)
- off += start_offset+length;
+ off += length;
+ else if(type!=S_BEG)
+ throw invalid_argument("Slice::seek");
if(off<start_offset || off>start_offset+length)
throw bad_seek(off, type);