void File::set_block(bool b)
{
- mode = b?(mode&~M_NONBLOCK):(mode|M_NONBLOCK);
+ adjust_mode(mode, M_NONBLOCK, !b);
sys_set_blocking(handle, b);
}
inline Mode operator~(Mode m)
{ return Mode(~static_cast<int>(m)); }
+inline void adjust_mode(Mode &m, Mode f, bool b)
+{ m = b ? (m|f) : (m&~f); }
+
class invalid_access: public std::logic_error
{
void Pipe::set_block(bool b)
{
- mode = (mode&~M_NONBLOCK);
- if(b)
- mode = (mode|M_NONBLOCK);
-
+ adjust_mode(mode, M_NONBLOCK, !b);
sys_set_blocking(read_handle, b);
sys_set_blocking(write_handle, b);
}
void Serial::set_block(bool b)
{
- mode = b?(mode&~M_NONBLOCK):(mode|M_NONBLOCK);
+ adjust_mode(mode, M_NONBLOCK, !b);
sys_set_blocking(handle, b);
}