PTY: Add support for the poll() method.

This commit is contained in:
Gregory Nutt 2016-07-15 10:07:33 -06:00
parent 95555a0199
commit 4d1b811117

@ -504,10 +504,69 @@ static int pty_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
****************************************************************************/
#ifndef CONFIG_DISABLE_POLL
/* REVISIT: There is a file_poll() function, but it does not work in this
* context so the logic is implemented locally as my_file_poll().
*/
static my_file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup)
{
FAR struct inode *inode;
int ret = -ENOSYS;
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
inode = filep->f_inode;
/* Is a driver registered? Does it support the poll method?
* If not, return -ENOSYS
*/
if (inode != NULL && inode->u.i_ops != NULL && inode->u.i_ops->poll != NULL)
{
/* Yes, then setup the poll */
ret = (int)inode->u.i_ops->poll(filep, fds, setup);
}
return ret;
}
static int pty_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup)
{
#warning Missing logic
FAR struct inode *inode;
FAR struct pty_dev_s *dev;
int ret = -ENOSYS;
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
inode = filep->f_inode;
dev = inode->i_private;
/* REVISIT: If both POLLIN and POLLOUT are set, might the following logic
* fail? Could we not get POLLIN on the sink file and POLLOUT on the source
* file?
*
* REVISIT: There is a file_poll() function, but it does not work in this
* context so the logic is implemented locally as my_file_poll().
*/
/* POLLIN: Data other than high-priority data may be read without blocking. */
if ((fds->events & POLLIN) != 0)
{
ret = my_file_poll(dev->pd_src, fds, setup);
}
if (ret >= OK || ret == -ENOTTY)
{
/* POLLOUT: Normal data may be written without blocking. */
if ((fds->events & POLLOUT) != 0)
{
ret = my_file_poll(dev->pd_sink, fds, setup);
}
}
return ret;
}
#endif