Commit 775291f
committed
net: Allow curl handle in
The `CurlHttpClient` currently produces an excessive number of
`connect()` syscalls, as every `makeRequest` creates a new TCP
connection. This inefficiency becomes particularly evident with
`TgLongPoll`, which continuously calls `getUpdates` in an endless loop,
creating a relentless cycle of `connect()` and `close()` operations.
A more sensible approach is to reuse HTTP connections by keeping them
alive across multiple requests. I suggest modifying the implementation
to allow the curl handle to persist until the `CurlHttpClient` object is
destroyed.
For thread safety, we can maintain a
`std::unordered_map<std::thread::id, CURL*> curlHandles` within the
`CurlHttpClient` class, ensuring each thread gets its own handle.
After all, treating connections like disposable napkins doesn't exactly
scream efficiency.
Signed-off-by: Ammar Faizi <ammarfaizi2@gnuweeb.org>CurlHttpClient to be kept alive1 parent f88c332 commit 775291f
File tree
2 files changed
+35
-17
lines changed- include/tgbot/net
- src/net
2 files changed
+35
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
15 | 18 | | |
16 | 19 | | |
17 | 20 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | | - | |
| 41 | + | |
39 | 42 | | |
40 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | 11 | | |
16 | 12 | | |
17 | 13 | | |
18 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
19 | 38 | | |
20 | 39 | | |
21 | 40 | | |
| |||
24 | 43 | | |
25 | 44 | | |
26 | 45 | | |
27 | | - | |
28 | | - | |
29 | | - | |
| 46 | + | |
30 | 47 | | |
31 | 48 | | |
32 | 49 | | |
33 | 50 | | |
34 | 51 | | |
35 | 52 | | |
36 | 53 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
| |||
64 | 76 | | |
65 | 77 | | |
66 | 78 | | |
67 | | - | |
68 | | - | |
69 | 79 | | |
70 | 80 | | |
71 | 81 | | |
| |||
0 commit comments