Statistics
| Branch: | Revision:

napa-baselibs / tests / peer / chunk.h @ 507372bb

History | View | Annotate | Download (1.62 KB)

1
#include <stdlib.h>
2
#include <fcntl.h>
3
#include <stdio.h>
4
#include <string.h>
5
#include <errno.h>
6

    
7
#include <event2/event.h>
8
#include <event2/buffer.h>
9
#include <event2/bufferevent.h>
10
#include <event2/http.h>
11

    
12
#include <event2/http_struct.h>
13

    
14
#include <event2/buffer.h>
15
#include <sys/time.h>
16

    
17
#include "napa.h"
18

    
19

    
20
struct chunk {
21
    struct timeval rectime;
22
    unsigned int chunk_num;
23
    int len;
24
    unsigned char buf[0];
25
};
26

    
27
unsigned int chbuf_get_current(void);
28
void chbuf_enqueue_from_evbuf(struct evbuffer *eb, int chunk_num, struct timeval* timestamp);
29

    
30
/**
31
 *        enqueue chunk. Input chunk ownership remains with the caller.
32
 *  @param chunk_num   :   chunk ordinal_number
33
 *  @param length   :    chunk data length
34
 *  @param timestamp   :   the chunk timestamp (at ingesion)
35

36
*/
37
void chbuf_enqueue_chunk(int chunk_num, int length, struct timeval *timestamp, unsigned char *buffer);
38

    
39
/* returns data length, if found,
40
 * otherwise returns  CB_OLDER if the exiting is older than chunk_num or CB_NEWER otherwise.
41
 * chunk_data, and chunk_time are normally filled up with data, but both may be NULL
42
*/
43

    
44
#define CB_OLDER -1
45
#define CB_NEWER -2
46

    
47
int chbuf_get(int chunk_num, unsigned char **chunk_data, struct timeval *chunk_time);
48

    
49
void *chbuf_add_listener(int delay_usec, void (*callback)(struct chunk *, void *arg), void *arg);
50

    
51
void chbuf_remove_listener(void *listener_handle);
52

    
53
/* *********** WAITTIME UTILITY **************** */
54
/* get the remaining time (in timeval format) for a timestamp delayed by delay;
55
       return 0;0 if this is delay has already elapsed. */
56

    
57
void calc_waittime_for(struct timeval *base, int delay_usec, struct timeval *to_set);