/[LeafOK_CVS]/pvpgn-1.7.4/src/bnproxy/virtconn.c
ViewVC logotype

Contents of /pvpgn-1.7.4/src/bnproxy/virtconn.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1.1.1 - (show annotations) (vendor branch)
Tue Jun 6 03:41:37 2006 UTC (19 years, 9 months ago) by sysadm
Branch: GNU, MAIN
CVS Tags: arelease, HEAD
Changes since 1.1: +0 -0 lines
Content type: text/x-csrc
Error occurred while calculating annotation data.
no message

1 /*
2 * Copyright (C) 1999 Ross Combs (rocombs@cs.nmsu.edu)
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18 #define VIRTCONN_INTERNAL_ACCESS
19 #include "common/setup_before.h"
20 #ifdef HAVE_STDDEF_H
21 # include <stddef.h>
22 #else
23 # ifndef NULL
24 # define NULL ((void *)0)
25 # endif
26 #endif
27 #ifdef STDC_HEADERS
28 # include <stdlib.h>
29 #else
30 # ifdef HAVE_MALLOC_H
31 # include <malloc.h>
32 # endif
33 #endif
34 #ifdef HAVE_UNISTD_H
35 # include <unistd.h>
36 #endif
37 #include "compat/socket.h"
38 #include "compat/psock.h"
39 #include "common/queue.h"
40 #include "common/list.h"
41 #include "common/eventlog.h"
42 #include "virtconn.h"
43 #include "common/setup_after.h"
44
45
46 static t_list * virtconn_head=NULL;
47
48
49 extern t_virtconn * virtconn_create(int csd, int ssd, unsigned int udpaddr, unsigned short udpport)
50 {
51 t_virtconn * temp=NULL;
52
53 if (csd<0)
54 {
55 eventlog(eventlog_level_error,__FUNCTION__,"got bad client socket");
56 return NULL;
57 }
58 if (ssd<0)
59 {
60 eventlog(eventlog_level_error,__FUNCTION__,"got bad server socket");
61 return NULL;
62 }
63
64 if (!(temp = malloc(sizeof(t_virtconn))))
65 {
66 eventlog(eventlog_level_error,__FUNCTION__,"could not allocate memory for temp");
67 return NULL;
68 }
69
70 temp->csd = csd;
71 temp->ssd = ssd;
72 temp->udpport = udpport;
73 temp->udpaddr = udpaddr;
74 temp->class = virtconn_class_none;
75 temp->state = virtconn_state_initial;
76 temp->coutqueue = NULL;
77 temp->coutsize = 0;
78 temp->cinqueue = NULL;
79 temp->cinsize = 0;
80 temp->soutqueue = NULL;
81 temp->soutsize = 0;
82 temp->sinqueue = NULL;
83 temp->sinsize = 0;
84 temp->fileleft = 0;
85
86 if (list_prepend_data(virtconn_head,temp)<0)
87 {
88 free(temp);
89 eventlog(eventlog_level_error,__FUNCTION__,"could not prepend temp");
90 return NULL;
91 }
92
93 return temp;
94 }
95
96
97 extern void virtconn_destroy(t_virtconn * vc)
98 {
99 t_elem * curr;
100
101 if (!vc)
102 {
103 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
104 return;
105 }
106 if (list_remove_data(virtconn_head,vc, &curr)<0)
107 eventlog(eventlog_level_error,__FUNCTION__,"could not remove item from list");
108
109 vc->state = virtconn_state_empty;
110
111 psock_close(vc->ssd);
112 psock_close(vc->csd);
113
114 /* clear out the packet queues */
115 queue_clear(&vc->sinqueue);
116 queue_clear(&vc->soutqueue);
117 queue_clear(&vc->cinqueue);
118 queue_clear(&vc->coutqueue);
119
120 eventlog(eventlog_level_info,__FUNCTION__,"[%d] closed server connection (%d) class=%d",vc->ssd,vc->csd,(int)vc->class);
121 eventlog(eventlog_level_info,__FUNCTION__,"[%d] closed client connection (%d) class=%d",vc->csd,vc->ssd,(int)vc->class);
122
123 free(vc);
124 }
125
126
127 extern t_virtconn_class virtconn_get_class(t_virtconn const * vc)
128 {
129 if (!vc)
130 {
131 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
132 return virtconn_class_none;
133 }
134
135 return vc->class;
136 }
137
138
139 extern void virtconn_set_class(t_virtconn * vc, t_virtconn_class class)
140 {
141 if (!vc)
142 {
143 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
144 return;
145 }
146
147 vc->class = class;
148 }
149
150
151 extern t_virtconn_state virtconn_get_state(t_virtconn const * vc)
152 {
153 if (!vc)
154 {
155 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
156 return virtconn_state_empty;
157 }
158
159 return vc->state;
160 }
161
162
163 extern void virtconn_set_state(t_virtconn * vc, t_virtconn_state state)
164 {
165 if (!vc)
166 {
167 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
168 return;
169 }
170
171 vc->state = state;
172 }
173
174
175 extern unsigned int virtconn_get_udpaddr(t_virtconn const * vc)
176 {
177 if (!vc)
178 {
179 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
180 return 0;
181 }
182
183 return vc->udpaddr;
184 }
185
186
187 extern unsigned short virtconn_get_udpport(t_virtconn const * vc)
188 {
189 if (!vc)
190 {
191 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
192 return 0;
193 }
194
195 return vc->udpport;
196 }
197
198
199 extern t_queue * * virtconn_get_clientin_queue(t_virtconn * vc)
200 {
201 if (!vc)
202 {
203 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
204 return NULL;
205 }
206
207 return &vc->cinqueue;
208 }
209
210
211 extern int virtconn_get_clientin_size(t_virtconn const * vc)
212 {
213 if (!vc)
214 {
215 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
216 return -1;
217 }
218
219 return vc->cinsize;
220 }
221
222
223 extern void virtconn_set_clientin_size(t_virtconn * vc, unsigned int size)
224 {
225 if (!vc)
226 {
227 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
228 return;
229 }
230
231 vc->cinsize = size;
232 }
233
234
235 extern t_queue * * virtconn_get_clientout_queue(t_virtconn * vc)
236 {
237 if (!vc)
238 {
239 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
240 return NULL;
241 }
242
243 return &vc->coutqueue;
244 }
245
246
247 extern int virtconn_get_clientout_size(t_virtconn const * vc)
248 {
249 if (!vc)
250 {
251 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
252 return -1;
253 }
254
255 return vc->coutsize;
256 }
257
258
259 extern void virtconn_set_clientout_size(t_virtconn * vc, unsigned int size)
260 {
261 if (!vc)
262 {
263 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
264 return;
265 }
266
267 vc->coutsize = size;
268 }
269
270
271 extern int virtconn_get_client_socket(t_virtconn const * vc)
272 {
273 if (!vc)
274 {
275 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
276 return -1;
277 }
278 return vc->csd;
279 }
280
281
282 extern t_queue * * virtconn_get_serverin_queue(t_virtconn * vc)
283 {
284 if (!vc)
285 {
286 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
287 return NULL;
288 }
289
290 return &vc->sinqueue;
291 }
292
293
294 extern int virtconn_get_serverin_size(t_virtconn const * vc)
295 {
296 if (!vc)
297 {
298 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
299 return -1;
300 }
301
302 return vc->sinsize;
303 }
304
305
306 extern void virtconn_set_serverin_size(t_virtconn * vc, unsigned int size)
307 {
308 if (!vc)
309 {
310 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
311 return;
312 }
313
314 vc->sinsize = size;
315 }
316
317
318 extern t_queue * * virtconn_get_serverout_queue(t_virtconn * vc)
319 {
320 if (!vc)
321 {
322 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
323 return NULL;
324 }
325
326 return &vc->soutqueue;
327 }
328
329
330 extern int virtconn_get_serverout_size(t_virtconn const * vc)
331 {
332 if (!vc)
333 {
334 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
335 return -1;
336 }
337
338 return vc->soutsize;
339 }
340
341
342 extern void virtconn_set_serverout_size(t_virtconn * vc, unsigned int size)
343 {
344 if (!vc)
345 {
346 eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection");
347 return;
348 }
349
350 vc->soutsize = size;
351 }
352
353
354 extern int virtconn_get_server_socket(t_virtconn const * vc)
355 {
356 if (!vc)
357 {
358 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
359 return -1;
360 }
361 return vc->ssd;
362 }
363
364
365 extern void virtconn_set_fileleft(t_virtconn * vc, unsigned int size)
366 {
367 if (!vc)
368 {
369 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
370 return;
371 }
372 vc->fileleft = size;
373 }
374
375
376 extern unsigned int virtconn_get_fileleft(t_virtconn const * vc)
377 {
378 if (!vc)
379 {
380 eventlog(eventlog_level_error,__FUNCTION__,"got NULL virtconn");
381 return 0;
382 }
383 return vc->fileleft;
384 }
385
386
387 extern int virtconnlist_create(void)
388 {
389 if (!(virtconn_head = list_create()))
390 return -1;
391 return 0;
392 }
393
394
395 extern int virtconnlist_destroy(void)
396 {
397 if (list_destroy(virtconn_head)<0)
398 return -1;
399 virtconn_head = NULL;
400 return 0;
401 }
402
403
404 extern t_list * virtconnlist(void)
405 {
406 return virtconn_head;
407 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1