Split out rand

This commit is contained in:
Ian Gulliver
2016-02-22 14:45:18 -08:00
parent f255170967
commit 16685b8d05
6 changed files with 37 additions and 28 deletions

View File

@@ -12,6 +12,7 @@
#include <uuid/uuid.h>
#include "common.h"
#include "rand.h"
#include "wakeup.h"
static char server_id[UUID_LEN];
@@ -220,22 +221,6 @@ void uuid_gen(char *out) {
}
static int rand_fd;
void rand_init() {
rand_fd = open("/dev/urandom", O_RDONLY);
assert(rand_fd >= 0);
}
void rand_cleanup() {
assert(!close(rand_fd));
}
void rand_fill(void *value, size_t size) {
assert(read(rand_fd, value, size) == size);
}
#define RETRY_MIN_MS 2000
#define RETRY_MAX_MS 60000
uint32_t retry_get_delay_ms(uint32_t attempt) {