ssize_t read(int handle, void *out, size_t length) { FileDescriptor *descriptor = static_cast<FileDescriptor*>(GetResource(handle, OBJ_FD)); if (descriptor == 0) return E_BAD_HANDLE; ssize_t err = descriptor->Read(out, length); descriptor->ReleaseRef(); return err; }
bool TTYKeyboard::OnFileEvent(FileDescriptor fd, unsigned mask) { char buffer[256]; const ssize_t nbytes = fd.Read(buffer, sizeof(buffer)); if (nbytes > 0) { for (ssize_t i = 0; i < nbytes; ++i) HandleInputByte(buffer[i]); } else if (nbytes == 0 || errno != EAGAIN) { queue.Quit(); return false; } return true; }
bool LogCatReader::OnFileEvent(int _fd, unsigned mask) { assert(_fd == fd.Get()); char buffer[1024]; ssize_t nbytes = fd.Read(buffer, sizeof(buffer)); if (nbytes > 0) { if (data.length() < 1024 * 1024) data.append(buffer, nbytes); return true; } else { EndOfFile(); return false; } }