| 5 * (incoming packet) queue. The actual packet handlers are in |
5 * (incoming packet) queue. The actual packet handlers are in |
| 6 * aim_rxhandlers.c. |
6 * aim_rxhandlers.c. |
| 7 */ |
7 */ |
| 8 |
8 |
| 9 #include <faim/aim.h> |
9 #include <faim/aim.h> |
| |
10 |
| |
11 #ifndef _WIN32 |
| 10 #include <sys/socket.h> |
12 #include <sys/socket.h> |
| |
13 #endif |
| 11 |
14 |
| 12 /* |
15 /* |
| 13 * Since not all implementations support MSG_WAITALL, define |
16 * Since not all implementations support MSG_WAITALL, define |
| 14 * an alternate guarenteed read function... |
17 * an alternate guarenteed read function... |
| 15 * |
18 * |
| 16 * We keep recv() for systems that can do it because it means |
19 * We keep recv() for systems that can do it because it means |
| 17 * a single system call for the entire packet, where read may |
20 * a single system call for the entire packet, where read may |
| 18 * take more for a badly fragmented packet. |
21 * take more for a badly fragmented packet. |
| 19 * |
22 * |
| 20 */ |
23 */ |
| 21 static int aim_recv(int fd, void *buf, size_t count) |
24 faim_internal int aim_recv(int fd, void *buf, size_t count) |
| 22 { |
25 { |
| 23 #ifdef MSG_WAITALL |
26 #ifdef MSG_WAITALL |
| 24 return recv(fd, buf, count, MSG_WAITALL); |
27 return recv(fd, buf, count, MSG_WAITALL); |
| 25 #else |
28 #else |
| 26 int left, ret, cur = 0; |
29 int left, ret, cur = 0; |
| 27 |
30 |
| 28 left = count; |
31 left = count; |
| 29 |
32 |
| 30 while (left) { |
33 while (left) { |
| 31 ret = read(fd, ((unsigned char *)buf)+cur, left); |
34 ret = recv(fd, ((unsigned char *)buf)+cur, left, 0); |
| 32 if (ret == -1) |
35 if (ret == -1) |
| 33 return -1; |
36 return -1; |
| 34 if (ret == 0) |
37 if (ret == 0) |
| 35 return cur; |
38 return cur; |
| 36 |
39 |