* @brief This function will get the pipe status. * * @param fd is the file descriptor. * * @param req is the request type. * * @return mask of the pipe status. * POLLIN means there is data to be read. * POLLHUP means there is no thread that occupied the pipe to open for writing. * POLLOUT means there is space to be written. * POLLERR mea
| 355 | * POLLERR means there is no thread that occupied the pipe to open for reading. |
| 356 | */ |
| 357 | static int pipe_fops_poll(struct dfs_file *fd, rt_pollreq_t *req) |
| 358 | { |
| 359 | int mask = 0; |
| 360 | rt_pipe_t *pipe; |
| 361 | int mode = 0; |
| 362 | pipe = (rt_pipe_t *)fd->vnode->data; |
| 363 | |
| 364 | rt_poll_add(&pipe->reader_queue, req); |
| 365 | rt_poll_add(&pipe->writer_queue, req); |
| 366 | |
| 367 | switch (fd->flags & O_ACCMODE) |
| 368 | { |
| 369 | case O_RDONLY: |
| 370 | mode = 1; |
| 371 | break; |
| 372 | case O_WRONLY: |
| 373 | mode = 2; |
| 374 | break; |
| 375 | case O_RDWR: |
| 376 | mode = 3; |
| 377 | break; |
| 378 | } |
| 379 | |
| 380 | if (mode & 1) |
| 381 | { |
| 382 | if (rt_ringbuffer_data_len(pipe->fifo) != 0) |
| 383 | { |
| 384 | mask |= POLLIN; |
| 385 | } |
| 386 | else if (pipe->writer == 0) |
| 387 | { |
| 388 | mask = POLLHUP; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | if (mode & 2) |
| 393 | { |
| 394 | if (rt_ringbuffer_space_len(pipe->fifo) != 0) |
| 395 | { |
| 396 | mask |= POLLOUT; |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | return mask; |
| 401 | } |
| 402 | |
| 403 | static const struct dfs_file_ops pipe_fops = |
| 404 | { |
nothing calls this directly
no test coverage detected