From 00bbcb6e4d44d0e163708f130fe4826a0ce663d7 Mon Sep 17 00:00:00 2001
From: adminPyf <3043130461@qq.com>
Date: Wed, 30 Jun 2021 00:14:13 +0800
Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?=
=?UTF-8?q?=20'test=5Fbufffer=5Ffilter=5Fzlib'?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
过滤器+zlib简单案例
---
test_bufffer_filter_zlib/001.txt | 1 +
test_bufffer_filter_zlib/Makefile | 2 +
.../first_libevent.vcxproj | 165 ++++++++++++++++++
.../first_libevent.vcxproj.user | 4 +
.../test_bufffer_filter_zlib.cpp | 70 ++++++++
5 files changed, 242 insertions(+)
create mode 100644 test_bufffer_filter_zlib/001.txt
create mode 100644 test_bufffer_filter_zlib/Makefile
create mode 100644 test_bufffer_filter_zlib/first_libevent.vcxproj
create mode 100644 test_bufffer_filter_zlib/first_libevent.vcxproj.user
create mode 100644 test_bufffer_filter_zlib/test_bufffer_filter_zlib.cpp
diff --git a/test_bufffer_filter_zlib/001.txt b/test_bufffer_filter_zlib/001.txt
new file mode 100644
index 0000000..d86c1d1
--- /dev/null
+++ b/test_bufffer_filter_zlib/001.txt
@@ -0,0 +1 @@
+89012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789067890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901245678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789end
\ No newline at end of file
diff --git a/test_bufffer_filter_zlib/Makefile b/test_bufffer_filter_zlib/Makefile
new file mode 100644
index 0000000..19021e7
--- /dev/null
+++ b/test_bufffer_filter_zlib/Makefile
@@ -0,0 +1,2 @@
+test_bufffer_filter: test_bufffer_filter.cpp
+ g++ $^ -o $@ -levent
\ No newline at end of file
diff --git a/test_bufffer_filter_zlib/first_libevent.vcxproj b/test_bufffer_filter_zlib/first_libevent.vcxproj
new file mode 100644
index 0000000..6fc0d62
--- /dev/null
+++ b/test_bufffer_filter_zlib/first_libevent.vcxproj
@@ -0,0 +1,165 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 15.0
+ {129BF326-BFEE-4F1C-920C-0C302BB84895}
+ Win32Proj
+ firstlibevent
+ 10.0.17763.0
+ test_bufffer_filter_zlib
+
+
+
+ Application
+ true
+ v141
+ Unicode
+
+
+ Application
+ false
+ v141
+ true
+ Unicode
+
+
+ Application
+ true
+ v141
+ Unicode
+
+
+ Application
+ false
+ v141
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+
+
+ true
+
+
+ false
+
+
+ false
+
+
+
+
+
+ Level3
+ Disabled
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ NotUsing
+ Level3
+ Disabled
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS
+ true
+ ..\..\include
+ EnableFastChecks
+
+
+ Console
+ true
+ ..\..\lib
+ libevent.lib;ws2_32.lib;zlib.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/test_bufffer_filter_zlib/first_libevent.vcxproj.user b/test_bufffer_filter_zlib/first_libevent.vcxproj.user
new file mode 100644
index 0000000..6e2aec7
--- /dev/null
+++ b/test_bufffer_filter_zlib/first_libevent.vcxproj.user
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/test_bufffer_filter_zlib/test_bufffer_filter_zlib.cpp b/test_bufffer_filter_zlib/test_bufffer_filter_zlib.cpp
new file mode 100644
index 0000000..b00e559
--- /dev/null
+++ b/test_bufffer_filter_zlib/test_bufffer_filter_zlib.cpp
@@ -0,0 +1,70 @@
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#ifdef _WIN32
+
+#else
+#include
+#endif // !_WIN32
+
+using namespace std;
+
+
+int main()
+{
+#ifdef _WIN32
+ //初始化socket库
+ WSADATA wsa;
+ WSAStartup(MAKEWORD(2, 2), &wsa);
+#else
+ if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
+ { //忽略管道信号,发送数据给已关闭的socket,会飞掉!
+ return 1;
+ }
+#endif
+
+ //初始化libevent上下文
+ event_config *conf = event_config_new();
+
+ //windows中支持IOCP(线程池) 要查看该项是否开启成功,可以在运行程序后打开任务管理器查看线程数量
+#ifdef _WIN32
+ event_config_set_flag(conf, EVENT_BASE_FLAG_STARTUP_IOCP);
+ evthread_use_windows_threads();
+ //设置cpu数量
+ SYSTEM_INFO si;
+ GetSystemInfo(&si);
+ event_config_set_num_cpus_hint(conf, si.dwNumberOfProcessors);
+#endif
+
+ //初始化配置上下文
+ event_base *base = event_base_new_with_config(conf);
+
+ if (!base)
+ {
+ cout << "event_base_new_with_config failed!" << endl;
+ base = event_base_new();
+ if (!base)
+ {
+ cerr << "event_base_new failed" << endl;
+ return 0;
+ }
+ }
+ else
+ {
+ void Server(event_base* base);
+ Server(base);
+ void Client(event_base* base);
+ Client(base);
+
+
+ event_base_dispatch(base);
+ event_base_free(base);
+ event_config_free(conf);
+ }
+ return 0;
+}