diff options
Diffstat (limited to 'toxcore/ping_array.h')
-rw-r--r-- | toxcore/ping_array.h | 55 |
1 files changed, 23 insertions, 32 deletions
diff --git a/toxcore/ping_array.h b/toxcore/ping_array.h index bdf3c6db..b927bbd4 100644 --- a/toxcore/ping_array.h +++ b/toxcore/ping_array.h | |||
@@ -26,51 +26,42 @@ | |||
26 | 26 | ||
27 | #include "network.h" | 27 | #include "network.h" |
28 | 28 | ||
29 | typedef struct { | 29 | #ifndef PING_ARRAY_DEFINED |
30 | void *data; | 30 | #define PING_ARRAY_DEFINED |
31 | uint32_t length; | 31 | typedef struct Ping_Array Ping_Array; |
32 | uint64_t time; | 32 | #endif /* PING_ARRAY_DEFINED */ |
33 | uint64_t ping_id; | ||
34 | } Ping_Array_Entry; | ||
35 | 33 | ||
34 | /** | ||
35 | * Initialize a Ping_Array. | ||
36 | * size represents the total size of the array and should be a power of 2. | ||
37 | * timeout represents the maximum timeout in seconds for the entry. | ||
38 | * | ||
39 | * return 0 on success. | ||
40 | * return -1 on failure. | ||
41 | */ | ||
42 | struct Ping_Array *ping_array_new(uint32_t size, uint32_t timeout); | ||
36 | 43 | ||
37 | typedef struct { | 44 | /** |
38 | Ping_Array_Entry *entries; | 45 | * Free all the allocated memory in a Ping_Array. |
39 | 46 | */ | |
40 | uint32_t last_deleted; /* number representing the next entry to be deleted. */ | 47 | void ping_array_kill(struct Ping_Array *_array); |
41 | uint32_t last_added; /* number representing the last entry to be added. */ | ||
42 | uint32_t total_size; /* The length of entries */ | ||
43 | uint32_t timeout; /* The timeout after which entries are cleared. */ | ||
44 | } Ping_Array; | ||
45 | |||
46 | 48 | ||
47 | /* Add a data with length to the Ping_Array list and return a ping_id. | 49 | /** |
50 | * Add a data with length to the Ping_Array list and return a ping_id. | ||
48 | * | 51 | * |
49 | * return ping_id on success. | 52 | * return ping_id on success. |
50 | * return 0 on failure. | 53 | * return 0 on failure. |
51 | */ | 54 | */ |
52 | uint64_t ping_array_add(Ping_Array *array, const uint8_t *data, uint32_t length); | 55 | uint64_t ping_array_add(struct Ping_Array *_array, const uint8_t *data, uint32_t length); |
53 | 56 | ||
54 | /* Check if ping_id is valid and not timed out. | 57 | /** |
58 | * Check if ping_id is valid and not timed out. | ||
55 | * | 59 | * |
56 | * On success, copies the data into data of length, | 60 | * On success, copies the data into data of length, |
57 | * | 61 | * |
58 | * return length of data copied on success. | 62 | * return length of data copied on success. |
59 | * return -1 on failure. | 63 | * return -1 on failure. |
60 | */ | 64 | */ |
61 | int ping_array_check(uint8_t *data, uint32_t length, Ping_Array *array, uint64_t ping_id); | 65 | int32_t ping_array_check(struct Ping_Array *_array, uint8_t *data, size_t length, uint64_t ping_id); |
62 | |||
63 | /* Initialize a Ping_Array. | ||
64 | * size represents the total size of the array and should be a power of 2. | ||
65 | * timeout represents the maximum timeout in seconds for the entry. | ||
66 | * | ||
67 | * return 0 on success. | ||
68 | * return -1 on failure. | ||
69 | */ | ||
70 | int ping_array_init(Ping_Array *empty_array, uint32_t size, uint32_t timeout); | ||
71 | |||
72 | /* Free all the allocated memory in a Ping_Array. | ||
73 | */ | ||
74 | void ping_array_free_all(Ping_Array *array); | ||
75 | 66 | ||
76 | #endif | 67 | #endif |