git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@981 77e5149b-7576-45b1-b177-96237e5ba77b
Tomasz Kojm authored on 2004/10/09 01:03:06... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Fri Oct 8 17:53:30 CEST 2004 (tk) |
|
2 |
+---------------------------------- |
|
3 |
+ * clamd/others.c: improve poll code in is_fd_connected() (Trog) |
|
4 |
+ |
|
1 | 5 |
Thu Oct 7 16:37:04 BST 2004 (njh) |
2 | 6 |
---------------------------------- |
3 | 7 |
* clamav-milter: Requirement for ScanMail removed since that is no |
... | ... |
@@ -31,6 +31,7 @@ |
31 | 31 |
#include <errno.h> |
32 | 32 |
#include <sys/time.h> |
33 | 33 |
#include <sys/socket.h> |
34 |
+#include <sys/ioctl.h> |
|
34 | 35 |
#if HAVE_SYS_TYPES_H |
35 | 36 |
#include <sys/types.h> |
36 | 37 |
#endif |
... | ... |
@@ -138,20 +139,31 @@ int poll_fd(int fd, int timeout_sec) |
138 | 138 |
|
139 | 139 |
int is_fd_connected(int fd) |
140 | 140 |
{ |
141 |
-#undef HAVE_POLL /* temporarily disabled */ |
|
142 | 141 |
#ifdef HAVE_POLL |
143 | 142 |
struct pollfd poll_data[1]; |
143 |
+ int count; |
|
144 | 144 |
|
145 | 145 |
poll_data[0].fd = fd; |
146 | 146 |
poll_data[0].events = POLLIN; |
147 | 147 |
poll_data[0].revents = 0; |
148 | 148 |
|
149 |
- if (poll(poll_data, 1, 0) == -1) { |
|
149 |
+ if ((count=poll(poll_data, 1, 0)) == -1) { |
|
150 |
+ if (errno == EINTR) { |
|
151 |
+ return 1; |
|
152 |
+ } |
|
150 | 153 |
return 0; |
151 | 154 |
} |
155 |
+ if (count == 0) { |
|
156 |
+ return 1; |
|
157 |
+ } |
|
152 | 158 |
if (poll_data[0].revents & POLLHUP) { |
153 | 159 |
return 0; |
154 | 160 |
} |
161 |
+ if ((poll_data[0].revents & POLLIN) && (ioctl(fd, FIONREAD, &count) == 0)) { |
|
162 |
+ if (count == 0) { |
|
163 |
+ return 0; |
|
164 |
+ } |
|
165 |
+ } |
|
155 | 166 |
return 1; |
156 | 167 |
|
157 | 168 |
#else |