/* * We have just consumed "c" bytes. */ void ring_consumed (Ring * ring, int count) { if (count == 0) /* don't update anything */ return; if (ring->mark && (ring_subtract (ring, ring->mark, ring->consume) < count)) { ring->mark = 0; } #ifdef ENCRYPTION if (ring->consume < ring->clearto && ring->clearto <= ring->consume + count) ring->clearto = 0; else if (ring->consume + count > ring->top && ring->bottom <= ring->clearto && ring->bottom + ((ring->consume + count) - ring->top)) ring->clearto = 0; #endif /* ENCRYPTION */ ring->consume = ring_increment (ring, ring->consume, count); ring->consumetime = ++ring_clock; /* * Try to encourage "ring_empty_consecutive()" to be large. */ if (ring_empty (ring)) { ring->consume = ring->supply = ring->bottom; } }
/** peek at timevalue for next item in ring */ static struct timeval* ring_peek_time(struct ringbuf* r) { if(ring_empty(r)) return NULL; return (struct timeval*)&r->buf[r->low]; }
/** send out waiting packets */ static void service_send(struct ringbuf* ring, struct timeval* now, sldns_buffer* pkt, struct sockaddr_storage* srv_addr, socklen_t srv_len) { struct proxy* p; struct timeval tv; ssize_t sent; while(!ring_empty(ring) && dl_tv_smaller(ring_peek_time(ring), now)) { /* this items needs to be sent out */ if(!ring_pop(ring, pkt, &tv, &p)) fatal_exit("ringbuf error: pop failed"); verbose(1, "send out query %d.%6.6d", (unsigned)tv.tv_sec, (unsigned)tv.tv_usec); log_addr(1, "from client", &p->addr, p->addr_len); /* send it */ sent = sendto(p->s, (void*)sldns_buffer_begin(pkt), sldns_buffer_limit(pkt), 0, (struct sockaddr*)srv_addr, srv_len); if(sent == -1) { #ifndef USE_WINSOCK log_err("sendto: %s", strerror(errno)); #else log_err("sendto: %s", wsa_strerror(WSAGetLastError())); #endif } else if(sent != (ssize_t)sldns_buffer_limit(pkt)) { log_err("sendto: partial send"); } p->lastuse = *now; p->numsent++; } }
void ring_clearto (Ring * ring) { if (!ring_empty (ring)) ring->clearto = ring->supply; else ring->clearto = 0; }
char frob (unsigned short a, unsigned short b) { g = a; p = b; inc_g (); return ring_empty (); }
/* Number of bytes that may be supplied */ int ring_empty_count(Ring *ring) { if (ring_empty(ring)) { /* if empty */ return ring->size; } else { return ring_subtract(ring, ring->consume, ring->supply); } }
int ring_get(Ring *ring, RingEntry *entry) { if (ring_empty(ring)) { return 0; } RingEntry *e = ring->data + ring->start; memcpy(entry, e, sizeof(RingEntry)); ring->start = (ring->start + 1) % ring->capacity; return 1; }
int gpc_not_empty() { if(ring_empty(&gpc_output_ring) > 0) { return 1; }else { return 0; } }
unsigned short get_n (void) { unsigned short n = 0; unsigned short org_g; org_g = curr_g (); while (!ring_empty () && n < 5) { inc_g (); n++; } return n; }
/* number of CONSECUTIVE bytes that may be supplied */ int ring_empty_consecutive(Ring *ring) { if ((ring->consume < ring->supply) || ring_empty(ring)) { /* * if consume is "below" supply, or empty, then * return distance to the top */ return ring_subtract(ring, ring->top, ring->supply); } else { /* * else, return what we may. */ return ring_subtract(ring, ring->consume, ring->supply); } }
void ring_encrypt(Ring *ring, void (*encryptor)(unsigned char *, int)) { unsigned char *s, *c; if (ring_empty(ring) || ring->clearto == ring->supply) return; if (!(c = ring->clearto)) c = ring->consume; s = ring->supply; if (s <= c) { (*encryptor)(c, ring->top - c); (*encryptor)(ring->bottom, s - ring->bottom); } else (*encryptor)(c, s - c); ring->clearto = ring->supply; }