Mercurial > audlegacy-plugins
annotate src/neon/rb.c @ 1872:50f1c5a40a7d
adplug -> new buildsys.
Untested, please test!
author | Jonathan Schleifer <js@h3c.de> |
---|---|
date | Tue, 25 Sep 2007 18:03:21 +0200 |
parents | dc83901850df |
children | 9a9f406374c6 |
rev | line source |
---|---|
1751
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
1 /* |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
2 * This program is free software; you can redistribute it and/or modify |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
3 * it under the terms of the GNU General Public License as published by |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
4 * the Free Software Foundation; either version 2 of the License, or |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
5 * (at your option) any later version. |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
6 * |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
7 * This program is distributed in the hope that it will be useful, |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
10 * GNU General Public License for more details. |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
11 * |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
12 * You should have received a copy of the GNU General Public License |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
13 * along with this program; if not, write to the Free Software |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
15 */ |
dc83901850df
- Add license texts to the neon source
Ralf Ertzinger <ralf@skytale.net>
parents:
1719
diff
changeset
|
16 |
1719
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
17 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
18 * Ringbuffer implementation |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
19 * |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
20 * GPL |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
21 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
22 #include <string.h> |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
23 #include "rb.h" |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
24 #include "debug.h" |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
25 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
26 #ifdef RB_DEBUG |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
27 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
28 * An internal assertion function to make sure that the |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
29 * ringbuffer structure is consistient. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
30 * |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
31 * WARNING: This function will call abort() if the ringbuffer |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
32 * is found to be inconsistient. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
33 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
34 static void _assert_rb(struct ringbuf* rb) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
35 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
36 unsigned int realused; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
37 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
38 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
39 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
40 _DEBUG("rb->buf=%p, rb->end=%p, rb->wp=%p, rb->rp=%p, rb->free=%u, rb->used=%u, rb->size=%u", |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
41 rb->buf, rb->end, rb->wp, rb->rp, rb->free, rb->used, rb->size); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
42 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
43 if (0 == rb->size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
44 _ERROR("Buffer size is 0"); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
45 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
46 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
47 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
48 if (NULL == rb->buf) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
49 _ERROR("Buffer start is NULL"); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
50 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
51 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
52 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
53 if (rb->used+rb->free != rb->size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
54 _ERROR("rb->free and rb->used do not add up to rb->size"); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
55 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
56 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
57 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
58 if (rb->buf+(rb->size-1) != rb->end) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
59 _ERROR("rb->buf and rb->end not rb->size bytes apart"); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
60 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
61 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
62 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
63 if ((rb->wp < rb->buf) || (rb->wp > rb->end)) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
64 _ERROR("Write pointer outside buffer space"); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
65 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
66 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
67 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
68 if ((rb->rp < rb->buf) || (rb->rp > rb->end)) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
69 _ERROR("Read pointer outside buffer space"); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
70 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
71 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
72 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
73 if (rb->rp <= rb->wp) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
74 realused = rb->wp - rb->rp; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
75 } else { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
76 realused = (rb->end - rb->rp) + 1 + (rb->wp-rb->buf); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
77 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
78 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
79 if (rb->used != realused) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
80 _ERROR("Usage count is inconsistient (is %d, should be %d)", rb->used, realused); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
81 abort(); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
82 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
83 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
84 _LEAVE; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
85 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
86 #endif |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
87 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
88 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
89 * Reset a ringbuffer structure (i.e. discard |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
90 * all data inside of it) |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
91 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
92 void reset_rb(struct ringbuf* rb) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
93 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
94 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
95 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
96 pthread_mutex_lock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
97 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
98 rb->wp = rb->buf; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
99 rb->rp = rb->buf; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
100 rb->free = rb->size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
101 rb->used = 0; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
102 rb->end = rb->buf+(rb->size-1); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
103 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
104 pthread_mutex_unlock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
105 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
106 _LEAVE; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
107 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
108 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
109 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
110 * Initialize a ringbuffer structure (including |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
111 * memory allocation. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
112 * |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
113 * Return -1 on error |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
114 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
115 int init_rb(struct ringbuf* rb, unsigned int size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
116 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
117 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
118 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
119 if (0 == size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
120 _LEAVE -1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
121 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
122 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
123 if (0 != pthread_mutex_init(&rb->lock, NULL)) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
124 _LEAVE -1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
125 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
126 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
127 if (NULL == (rb->buf = malloc(size))) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
128 _LEAVE -1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
129 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
130 rb->size = size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
131 reset_rb(rb); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
132 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
133 ASSERT_RB(rb); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
134 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
135 _LEAVE 0; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
136 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
137 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
138 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
139 * Write size bytes at buf into the ringbuffer. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
140 * Return -1 on error (not enough space in buffer) |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
141 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
142 int write_rb(struct ringbuf* rb, void* buf, unsigned int size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
143 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
144 int ret = -1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
145 int endfree; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
146 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
147 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
148 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
149 pthread_mutex_lock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
150 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
151 ASSERT_RB(rb); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
152 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
153 if (rb->free < size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
154 ret = -1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
155 goto out; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
156 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
157 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
158 endfree = (rb->end - rb->wp)+1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
159 if (endfree < size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
160 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
161 * There is enough space in the buffer, but not in |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
162 * one piece. We need to split the copy into two parts. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
163 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
164 memcpy(rb->wp, buf, endfree); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
165 memcpy(rb->buf, buf+endfree, size-endfree); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
166 rb->wp = rb->buf + (size-endfree); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
167 } else if (endfree > size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
168 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
169 * There is more space than needed at the end |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
170 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
171 memcpy(rb->wp, buf, size); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
172 rb->wp += size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
173 } else { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
174 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
175 * There is exactly the space needed at the end. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
176 * We need to wrap around the read pointer. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
177 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
178 memcpy(rb->wp, buf, size); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
179 rb->wp = rb->buf; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
180 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
181 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
182 rb->free -= size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
183 rb->used += size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
184 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
185 ret = 0; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
186 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
187 out: |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
188 ASSERT_RB(rb); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
189 pthread_mutex_unlock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
190 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
191 _LEAVE ret; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
192 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
193 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
194 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
195 * Read size byes from buffer into buf. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
196 * Return -1 on error (not enough data in buffer) |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
197 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
198 int read_rb(struct ringbuf* rb, void* buf, unsigned int size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
199 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
200 int ret; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
201 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
202 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
203 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
204 pthread_mutex_lock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
205 ret = read_rb_locked(rb, buf, size); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
206 pthread_mutex_unlock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
207 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
208 _LEAVE ret; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
209 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
210 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
211 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
212 * Read size bytes from buffer into buf, assuming the buffer lock |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
213 * is already held. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
214 * Return -1 on error (not enough data in buffer) |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
215 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
216 int read_rb_locked(struct ringbuf* rb, void* buf, unsigned int size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
217 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
218 int endused; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
219 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
220 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
221 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
222 ASSERT_RB(rb); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
223 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
224 if (rb->used < size) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
225 /* Not enough bytes in buffer */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
226 _LEAVE -1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
227 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
228 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
229 if (rb->rp < rb->wp) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
230 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
231 Read pointer is behind write pointer, all the data is available in one cunk |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
232 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
233 memcpy(buf, rb->rp, size); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
234 rb->rp += size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
235 } else { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
236 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
237 * Read pointer is before write pointer |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
238 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
239 endused = (rb->end - rb->rp)+1; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
240 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
241 if (size < endused) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
242 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
243 * Data is available in one chunk |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
244 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
245 memcpy(buf, rb->rp, size); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
246 rb->rp += size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
247 } else { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
248 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
249 * There is enough data in the buffer, but it is fragmented. |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
250 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
251 memcpy(buf, rb->rp, endused); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
252 memcpy(buf+endused, rb->buf, size-endused); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
253 rb->rp = rb->buf + (size-endused); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
254 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
255 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
256 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
257 rb->free += size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
258 rb->used -= size; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
259 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
260 ASSERT_RB(rb); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
261 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
262 _LEAVE 0; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
263 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
264 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
265 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
266 * Return the amount of free space currently in the rb |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
267 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
268 unsigned int free_rb(struct ringbuf* rb) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
269 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
270 unsigned int f; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
271 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
272 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
273 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
274 pthread_mutex_lock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
275 f = rb->free; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
276 pthread_mutex_unlock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
277 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
278 _LEAVE f; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
279 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
280 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
281 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
282 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
283 * Return the amount of used space currently in the rb |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
284 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
285 unsigned int used_rb(struct ringbuf* rb) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
286 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
287 unsigned int u; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
288 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
289 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
290 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
291 pthread_mutex_lock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
292 u = rb->used; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
293 pthread_mutex_unlock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
294 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
295 _LEAVE u; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
296 } |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
297 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
298 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
299 /* |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
300 * destroy a ringbuffer |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
301 */ |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
302 void destroy_rb(struct ringbuf* rb) { |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
303 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
304 _ENTER; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
305 pthread_mutex_lock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
306 free(rb->buf); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
307 pthread_mutex_unlock(&rb->lock); |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
308 |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
309 _LEAVE; |
29c35cb8873e
- Add neon HTTP transport plugin sources (for real)
Ralf Ertzinger <ralf@skytale.net>
parents:
diff
changeset
|
310 } |