comparison libfaim/aim_rxqueue.c @ 840:595ac7759563

[gaim-migrate @ 850] lots of (mostly useless for us) libfaim changes. should help portability, but it was always portable between unices.... stupid win32ers. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Mon, 04 Sep 2000 23:37:32 +0000
parents 88f8f98de02d
children e1da6a6ec42b
comparison
equal deleted inserted replaced
839:8f66e00af045 840:595ac7759563
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 #include <sys/socket.h>
11
12 /*
13 * Since not all implementations support MSG_WAITALL, define
14 * an alternate guarenteed read function...
15 *
16 * We keep recv() for systems that can do it because it means
17 * a single system call for the entire packet, where read may
18 * take more for a badly fragmented packet.
19 *
20 */
21 static int aim_recv(int fd, void *buf, size_t count)
22 {
23 #ifdef MSG_WAITALL
24 return recv(fd, buf, count, MSG_WAITALL);
25 #else
26 int left, ret, cur = 0;
27
28 left = count;
29
30 while (left) {
31 ret = read(fd, ((unsigned char *)buf)+cur, left);
32 if (ret == -1)
33 return -1;
34 if (ret == 0)
35 return cur;
36
37 cur += ret;
38 left -= ret;
39 }
40
41 return cur;
42 #endif
43 }
10 44
11 /* 45 /*
12 * Grab a single command sequence off the socket, and enqueue 46 * Grab a single command sequence off the socket, and enqueue
13 * it in the incoming event queue in a seperate struct. 47 * it in the incoming event queue in a seperate struct.
14 */ 48 */
15 int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *conn) 49 faim_export int aim_get_command(struct aim_session_t *sess, struct aim_conn_t *conn)
16 { 50 {
17 unsigned char generic[6]; 51 unsigned char generic[6];
18 struct command_rx_struct *newrx = NULL; 52 struct command_rx_struct *newrx = NULL;
19 53
20 if (!sess || !conn) 54 if (!sess || !conn)
39 * 1 char -- Channel ID. Usually 2 -- 1 and 4 are used during login. 73 * 1 char -- Channel ID. Usually 2 -- 1 and 4 are used during login.
40 * 2 short -- Sequence number 74 * 2 short -- Sequence number
41 * 4 short -- Number of data bytes that follow. 75 * 4 short -- Number of data bytes that follow.
42 */ 76 */
43 faim_mutex_lock(&conn->active); 77 faim_mutex_lock(&conn->active);
44 if (recv(conn->fd, generic, 6, MSG_WAITALL) < 6){ 78 if (aim_recv(conn->fd, generic, 6) < 6){
45 aim_conn_close(conn); 79 aim_conn_close(conn);
46 faim_mutex_unlock(&conn->active); 80 faim_mutex_unlock(&conn->active);
47 return -1; 81 return -1;
48 } 82 }
49 83
87 faim_mutex_unlock(&conn->active); 121 faim_mutex_unlock(&conn->active);
88 return -1; 122 return -1;
89 } 123 }
90 124
91 /* read the data portion of the packet */ 125 /* read the data portion of the packet */
92 if (recv(conn->fd, newrx->data, newrx->commandlen, MSG_WAITALL) < newrx->commandlen){ 126 if (aim_recv(conn->fd, newrx->data, newrx->commandlen) < newrx->commandlen){
93 free(newrx->data); 127 free(newrx->data);
94 free(newrx); 128 free(newrx);
95 aim_conn_close(conn); 129 aim_conn_close(conn);
96 faim_mutex_unlock(&conn->active); 130 faim_mutex_unlock(&conn->active);
97 return -1; 131 return -1;
134 * but will not be free'ed. The client _must_ keep a pointer to the 168 * but will not be free'ed. The client _must_ keep a pointer to the
135 * data -- libfaim will not! If the client marks ->nofree but 169 * data -- libfaim will not! If the client marks ->nofree but
136 * does not keep a pointer, it's lost forever. 170 * does not keep a pointer, it's lost forever.
137 * 171 *
138 */ 172 */
139 void aim_purge_rxqueue(struct aim_session_t *sess) 173 faim_export void aim_purge_rxqueue(struct aim_session_t *sess)
140 { 174 {
141 struct command_rx_struct *cur = NULL; 175 struct command_rx_struct *cur = NULL;
142 struct command_rx_struct *tmp; 176 struct command_rx_struct *tmp;
143 177
144 if (sess->queue_incoming == NULL) 178 if (sess->queue_incoming == NULL)
192 * to clean up the rxqueue of unprocessed connections on that socket. 226 * to clean up the rxqueue of unprocessed connections on that socket.
193 * 227 *
194 * XXX: this is something that was handled better in the old connection 228 * XXX: this is something that was handled better in the old connection
195 * handling method, but eh. 229 * handling method, but eh.
196 */ 230 */
197 void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn) 231 faim_internal void aim_rxqueue_cleanbyconn(struct aim_session_t *sess, struct aim_conn_t *conn)
198 { 232 {
199 struct command_rx_struct *currx; 233 struct command_rx_struct *currx;
200 234
201 for (currx = sess->queue_incoming; currx; currx = currx->next) { 235 for (currx = sess->queue_incoming; currx; currx = currx->next) {
202 if ((!currx->handled) && (currx->conn == conn)) 236 if ((!currx->handled) && (currx->conn == conn))