while(1)
{
- int c=get();
+ int c = get();
if(c==-1 || c=='\n')
break;
- line+=c;
+ line += c;
}
return !eof_flag || !line.empty();
void Base::set_events(PollEvent e)
{
- events=e;
+ events = e;
signal_events_changed.emit(events);
}
end(buf),
cur_op(M_NONE)
{
- mode=below.get_mode();
+ mode = below.get_mode();
below.signal_flush_required.connect(sigc::mem_fun(this, &Buffered::flush));
}
if(end<buf+buf_size)
{
- *end++=c;
+ *end++ = c;
return 1;
}
else
{
if(cur_op==M_WRITE)
{
- unsigned used=end-begin;
+ unsigned used = end-begin;
if(used)
{
- unsigned len=below.write(begin, used);
+ unsigned len = below.write(begin, used);
- begin=end=buf;
+ begin=end = buf;
if(len<used)
throw Exception("Couldn't flush all data");
}
}
else if(cur_op==M_READ)
- begin=end=buf;
+ begin=end = buf;
}
bool Buffered::getline(std::string &line)
if(*i=='\n')
{
line.assign(begin, i-begin);
- begin=i+1;
+ begin = i+1;
return true;
}
{
if(op!=cur_op)
flush();
- cur_op=op;
+ cur_op = op;
}
unsigned Buffered::do_write(const char *data, unsigned size)
{
// All data fits in buffer with whatever is already there
memcpy(end, data, size);
- end+=size;
+ end += size;
return size;
}
{
// Put new data in the buffer to wait for more
memcpy(end, data, size);
- end+=size;
+ end += size;
return size;
}
{
// The request can be served from the buffer
memcpy(data, begin, size);
- begin+=size;
+ begin += size;
- eof_flag=(below.eof() && begin==end);
+ eof_flag = (below.eof() && begin==end);
return size;
}
{
// Give out whatever is in the buffer already
memcpy(data, begin, end-begin);
- unsigned ret=end-begin;
- begin=end=buf;
+ unsigned ret = end-begin;
+ begin=end = buf;
- data+=ret;
- size-=ret;
+ data += ret;
+ size -= ret;
if(size<buf_size)
{
// Fill the buffer and serve the rest of the request from it
- unsigned len=below.read(end, buf+buf_size-end);
- end+=len;
+ unsigned len = below.read(end, buf+buf_size-end);
+ end += len;
- len=min(static_cast<unsigned>(end-begin), size);
+ len = min(static_cast<unsigned>(end-begin), size);
memcpy(data, begin, len);
- begin+=len;
- ret+=len;
+ begin += len;
+ ret += len;
}
else
// Read the rest directly from the underlying object
- ret+=below.read(data, size);
+ ret += below.read(data, size);
- eof_flag=(below.eof() && begin==end);
+ eof_flag = (below.eof() && begin==end);
return ret;
}
if(n>2)
throw InvalidParameterValue("Invalid parameter for Console::Console");
- mode=(n==0 ? M_READ : M_WRITE);
+ mode = (n==0 ? M_READ : M_WRITE);
#ifdef WIN32
switch(n)
{
- case 0: handle=GetStdHandle(STD_INPUT_HANDLE); break;
- case 1: handle=GetStdHandle(STD_OUTPUT_HANDLE); break;
- case 2: handle=GetStdHandle(STD_ERROR_HANDLE); break;
+ case 0: handle = GetStdHandle(STD_INPUT_HANDLE); break;
+ case 1: handle = GetStdHandle(STD_OUTPUT_HANDLE); break;
+ case 2: handle = GetStdHandle(STD_ERROR_HANDLE); break;
}
#else
- handle=n;
+ handle = n;
if(handle==0)
tcgetattr(handle, &orig_attr);
// XXX Dunno how to do this in win32
(void)b;
#else
- int flags=fcntl(0, F_GETFL);
- flags=(flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
+ int flags = fcntl(0, F_GETFL);
+ flags = (flags&~O_NONBLOCK) | (b?0:O_NONBLOCK);
fcntl(0, F_SETFL, flags);
#endif
}
#else
termios t;
tcgetattr(0, &t);
- t.c_lflag=(t.c_lflag&~ECHO) | (e?ECHO:0);
+ t.c_lflag = (t.c_lflag&~ECHO) | (e?ECHO:0);
tcsetattr(0, TCSADRAIN, &t);
#endif
}
// XXX ICANON does more than just set line buffering, may need a bit more thought
termios t;
tcgetattr(0, &t);
- t.c_lflag=(t.c_lflag&~ICANON) | (l?ICANON:0);
+ t.c_lflag = (t.c_lflag&~ICANON) | (l?ICANON:0);
tcsetattr(0, TCSADRAIN, &t);
#endif
}
#ifdef WIN32
// XXX Figure out how to do this
- rows=24;
- cols=80;
+ rows = 24;
+ cols = 80;
#else
struct winsize wsz;
ioctl(handle, TIOCGWINSZ, &wsz);
- rows=wsz.ws_row;
- cols=wsz.ws_col;
+ rows = wsz.ws_row;
+ cols = wsz.ws_col;
#endif
}
if(!WriteFile(handle, buf, len, &ret, 0))
throw SystemError("Writing to console failed", GetLastError());
#else
- int ret=::write(handle, buf, len);
+ int ret = ::write(handle, buf, len);
if(ret==-1)
throw SystemError("Writing to console failed", errno);
#endif
if(!ReadFile(handle, buf, len, &ret, 0))
throw SystemError("Reading from console failed", GetLastError());
#else
- int ret=::read(handle, buf, len);
+ int ret = ::read(handle, buf, len);
if(ret==-1)
{
if(errno==EAGAIN)
throw SystemError("Reading from console failed", errno);
}
else if(ret==0)
- eof_flag=true;
+ eof_flag = true;
#endif
return ret;
throw InvalidParameterValue("Unknown Console instance requested");
}
-Console &cin=Console::instance(0);
-Console &cout=Console::instance(1);
-Console &cerr=Console::instance(2);
+Console &cin = Console::instance(0);
+Console &cout = Console::instance(1);
+Console &cerr = Console::instance(2);
} // namespace IO
} // namespace Msp
void EventDispatcher::add(Base &obj)
{
- SlotMap::iterator i=objects.find(&obj);
+ SlotMap::iterator i = objects.find(&obj);
if(i==objects.end())
{
- i=objects.insert(SlotMap::value_type(&obj, Slot(&obj))).first;
- i->second.evch_conn=obj.signal_events_changed.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_events_changed), &obj));
- i->second.del_conn=obj.signal_deleted.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_deleted), &obj));
+ i = objects.insert(SlotMap::value_type(&obj, Slot(&obj))).first;
+ i->second.evch_conn = obj.signal_events_changed.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_events_changed), &obj));
+ i->second.del_conn = obj.signal_deleted.connect(sigc::bind(sigc::mem_fun(this, &EventDispatcher::object_deleted), &obj));
if(obj.get_events())
poller.set_object(obj, obj.get_events());
void EventDispatcher::remove(Base &obj)
{
- SlotMap::iterator i=objects.find(&obj);
+ SlotMap::iterator i = objects.find(&obj);
if(i!=objects.end())
{
i->second.evch_conn.disconnect();
void EventDispatcher::dispatch()
{
- const Poller::SlotSeq &result=poller.get_result();
+ const Poller::SlotSeq &result = poller.get_result();
for(Poller::SlotSeq::const_iterator i=result.begin(); i!=result.end(); ++i)
i->object->event(i->events);
}
if(cm&~(C_CREATE|C_TRUNCATE))
throw InvalidParameterValue("Invalid create mode");
- mode=m;
+ mode = m;
#ifdef WIN32
- int flags=0;
- int create_flags=OPEN_EXISTING;
+ int flags = 0;
+ int create_flags = OPEN_EXISTING;
if(mode&M_READ)
- flags|=GENERIC_READ;
+ flags |= GENERIC_READ;
else if(mode&M_WRITE)
{
- flags|=GENERIC_WRITE;
+ flags |= GENERIC_WRITE;
switch(static_cast<int>(cm))
{
- case C_NONE: create_flags=OPEN_EXISTING; break;
- case C_CREATE: create_flags=OPEN_ALWAYS; break;
- case C_TRUNCATE: create_flags=TRUNCATE_EXISTING; break;
- case C_CREATE+C_TRUNCATE: create_flags=CREATE_ALWAYS; break;
+ case C_NONE: create_flags = OPEN_EXISTING; break;
+ case C_CREATE: create_flags = OPEN_ALWAYS; break;
+ case C_TRUNCATE: create_flags = TRUNCATE_EXISTING; break;
+ case C_CREATE+C_TRUNCATE: create_flags = CREATE_ALWAYS; break;
}
}
- handle=CreateFile(fn.c_str(), flags, 0, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0);
+ handle = CreateFile(fn.c_str(), flags, 0, 0, create_flags, FILE_ATTRIBUTE_NORMAL, 0);
if(handle==INVALID_HANDLE_VALUE)
{
- int err=GetLastError();
+ int err = GetLastError();
if(err==ERROR_FILE_NOT_FOUND)
throw FileNotFound("Can't find file "+fn, fn);
else
throw SystemError(format("Can't open file '%s'", fn), GetLastError());
}
#else
- int flags=0;
+ int flags = 0;
switch(mode&M_RDWR)
{
- case M_READ: flags|=O_RDONLY; break;
- case M_WRITE: flags|=O_WRONLY; break;
- case M_RDWR: flags|=O_RDWR; break;
+ case M_READ: flags |= O_RDONLY; break;
+ case M_WRITE: flags |= O_WRONLY; break;
+ case M_RDWR: flags |= O_RDWR; break;
default:;
}
if(mode&M_WRITE)
{
if(cm&C_CREATE)
- flags|=O_CREAT;
+ flags |= O_CREAT;
if(cm&C_TRUNCATE)
- flags|=O_TRUNC;
+ flags |= O_TRUNC;
}
if(mode&M_APPEND)
- flags|=O_APPEND;
+ flags |= O_APPEND;
if(mode&M_NONBLOCK)
- flags|=O_NONBLOCK;
+ flags |= O_NONBLOCK;
- handle=::open(fn.c_str(), flags, 0666);
+ handle = ::open(fn.c_str(), flags, 0666);
if(handle==-1)
{
- int err=errno;
+ int err = errno;
if(err==ENOENT)
throw FileNotFound("Can't find file "+fn, fn);
else
::close(handle);
#endif
- handle=MSP_IO_INVALID_HANDLE;
+ handle = MSP_IO_INVALID_HANDLE;
signal_closed.emit();
}
{
check_access(M_NONE);
- mode=(mode&~M_NONBLOCK);
+ mode = (mode&~M_NONBLOCK);
if(b)
- mode=(mode|M_NONBLOCK);
+ mode = (mode|M_NONBLOCK);
#ifndef WIN32
- int flags=fcntl(handle, F_GETFD);
+ int flags = fcntl(handle, F_GETFD);
fcntl(handle, F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
#endif
}
signal_flush_required.emit();
- int type=sys_seek_type(st);
+ int type = sys_seek_type(st);
#ifdef WIN32
- DWORD ret=SetFilePointer(handle, off, 0, type);
+ DWORD ret = SetFilePointer(handle, off, 0, type);
if(ret==INVALID_SET_FILE_POINTER)
throw SystemError("Seek failed", GetLastError());
#else
- int ret=lseek(handle, off, type);
+ int ret = lseek(handle, off, type);
if(ret==-1)
throw SystemError("Seek failed", errno);
#endif
- eof_flag=false;
+ eof_flag = false;
return ret;
}
check_access(M_NONE);
#ifdef WIN32
- DWORD ret=SetFilePointer(handle, 0, 0, FILE_CURRENT);
+ DWORD ret = SetFilePointer(handle, 0, 0, FILE_CURRENT);
if(ret==INVALID_SET_FILE_POINTER)
throw SystemError("Tell failed", GetLastError());
#else
- int ret=lseek(handle, 0, SEEK_CUR);
+ int ret = lseek(handle, 0, SEEK_CUR);
if(ret==-1)
throw SystemError("Tell failed", errno);
#endif
if(WriteFile(handle, buf, size, &ret, 0)==0)
throw SystemError("Writing to file failed", GetLastError());
#else
- int ret=::write(handle, buf, size);
+ int ret = ::write(handle, buf, size);
if(ret==-1)
{
if(errno==EAGAIN)
if(ReadFile(handle, buf, size, &ret, 0)==0)
throw SystemError("Reading from file failed", GetLastError());
#else
- int ret=::read(handle, buf, size);
+ int ret = ::read(handle, buf, size);
if(ret==-1)
{
if(errno==EAGAIN)
if(ret==0)
{
- eof_flag=true;
+ eof_flag = true;
signal_end_of_file.emit();
}
public:
enum CreateMode
{
- C_NONE=0,
- C_CREATE=1,
- C_TRUNCATE=2
+ C_NONE = 0,
+ C_CREATE = 1,
+ C_TRUNCATE = 2
};
- File(const std::string &, Mode=M_READ, CreateMode =CreateMode(C_CREATE+C_TRUNCATE));
+ File(const std::string &, Mode = M_READ, CreateMode =CreateMode(C_CREATE+C_TRUNCATE));
void close();
{
Filtered &f;
- Activator(Filtered &f_): f(f_) { f.active=true; }
- ~Activator() { f.active=false; }
+ Activator(Filtered &f_): f(f_) { f.active = true; }
+ ~Activator() { f.active = false; }
};
F filter;
public:
Filtered(): filter(*this), active(false) { }
- ~Filtered() { active=true; }
+ ~Filtered() { active = true; }
template<typename A0>
Filtered(A0 a0): B(a0), filter(*this), active(false) { }
Memory::Memory(const char *cd, unsigned s)
{
- char *d=const_cast<char *>(cd);
+ char *d = const_cast<char *>(cd);
init(d, d+s, M_READ);
}
void Memory::init(char *b, char *e, Mode m)
{
- begin=b;
- end=e;
- pos=begin;
- mode=m;
+ begin = b;
+ end = e;
+ pos = begin;
+ mode = m;
}
unsigned Memory::put(char c)
{
check_mode(M_WRITE);
- *pos++=c;
+ *pos++ = c;
return 1;
}
bool Memory::getline(string &line)
{
- char *nl=find(pos, end, '\n');
+ char *nl = find(pos, end, '\n');
line.assign(pos, nl);
- bool result=(nl!=pos);
- pos=nl;
+ bool result = (nl!=pos);
+ pos = nl;
return result;
}
{
if(pos==end)
{
- eof_flag=true;
+ eof_flag = true;
return -1;
}
{
char *new_pos;
if(type==S_BEG)
- new_pos=begin+off;
+ new_pos = begin+off;
else if(type==S_CUR)
- new_pos=pos+off;
+ new_pos = pos+off;
else if(type==S_END)
- new_pos=end+off;
+ new_pos = end+off;
else
throw InvalidParameterValue("Invalid seek type");
if(new_pos<begin || new_pos>end)
throw InvalidParameterValue("Invalid seek offset");
- pos=new_pos;
+ pos = new_pos;
return pos-begin;
}
{
check_mode(M_WRITE);
- size=min<unsigned>(size, end-pos);
+ size = min<unsigned>(size, end-pos);
memcpy(pos, buf, size);
- pos+=size;
+ pos += size;
return size;
}
{
if(pos==end)
{
- eof_flag=true;
+ eof_flag = true;
return 0;
}
- size=min<unsigned>(size, end-pos);
+ size = min<unsigned>(size, end-pos);
memcpy(buf, pos, size);
- pos+=size;
+ pos += size;
return size;
}
enum Mode
{
- M_NONE=0,
- M_READ=1,
- M_WRITE=2,
- M_RDWR=M_READ|M_WRITE,
- M_APPEND=4,
- M_NONBLOCK=8
+ M_NONE = 0,
+ M_READ = 1,
+ M_WRITE = 2,
+ M_RDWR = M_READ|M_WRITE,
+ M_APPEND = 4,
+ M_NONBLOCK = 8
};
inline Mode operator|(Mode m, Mode n)
Pipe::Pipe()
{
#ifdef WIN32
- string name=format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
- handle[0]=CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
+ string name = format("\\\\.\\pipe\\%u.%p", GetCurrentProcessId(), this);
+ handle[0] = CreateNamedPipe(name.c_str(), PIPE_ACCESS_INBOUND|FILE_FLAG_OVERLAPPED, PIPE_TYPE_BYTE, 1, 1024, 1024, 0, 0);
if(handle[0]==INVALID_HANDLE_VALUE)
throw SystemError("Unable to create pipe", GetLastError());
- handle[1]=CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
+ handle[1] = CreateFile(name.c_str(), GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
if(handle[1]==INVALID_HANDLE_VALUE)
{
- unsigned err=GetLastError();
+ unsigned err = GetLastError();
CloseHandle(handle[0]);
throw SystemError("Unable to create pipe", err);
}
- overlapped=0;
- event=CreateEvent(0, true, false, 0);
- buf_size=1024;
- buffer=new char[buf_size];
- buf_avail=0;
- buf_next=buffer;
+ overlapped = 0;
+ event = CreateEvent(0, true, false, 0);
+ buf_size = 1024;
+ buffer = new char[buf_size];
+ buf_avail = 0;
+ buf_next = buffer;
#else
if(pipe(handle)==-1)
throw SystemError("Unable to create pipe", errno);
void Pipe::set_block(bool b)
{
- mode=(mode&~M_NONBLOCK);
+ mode = (mode&~M_NONBLOCK);
if(b)
- mode=(mode|M_NONBLOCK);
+ mode = (mode|M_NONBLOCK);
#ifndef WIN32
- int flags=fcntl(handle[0], F_GETFD);
+ int flags = fcntl(handle[0], F_GETFD);
fcntl(handle[0], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
- flags=fcntl(handle[1], F_GETFD);
+ flags = fcntl(handle[1], F_GETFD);
fcntl(handle[1], F_SETFL, (flags&O_NONBLOCK)|(b?0:O_NONBLOCK));
#endif
}
#ifdef WIN32
if(!overlapped && !buf_avail)
{
- overlapped=new OVERLAPPED;
+ overlapped = new OVERLAPPED;
memset(overlapped, 0, sizeof(OVERLAPPED));
- overlapped->hEvent=event;
+ overlapped->hEvent = event;
DWORD ret;
- buf_next=buffer;
+ buf_next = buffer;
if(!ReadFile(handle[0], buffer, buf_size, &ret, overlapped))
{
- unsigned err=GetLastError();
+ unsigned err = GetLastError();
if(err!=ERROR_IO_PENDING)
throw SystemError("Failed to start an overlapped read", err);
}
else
{
- buf_avail=ret;
+ buf_avail = ret;
delete overlapped;
- overlapped=0;
+ overlapped = 0;
SetEvent(event);
}
}
if(!WriteFile(handle[1], buf, size, &ret, 0))
throw SystemError("Writing to pipe failed", GetLastError());
#else
- int ret=::write(handle[1], buf, size);
+ int ret = ::write(handle[1], buf, size);
if(ret==-1)
{
if(errno==EAGAIN)
throw SystemError("Reading from pipe failed", GetLastError());
else
{
- buf_avail+=ret;
+ buf_avail += ret;
delete overlapped;
- overlapped=0;
+ overlapped = 0;
}
}
- unsigned ret=min(buf_avail, size);
+ unsigned ret = min(buf_avail, size);
memcpy(buf, buf_next, ret);
- buf_next+=ret;
- buf_avail-=ret;
+ buf_next += ret;
+ buf_avail -= ret;
// Initiate another overlapped read in case someone is polling us
get_event_handle();
#else
- int ret=::read(handle[0], buf, size);
+ int ret = ::read(handle[0], buf, size);
if(ret==-1)
{
if(errno==EAGAIN)
if(ret==0)
{
- eof_flag=true;
+ eof_flag = true;
signal_end_of_file.emit();
}
inline int sys_poll_event(PollEvent event)
{
- int result=0;
+ int result = 0;
if(event&~(P_INPUT|P_PRIO|P_OUTPUT))
throw InvalidParameterValue("Invalid poll events");
#ifndef WIN32
if(event&P_INPUT)
- result|=POLLIN;
+ result |= POLLIN;
if(event&P_PRIO)
- result|=POLLPRI;
+ result |= POLLPRI;
if(event&P_OUTPUT)
- result|=POLLOUT;
+ result |= POLLOUT;
#endif
return result;
inline PollEvent poll_event_from_sys(int event)
{
- PollEvent result=P_NONE;
+ PollEvent result = P_NONE;
#ifdef WIN32
// Stop the compiler from complaining about unused parameter
- event=event;
+ event = event;
#else
if(event&POLLIN)
- result=result|P_INPUT;
+ result = result|P_INPUT;
if(event&POLLPRI)
- result=result|P_PRIO;
+ result = result|P_PRIO;
if(event&POLLOUT)
- result=result|P_OUTPUT;
+ result = result|P_OUTPUT;
if(event&POLLERR)
- result=result|P_ERROR;
+ result = result|P_ERROR;
#endif
return result;
{
#ifdef WIN32
if(timeout<0)
- timeout=INFINITE;
+ timeout = INFINITE;
- DWORD ret=WaitForSingleObject(obj.get_event_handle(), timeout);
+ DWORD ret = WaitForSingleObject(obj.get_event_handle(), timeout);
if(ret==WAIT_OBJECT_0)
return pe;
else if(ret==WAIT_FAILED)
return P_NONE;
#else
- pollfd pfd={obj.get_event_handle(), sys_poll_event(pe), 0};
+ pollfd pfd = {obj.get_event_handle(), sys_poll_event(pe), 0};
- int ret=::poll(&pfd, 1, timeout);
+ int ret = ::poll(&pfd, 1, timeout);
if(ret==-1)
{
if(errno==EINTR)
if(ev)
obj.get_event_handle();
- SlotMap::iterator i=objects.find(&obj);
+ SlotMap::iterator i = objects.find(&obj);
if(i!=objects.end())
{
if(ev)
- i->second.events=ev;
+ i->second.events = ev;
else
objects.erase(i);
- pfd_dirty=true;
+ pfd_dirty = true;
}
else if(ev)
{
#endif
objects.insert(SlotMap::value_type(&obj, Slot(&obj, ev)));
- pfd_dirty=true;
+ pfd_dirty = true;
}
}
for(SlotMap::iterator i=objects.begin(); i!=objects.end(); ++i)
{
- p.fd=i->second.object->get_event_handle();
+ p.fd = i->second.object->get_event_handle();
#ifndef WIN32
- p.events=sys_poll_event(i->second.events);
+ p.events = sys_poll_event(i->second.events);
#endif
pfd.push_back(p);
}
- pfd_dirty=false;
+ pfd_dirty = false;
}
int Poller::do_poll(int timeout)
#ifdef WIN32
if(timeout<0)
- timeout=INFINITE;
+ timeout = INFINITE;
- DWORD ret=WaitForMultipleObjects(pfd.size(), &pfd.front().fd, false, timeout);
+ DWORD ret = WaitForMultipleObjects(pfd.size(), &pfd.front().fd, false, timeout);
if(/*ret>=WAIT_OBJECT_0 &&*/ ret<WAIT_OBJECT_0+pfd.size())
{
- SlotMap::iterator i=objects.begin();
+ SlotMap::iterator i = objects.begin();
advance(i, ret-WAIT_OBJECT_0);
poll_result.push_back(Slot(i->second.object, i->second.events));
return 0;
#else
- int ret=::poll(&pfd.front(), pfd.size(), timeout);
+ int ret = ::poll(&pfd.front(), pfd.size(), timeout);
if(ret==-1)
{
if(errno==EINTR)
throw SystemError("Poll failed", errno);
}
- int n=ret;
- SlotMap::iterator j=objects.begin();
+ int n = ret;
+ SlotMap::iterator j = objects.begin();
for(std::vector<pollfd>::iterator i=pfd.begin(); (i!=pfd.end() && n>0); ++i,++j)
if(i->revents)
{
enum PollEvent
{
- P_NONE=0,
- P_INPUT=1,
- P_PRIO=2,
- P_OUTPUT=4,
- P_ERROR=8
+ P_NONE = 0,
+ P_INPUT = 1,
+ P_PRIO = 2,
+ P_OUTPUT = 4,
+ P_ERROR = 8
};
inline PollEvent operator|(PollEvent e, PollEvent f)
unsigned read_all(Base &obj, char *buf, unsigned size)
{
- unsigned pos=0;
+ unsigned pos = 0;
while(pos<size)
- pos+=obj.read(buf+pos, size-pos);
+ pos += obj.read(buf+pos, size-pos);
return pos;
}