Created
May 14, 2023 19:44
-
-
Save azat/772e401df50703376963bbffdccbae29 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ git di | |
diff --git a/client.cpp b/client.cpp | |
index 294c8b7..cf347fe 100644 | |
--- a/client.cpp | |
+++ b/client.cpp | |
@@ -32,7 +32,7 @@ | |
#include <event2/util.h> | |
#include <event2/event.h> | |
-#include <sanitizer/lsan_interface.h> | |
+//#include <sanitizer/lsan_interface.h> | |
static const char MESSAGE[] = "Hello, World! "; | |
const char *message2; | |
@@ -49,7 +49,7 @@ static void signal_cb(evutil_socket_t, short, void *); | |
void handlerCont(int signum){ | |
printf("SIGCONT %d\n", signum); | |
#ifndef NDEBUG | |
- __lsan_do_recoverable_leak_check(); | |
+ //__lsan_do_recoverable_leak_check(); | |
#endif | |
} | |
@@ -105,6 +105,13 @@ main(int argc, char **argv) | |
return 1; | |
} | |
+ size_t limit = 1<<20; | |
+ struct timeval tick_len = { 1, 0 }; | |
+ auto cfg = ev_token_bucket_cfg_new(limit, limit, limit*2, limit*2, &tick_len); | |
+ int err = bufferevent_set_rate_limit(bev, cfg); | |
+ // NOTE: cfg should be freed with ev_token_bucket_cfg_free()! | |
+ //assert(!err); | |
+ | |
bufferevent_setcb(bev, conn_readcb, conn_writecb, conn_eventcb, NULL); | |
if (bufferevent_socket_connect( | |
diff --git a/server.cpp b/server.cpp | |
index 128e506..617f016 100644 | |
--- a/server.cpp | |
+++ b/server.cpp | |
@@ -26,6 +26,7 @@ | |
#include <unistd.h> | |
#include <arpa/inet.h> | |
#include <stdlib.h> | |
+#include <cassert> | |
#include <event2/bufferevent.h> | |
#include <event2/buffer.h> | |
@@ -33,7 +34,7 @@ | |
#include <event2/util.h> | |
#include <event2/event.h> | |
-#include <sanitizer/lsan_interface.h> | |
+//#include <sanitizer/lsan_interface.h> | |
static const char MESSAGE[] = "Hello, World! "; | |
@@ -49,7 +50,7 @@ static void signal_cb(evutil_socket_t, short, void *); | |
void handlerCont(int signum){ | |
printf("SIGCONT %d\n", signum); | |
#ifndef NDEBUG | |
- __lsan_do_recoverable_leak_check(); | |
+ //__lsan_do_recoverable_leak_check(); | |
#endif | |
} | |
@@ -132,6 +133,13 @@ listener_cb(struct evconnlistener *listener, evutil_socket_t fd, | |
bufferevent_setcb(bev, conn_readcb, conn_writecb, conn_eventcb, NULL); | |
bufferevent_enable(bev, EV_WRITE | EV_READ); | |
+ size_t limit = 1<<20; | |
+ struct timeval tick_len = { 1, 0 }; | |
+ auto cfg = ev_token_bucket_cfg_new(limit, limit, limit*2, limit*2, &tick_len); | |
+ int err = bufferevent_set_rate_limit(bev, cfg); | |
+ // NOTE: cfg should be freed with ev_token_bucket_cfg_free()! | |
+ assert(!err); | |
+ | |
// bufferevent_write(bev, MESSAGE, strlen(MESSAGE)); // | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment