ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev_select.c
(Generate patch)

Comparing libev/ev_select.c (file contents):
Revision 1.13 by root, Sun Nov 4 23:14:11 2007 UTC vs.
Revision 1.14 by root, Tue Nov 6 00:10:04 2007 UTC

53 53
54 if (vec_max < (fd >> 5) + 1) 54 if (vec_max < (fd >> 5) + 1)
55 { 55 {
56 int new_max = (fd >> 5) + 1; 56 int new_max = (fd >> 5) + 1;
57 57
58 vec_ri = (unsigned char *)realloc (vec_ri, new_max * 4); 58 vec_ri = (unsigned char *)ev_realloc (vec_ri, new_max * 4);
59 vec_ro = (unsigned char *)realloc (vec_ro, new_max * 4); /* could free/malloc */ 59 vec_ro = (unsigned char *)ev_realloc (vec_ro, new_max * 4); /* could free/malloc */
60 vec_wi = (unsigned char *)realloc (vec_wi, new_max * 4); 60 vec_wi = (unsigned char *)ev_realloc (vec_wi, new_max * 4);
61 vec_wo = (unsigned char *)realloc (vec_wo, new_max * 4); /* could free/malloc */ 61 vec_wo = (unsigned char *)ev_realloc (vec_wo, new_max * 4); /* could free/malloc */
62 62
63 for (; vec_max < new_max; ++vec_max) 63 for (; vec_max < new_max; ++vec_max)
64 ((uint32_t *)vec_ri)[vec_max] = 64 ((uint32_t *)vec_ri)[vec_max] =
65 ((uint32_t *)vec_wi)[vec_max] = 0; 65 ((uint32_t *)vec_wi)[vec_max] = 0;
66 } 66 }
75} 75}
76 76
77static void 77static void
78select_poll (EV_P_ ev_tstamp timeout) 78select_poll (EV_P_ ev_tstamp timeout)
79{ 79{
80 int word, offs;
80 struct timeval tv; 81 struct timeval tv;
81 int res; 82 int res;
82 83
83 memcpy (vec_ro, vec_ri, vec_max * 4); 84 memcpy (vec_ro, vec_ri, vec_max * 4);
84 memcpy (vec_wo, vec_wi, vec_max * 4); 85 memcpy (vec_wo, vec_wi, vec_max * 4);
86 tv.tv_sec = (long)timeout; 87 tv.tv_sec = (long)timeout;
87 tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6); 88 tv.tv_usec = (long)((timeout - (ev_tstamp)tv.tv_sec) * 1e6);
88 89
89 res = select (vec_max * 32, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv); 90 res = select (vec_max * 32, (fd_set *)vec_ro, (fd_set *)vec_wo, 0, &tv);
90 91
91 if (res > 0) 92 if (res < 0)
92 {
93 int word, offs;
94
95 for (word = vec_max; word--; )
96 {
97 if (((uint32_t *)vec_ro) [word] | ((uint32_t *)vec_wo) [word])
98 for (offs = 4; offs--; )
99 {
100 int idx = word * 4 + offs;
101 unsigned char byte_r = vec_ro [idx];
102 unsigned char byte_w = vec_wo [idx];
103 int bit;
104
105 if (byte_r | byte_w)
106 for (bit = 8; bit--; )
107 {
108 int events = 0;
109 events |= byte_r & (1 << bit) ? EV_READ : 0;
110 events |= byte_w & (1 << bit) ? EV_WRITE : 0;
111
112 if (events)
113 fd_event (EV_A_ idx * 8 + bit, events);
114 }
115 }
116 }
117 }
118 else if (res < 0)
119 { 93 {
120 if (errno == EBADF) 94 if (errno == EBADF)
121 fd_ebadf (EV_A); 95 fd_ebadf (EV_A);
122 else if (errno == ENOMEM) 96 else if (errno == ENOMEM && !syserr_cb)
123 fd_enomem (EV_A); 97 fd_enomem (EV_A);
98 else if (errno != EINTR)
99 syserr ();
100
101 return;
102 }
103
104 for (word = vec_max; word--; )
105 {
106 if (((uint32_t *)vec_ro) [word] | ((uint32_t *)vec_wo) [word])
107 for (offs = 4; offs--; )
108 {
109 int idx = word * 4 + offs;
110 unsigned char byte_r = vec_ro [idx];
111 unsigned char byte_w = vec_wo [idx];
112 int bit;
113
114 if (byte_r | byte_w)
115 for (bit = 8; bit--; )
116 {
117 int events = 0;
118 events |= byte_r & (1 << bit) ? EV_READ : 0;
119 events |= byte_w & (1 << bit) ? EV_WRITE : 0;
120
121 if (events)
122 fd_event (EV_A_ idx * 8 + bit, events);
123 }
124 }
124 } 125 }
125} 126}
126 127
127static int 128static int
128select_init (EV_P_ int flags) 129select_init (EV_P_ int flags)
141} 142}
142 143
143static void 144static void
144select_destroy (EV_P) 145select_destroy (EV_P)
145{ 146{
146 free (vec_ri); 147 ev_free (vec_ri);
147 free (vec_ro); 148 ev_free (vec_ro);
148 free (vec_wi); 149 ev_free (vec_wi);
149 free (vec_wo); 150 ev_free (vec_wo);
150} 151}
151 152
152 153

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines