forked from rbruenig/qperf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.h
56 lines (46 loc) · 1003 Bytes
/
common.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#pragma once
#include <quicly.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/syscall.h>
ptls_context_t *get_tlsctx();
struct addrinfo *get_address(const char *host, const char *port);
void enable_gso();
bool send_pending(quicly_context_t *ctx, int fd, quicly_conn_t *conn);
void print_escaped(const char *src, size_t len);
static inline int64_t min_int64(int64_t a, int64_t b)
{
if(a < b) {
return a;
} else {
return b;
}
}
static inline int64_t max_int64(int64_t a, int64_t b) {
if(a > b) {
return a;
} else {
return b;
}
}
static inline int64_t clamp_int64(int64_t val, int64_t min, int64_t max)
{
if(val < min) {
return min;
}
if(val > max) {
return max;
}
return val;
}
static inline uint64_t get_current_pid()
{
uint64_t pid;
#ifdef __APPLE__
pthread_threadid_np(NULL, &pid);
#else
pid = syscall(SYS_gettid);
#endif
return pid;
}