1 | /*
|
---|
2 | * Copyright (C) 1994-1998, Index Data.
|
---|
3 | * See the file LICENSE for details.
|
---|
4 | * Sebastian Hammer, Adam Dickmeiss
|
---|
5 | *
|
---|
6 | * $Log$
|
---|
7 | * Revision 1.1 2000/08/03 03:11:41 johnmcp
|
---|
8 | * Added the YAZ toolkit source to the packages directory (for z39.50 stuff)
|
---|
9 | *
|
---|
10 | * Revision 1.7 1999/11/30 13:47:12 adam
|
---|
11 | * Improved installation. Moved header files to include/yaz.
|
---|
12 | *
|
---|
13 | * Revision 1.6 1998/02/11 11:53:35 adam
|
---|
14 | * Changed code so that it compiles as C++.
|
---|
15 | *
|
---|
16 | * Revision 1.5 1998/02/10 11:03:56 adam
|
---|
17 | * Added support for extended handlers in backend server interface.
|
---|
18 | *
|
---|
19 | * Revision 1.4 1997/10/27 13:55:03 adam
|
---|
20 | * Fixed memory leak: member response wasn't freed when queue
|
---|
21 | * was destroyed.
|
---|
22 | *
|
---|
23 | * Revision 1.3 1997/09/01 08:53:00 adam
|
---|
24 | * New windows NT/95 port using MSV5.0. The test server 'ztest' was
|
---|
25 | * moved a separate directory. MSV5.0 project server.dsp created.
|
---|
26 | * As an option, the server can now operate as an NT service.
|
---|
27 | *
|
---|
28 | * Revision 1.2 1995/11/01 13:54:57 quinn
|
---|
29 | * Minor adjustments
|
---|
30 | *
|
---|
31 | * Revision 1.1 1995/05/15 12:12:22 quinn
|
---|
32 | * Request queue.
|
---|
33 | *
|
---|
34 | *
|
---|
35 | */
|
---|
36 |
|
---|
37 | /*
|
---|
38 | * Simple queue management.
|
---|
39 | *
|
---|
40 | * We also use the request-freelist to store encoding buffers, rather than
|
---|
41 | * freeing and xmalloc'ing them on each cycle.
|
---|
42 | */
|
---|
43 |
|
---|
44 | #include <stdlib.h>
|
---|
45 |
|
---|
46 | #include <yaz/xmalloc.h>
|
---|
47 | #include "session.h"
|
---|
48 |
|
---|
49 | void request_enq(request_q *q, request *r)
|
---|
50 | {
|
---|
51 | if (q->tail)
|
---|
52 | q->tail->next = r;
|
---|
53 | else
|
---|
54 | q->head = r;
|
---|
55 | q->tail = r;
|
---|
56 | q->num++;
|
---|
57 | }
|
---|
58 |
|
---|
59 | request *request_head(request_q *q)
|
---|
60 | {
|
---|
61 | return q->head;
|
---|
62 | }
|
---|
63 |
|
---|
64 | request *request_deq(request_q *q)
|
---|
65 | {
|
---|
66 | request *r = q->head;
|
---|
67 |
|
---|
68 | if (!r)
|
---|
69 | return 0;
|
---|
70 | q->head = q->head->next;
|
---|
71 | if (!q->head)
|
---|
72 | q->tail = 0;
|
---|
73 | q->num--;
|
---|
74 | return r;
|
---|
75 | }
|
---|
76 |
|
---|
77 | void request_initq(request_q *q)
|
---|
78 | {
|
---|
79 | q->head = q->tail = q->list = 0;
|
---|
80 | q->num = 0;
|
---|
81 | }
|
---|
82 |
|
---|
83 | void request_delq(request_q *q)
|
---|
84 | {
|
---|
85 | request *r1, *r = q->list;
|
---|
86 | while (r)
|
---|
87 | {
|
---|
88 | xfree (r->response);
|
---|
89 | r1 = r;
|
---|
90 | r = r->next;
|
---|
91 | xfree (r1);
|
---|
92 | }
|
---|
93 | }
|
---|
94 |
|
---|
95 | request *request_get(request_q *q)
|
---|
96 | {
|
---|
97 | request *r = q->list;
|
---|
98 |
|
---|
99 | if (r)
|
---|
100 | q->list = r->next;
|
---|
101 | else
|
---|
102 | {
|
---|
103 | if (!(r = (request *)xmalloc(sizeof(*r))))
|
---|
104 | abort();
|
---|
105 | r->response = 0;
|
---|
106 | r->size_response = 0;
|
---|
107 | }
|
---|
108 | r->q = q;
|
---|
109 | r->len_refid = 0;
|
---|
110 | r->refid = 0;
|
---|
111 | r->request = 0;
|
---|
112 | r->request_mem = 0;
|
---|
113 | r->len_response = 0;
|
---|
114 | r->clientData = 0;
|
---|
115 | r->state = REQUEST_IDLE;
|
---|
116 | r->next = 0;
|
---|
117 | return r;
|
---|
118 | }
|
---|
119 |
|
---|
120 | void request_release(request *r)
|
---|
121 | {
|
---|
122 | request_q *q = r->q;
|
---|
123 | r->next = q->list;
|
---|
124 | q->list = r;
|
---|
125 | }
|
---|
126 |
|
---|