YAZ  5.23.1
requestq.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
12 #if HAVE_CONFIG_H
13 #include <config.h>
14 #endif
15 
16 #include <stdlib.h>
17 
18 #include <yaz/xmalloc.h>
19 #include "session.h"
20 
22 {
23  if (q->tail)
24  q->tail->next = r;
25  else
26  q->head = r;
27  q->tail = r;
28  q->num++;
29 }
30 
32 {
33  return q->head;
34 }
35 
37 {
38  request *r = q->head;
39 
40  if (!r)
41  return 0;
42  q->head = q->head->next;
43  if (!q->head)
44  q->tail = 0;
45  q->num--;
46  return r;
47 }
48 
50 {
51  q->head = q->tail = q->list = 0;
52  q->num = 0;
53 }
54 
56 {
57  request *r1, *r = q->list;
58  while (r)
59  {
60  xfree (r->response);
61  r1 = r;
62  r = r->next;
63  xfree (r1);
64  }
65 }
66 
68 {
69  request *r = q->list;
70 
71  if (r)
72  q->list = r->next;
73  else
74  {
75  if (!(r = (request *)xmalloc(sizeof(*r))))
76  abort();
77  r->response = 0;
78  r->size_response = 0;
79  }
80  r->q = q;
81  r->gdu_request = 0;
82  r->apdu_request = 0;
83  r->request_mem = 0;
84  r->len_response = 0;
85  r->clientData = 0;
86  r->state = REQUEST_IDLE;
87  r->next = 0;
88  return r;
89 }
90 
92 {
93  request_q *q = r->q;
94  if (r->request_mem)
96  r->next = q->list;
97  q->list = r;
98 }
99 
100 /*
101  * Local variables:
102  * c-basic-offset: 4
103  * c-file-style: "Stroustrup"
104  * indent-tabs-mode: nil
105  * End:
106  * vim: shiftwidth=4 tabstop=8 expandtab
107  */
108 
Z_APDU * apdu_request
Definition: session.h:76
int num
Definition: session.h:93
struct request_q * q
Definition: session.h:85
void request_enq(request_q *q, request *r)
Definition: requestq.c:21
request * tail
Definition: session.h:91
request * request_head(request_q *q)
Definition: requestq.c:31
void nmem_destroy(NMEM n)
destroys NMEM handle and memory associated with it
Definition: nmem.c:204
Internal header for GFS.
request_state state
Definition: session.h:73
request * request_get(request_q *q)
Definition: requestq.c:67
request * request_deq(request_q *q)
Definition: requestq.c:36
struct request * next
Definition: session.h:84
#define xfree(x)
utility macro which calls xfree_f
Definition: xmalloc.h:53
int len_response
Definition: session.h:80
Z_GDU * gdu_request
Definition: session.h:75
void request_release(request *r)
Definition: requestq.c:91
request * list
Definition: session.h:92
void * clientData
Definition: session.h:83
request * head
Definition: session.h:90
NMEM request_mem
Definition: session.h:77
int size_response
Definition: session.h:79
#define xmalloc(x)
utility macro which calls malloc_f
Definition: xmalloc.h:49
void request_initq(request_q *q)
Definition: requestq.c:49
Header for memory handling functions.
void request_delq(request_q *q)
Definition: requestq.c:55
char * response
Definition: session.h:81