annotate libfaim/aim_conn.c @ 2:68b230f8da5f

[gaim-migrate @ 11] A few more commits :) committer: Tailor Script <tailor@pidgin.im>
author Rob Flynn <gaim@robflynn.com>
date Thu, 23 Mar 2000 03:16:06 +0000
parents
children 6ced2f1c8b24
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
1
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
2 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
3 * aim_conn.c
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
4 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
5 * Does all this gloriously nifty connection handling stuff...
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
6 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
7 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
8
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
9 #include "aim.h"
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
10
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
11 void aim_connrst(void)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
12 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
13 int i;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
14 for (i = 0; i < AIM_CONN_MAX; i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
15 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
16 aim_conns[i].fd = -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
17 aim_conns[i].type = -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
18 aim_conns[i].status = 0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
19 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
20
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
21 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
22
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
23 struct aim_conn_t *aim_conn_getnext(void)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
24 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
25 int i;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
26 for (i=0;i<AIM_CONN_MAX;i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
27 if (aim_conns[i].fd == -1)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
28 return &(aim_conns[i]);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
29 return NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
30 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
31
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
32 void aim_conn_close(struct aim_conn_t *deadconn)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
33 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
34 if (deadconn->fd >= 3)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
35 close(deadconn->fd);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
36 deadconn->fd = -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
37 deadconn->type = -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
38 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
39
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
40 struct aim_conn_t *aim_getconn_type(int type)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
41 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
42 int i;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
43 for (i=0; i<AIM_CONN_MAX; i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
44 if (aim_conns[i].type == type)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
45 return &(aim_conns[i]);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
46 return NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
47 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
48
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
49 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
50 * aim_newconn(type, dest)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
51 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
52 * Opens a new connection to the specified dest host of type type.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
53 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
54 * TODO: fix for proxies
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
55 * FIXME: Return errors in a more sane way.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
56 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
57 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
58 struct aim_conn_t *aim_newconn(int type, char *dest)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
59 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
60 struct aim_conn_t *connstruct;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
61 int ret;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
62 struct sockaddr_in sa;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
63 struct hostent *hp;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
64 int port = FAIM_LOGIN_PORT;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
65 int i=0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
66
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
67 if (!dest || ((connstruct=aim_conn_getnext())==NULL))
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
68 return NULL;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
69
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
70 connstruct->type = type;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
71
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
72 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
73 * As of 23 Jul 1999, AOL now sends the port number, preceded by a
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
74 * colon, in the BOS redirect. This fatally breaks all previous
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
75 * libfaims. Bad, bad AOL.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
76 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
77 * We put this here to catch every case.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
78 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
79 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
80 for(i=0;(i<strlen(dest));i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
81 if (dest[i] == ':') break;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
82 if (i<strlen(dest))
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
83 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
84 port = atoi(dest+i);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
85 dest[i] = '\0';
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
86 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
87
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
88 hp = gethostbyname2(dest, AF_INET);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
89 if (hp == NULL)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
90 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
91 connstruct->status = (h_errno | AIM_CONN_STATUS_RESOLVERR);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
92 return connstruct;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
93 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
94
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
95 memset(&sa.sin_zero, 0, 8);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
96 sa.sin_port = htons(port);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
97 memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
98 sa.sin_family = hp->h_addrtype;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
99
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
100 connstruct->fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
101 ret = connect(connstruct->fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
102 if( ret < 0)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
103 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
104 connstruct->fd = -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
105 connstruct->status = (errno | AIM_CONN_STATUS_CONNERR);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
106 return connstruct;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
107 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
108
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
109 return connstruct;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
110 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
111
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
112 int aim_conngetmaxfd(void)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
113 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
114 int i,j;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
115 j=0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
116 for (i=0;i<AIM_CONN_MAX;i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
117 if(aim_conns[i].fd > j)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
118 j = aim_conns[i].fd;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
119 return j;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
120 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
121
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
122 int aim_countconn(void)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
123 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
124 int i,cnt;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
125 cnt = 0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
126 for (i=0;i<AIM_CONN_MAX;i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
127 if (aim_conns[i].fd > -1)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
128 cnt++;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
129 return cnt;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
130 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
131
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
132 /*
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
133 * aim_select(timeout)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
134 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
135 * Waits for a socket with data or for timeout, whichever comes first.
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
136 * See select(2).
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
137 *
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
138 */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
139 struct aim_conn_t *aim_select(struct timeval *timeout)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
140 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
141 fd_set fds;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
142 fd_set errfds;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
143 int i;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
144
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
145 if (aim_countconn() <= 0)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
146 return 0;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
147
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
148 FD_ZERO(&fds);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
149 FD_ZERO(&errfds);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
150
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
151 for(i=0;i<AIM_CONN_MAX;i++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
152 if (aim_conns[i].fd>-1)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
153 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
154 FD_SET(aim_conns[i].fd, &fds);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
155 FD_SET(aim_conns[i].fd, &errfds);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
156 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
157
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
158 i = select(aim_conngetmaxfd()+1, &fds, NULL, &errfds, timeout);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
159 if (i>=1)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
160 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
161 int j;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
162 for (j=0;j<AIM_CONN_MAX;j++)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
163 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
164 if ((FD_ISSET(aim_conns[j].fd, &errfds)))
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
165 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
166 /* got an exception; close whats left of it up */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
167 aim_conn_close(&(aim_conns[j]));
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
168 return (struct aim_conn_t *)-1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
169 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
170 else if ((FD_ISSET(aim_conns[j].fd, &fds)))
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
171 return &(aim_conns[j]); /* return the first waiting struct */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
172 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
173 /* should never get here */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
174 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
175 else
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
176 return (struct aim_conn_t *)i; /* no waiting or error, return -- FIXME: return type funnies */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
177 return NULL; /* NO REACH */
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
178 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
179
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
180 int aim_conn_isready(struct aim_conn_t *conn)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
181 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
182 if (conn)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
183 return (conn->status & 0x0001);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
184 else
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
185 return -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
186 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
187
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
188 int aim_conn_setstatus(struct aim_conn_t *conn, int status)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
189 {
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
190 if (conn)
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
191 return (conn->status ^= status);
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
192 else
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
193 return -1;
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
194 }
68b230f8da5f [gaim-migrate @ 11]
Rob Flynn <gaim@robflynn.com>
parents:
diff changeset
195