Lines Matching defs:shaper
12 #include "shaper.h"
101 int active; /* is this shaper active ? */
114 netshaper_destroy( NetShaper shaper )
116 if (shaper) {
117 shaper->active = 0;
119 while (shaper->packets) {
120 QueuedPacket packet = shaper->packets;
121 shaper->packets = packet->next;
126 qemu_del_timer(shaper->timer);
127 qemu_free_timer(shaper->timer);
128 shaper->timer = NULL;
129 qemu_free(shaper);
133 /* this function is called when the shaper's timer expires */
135 netshaper_expires( NetShaper shaper )
139 while ((packet = shaper->packets) != NULL) {
145 shaper->packets = packet->next;
146 shaper->send_func( packet->data, packet->size, packet->opaque );
148 shaper->num_packets--;
152 if (shaper->packets) {
153 shaper->block_until = shaper->packets->expiration;
154 qemu_mod_timer( shaper->timer, shaper->block_until );
156 shaper->block_until = -1;
165 NetShaper shaper = qemu_malloc(sizeof(*shaper));
167 shaper->active = 0;
168 shaper->packets = NULL;
169 shaper->num_packets = 0;
170 shaper->timer = qemu_new_timer_ms( SHAPER_CLOCK,
172 shaper );
173 shaper->send_func = send_func;
174 shaper->max_rate = 1e6;
175 shaper->inv_rate = 0.;
177 shaper->block_until = -1; /* magic value, means to not block */
179 return shaper;
183 netshaper_set_rate( NetShaper shaper,
187 while (shaper->packets) {
188 QueuedPacket packet = shaper->packets;
189 shaper->packets = packet->next;
190 shaper->send_func(packet->data, packet->size, packet->opaque);
192 shaper->num_packets = 0;
195 shaper->max_rate = rate;
197 shaper->inv_rate = (8.*SHAPER_CLOCK_UNIT)/rate; /* qemu_get_clock returns time in ms */
198 shaper->active = 1; /* for the real-time clock */
200 shaper->active = 0;
203 shaper->block_until = -1;
207 netshaper_send_aux( NetShaper shaper,
214 if (!shaper->active || _packet_is_internal(data, size)) {
215 shaper->send_func( data, size, opaque );
220 if (now >= shaper->block_until) {
221 shaper->send_func( data, size, opaque );
222 shaper->block_until = now + size*shaper->inv_rate;
223 //fprintf(stderr, "NETSHAPER: block for %.2fms\n", (shaper->block_until - now)*1.0 );
231 packet = queued_packet_create( data, size, opaque, shaper->do_copy );
233 packet->expiration = shaper->block_until;
238 pnode = &shaper->packets;
248 if (packet == shaper->packets)
249 qemu_mod_timer( shaper->timer, packet->expiration );
251 shaper->num_packets += 1;
253 shaper->block_until += size*shaper->inv_rate;
254 //fprintf(stderr, "NETSHAPER: block2 for %.2fms\n", (shaper->block_until - now)*1.0 );
258 netshaper_send( NetShaper shaper,
262 netshaper_send_aux(shaper, data, size, NULL);
267 netshaper_can_send( NetShaper shaper )
271 if (!shaper->active || shaper->block_until < 0)
274 if (shaper->packets)
278 return (now >= shaper->block_until);