Structured comments updated.
[lincan.git] / lincan / src / select.c
1 /* select.c
2  * Header file for the Linux CAN-bus driver.
3  * Written by Arnaud Westenberg email:arnaud@wanadoo.nl
4  * Added by Pavel Pisa - OCERA team member
5  * email:pisa@cmp.felk.cvut.cz
6  * This software is released under the GPL-License.
7  * Version lincan-0.2  9 Jul 2003
8  */
9
10 #include "../include/can.h"
11 #include "../include/can_sysdep.h"
12 #include "../include/main.h"
13
14 #include <linux/poll.h>
15 #include "../include/select.h"
16
17 unsigned int can_poll(struct file *file, poll_table *wait)
18 {
19         struct canuser_t *canuser = (struct canuser_t*)(file->private_data);
20         struct canque_ends_t *qends;
21         struct msgobj_t *obj;
22         unsigned int mask = 0;
23         struct canque_edge_t *edge;
24         int full=0;
25         int i;
26
27         if(!canuser || (canuser->magic != CAN_USER_MAGIC)){
28                 CANMSG("can_close: bad canuser magic\n");
29                 return -ENODEV;
30         }
31         
32         obj = canuser->msgobj;
33         qends = canuser->qends;
34
35         if (file->f_mode & FMODE_READ) {
36                 poll_wait(file, &qends->endinfo.fileinfo.readq, wait);
37                 for(i=CANQUEUE_PRIO_NR;--i>=0;) {
38                         if(!list_empty(&qends->active[i]))
39                                 mask |= POLLIN | POLLRDNORM;
40                 }
41         }
42
43         if ((file->f_mode & FMODE_WRITE) && !(file->f_flags & O_SYNC)) {
44                 poll_wait(file, &qends->endinfo.fileinfo.writeq, wait);
45
46                 canque_for_each_inedge(qends, edge) {
47                         if(canque_fifo_test_fl(&edge->fifo,FULL))
48                                 full=1;
49                 }
50
51                 if(!full)
52                         mask |= POLLOUT | POLLWRNORM;
53         }
54
55         if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_SYNC)) {
56                 poll_wait(file, &qends->endinfo.fileinfo.emptyq, wait);
57
58                 canque_for_each_inedge(qends, edge) {
59                         if(!canque_fifo_test_fl(&edge->fifo,EMPTY))
60                                 full=1;
61                 }
62
63                 if(!full)
64                         mask |= POLLOUT | POLLWRNORM;
65         }
66         return mask;
67 }