Warning: Undefined array key "rss_show_deleted" in /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php on line 86

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 54

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 55

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/feed.php on line 56

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/inc/httputils.php on line 32

Warning: Cannot modify header information - headers already sent by (output started at /var/www/w12/dw/inc/Feed/FeedCreatorOptions.php:86) in /var/www/w12/dw/inc/httputils.php on line 33
wi12.unix7.org - cpp https://w12.unix7.org/ Wed, 05 Aug 2026 03:47:03 +0000 FeedCreator 1.8 https://w12.unix7.org/_media/wiki/dokuwiki.svg wi12.unix7.org https://w12.unix7.org/ ASIO standalone web server https://w12.unix7.org/cpp/asio-srv cpp ASIO standalone web server There present minimal sample code. From tests the code limited ~2000 concurrent connection. </code> main.cpp /* * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 C++20 chrono calendar functions https://w12.unix7.org/cpp/chorono cpp C++20 chrono calendar functions #include <iostream> #include <chrono> #include <sstream> #include <iostream> #include <iomanip> //using namespace std::chrono; void print_tp(std::chrono::system_clock::time_point tp) { std::time_t time = std::chrono::system_clock::to_time_t(tp); std::stringstream ss; ss << std::put_time(std::localtime(&time), "%Y-%m-%d %X"); std::cout << ss.str() << std::endl; } int main() { using namespace std::chrono; //auto ywdl {Monday[2]/2/… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Results of own 5day C++ network study course https://w12.unix7.org/cpp/course-w cpp Results of own 5day C++ network study course Результаты 5-дневного самостоятельного курса “Cетевые приложения, C++, сервер” You can use all samples as work code. Все примеры рассматриваются как рабочие прототипы anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Fuct wrappers example https://w12.unix7.org/cpp/func2 cpp Fuct wrappers example func2.cpp /* * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MER… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 SOAP C++ https://w12.unix7.org/cpp/gsoap-hello cpp SOAP C++ h.hello.req.xml <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:h="http://tempuri.org/h.xsd"> <SOAP-ENV:Body> <h:hello> </h:hello> </SOAP-ENV:Body> </SOAP-ENV:Envelope> anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 bison/flex based HTTP header compiler (lexer and parser) https://w12.unix7.org/cpp/http-compiler cpp bison/flex based HTTP header compiler (lexer and parser) For sample. Now parse only 4 header line types. requestcc.cpp /* * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Libconfig sample https://w12.unix7.org/cpp/libconfig cpp Libconfig sample as snippet. /* * config1.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> */ #include <iostream> #include <libconfig.hpp> int main(int argc, char **argv) { libconfig::Config config; try { config.readFile("test.conf"); } catch (std::exception& e) { std::cerr << e.what() << std::endl; return 1; } std::string foo = config.lookup("foo"); std::cout << foo << std::endl; try { libconfig::Setti… anonymous@undisclosed.example.com (Anonymous) Mon, 05 Sep 2022 08:00:20 +0000 Minimal sync file logger https://w12.unix7.org/cpp/logger cpp Minimal sync file logger /* * logger.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Json memory usage https://w12.unix7.org/cpp/njson-mem cpp Json memory usage Without json: PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND 10693 ziggi 1 35 0 18640K 14116K nanslp 0 0:00 0.59% json2 With json collector in memory: PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND 9905 ziggi 1 52 0 30976K 25376K nanslp 2 0:01 1.37% json2 anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 nlohmann JSON handle sample https://w12.unix7.org/cpp/njson cpp nlohmann JSON handle sample /* * json.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Old-old-old https://w12.unix7.org/cpp/oldoldold Old-old-old #include <iostream> using namespace std; class foo_c { public: uint i; string s; }; int main(int argc, char **argv) { foo_c foo; cout << foo.i << endl; cout << foo.s << endl; return 0; } anonymous@undisclosed.example.com (Anonymous) Mon, 29 Nov 2021 09:01:41 +0000 C++ using https://w12.unix7.org/cpp/override cpp embed C++ using sample 1 #include <iostream> class A { public: void print(char *str) { std::cout << "A:" << str << std::endl; } }; class B : public A { public: void print(char *str) { std::cout << "B1:" << str << std::endl; } using A::print; void print(std::string& str) { std::cout << "B2:" << str << std::endl; } }; int main(int argc, char **argv){ A a; char str[] = "qwerty"; … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Password https://w12.unix7.org/cpp/password cpp Password /* * password.cc * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABI… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Unix execute command with redirect std input/output to pipes. https://w12.unix7.org/cpp/pipe cpp Unix execute command with redirect std input/output to pipes. “Yet another” variant of classic algorithm. =) /* * pipe.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 libpqxx sample https://w12.unix7.org/cpp/pqxx cpp libpqxx sample /* * pqxx.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTA… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 https://w12.unix7.org/cpp/prom cpp #include <iostream> #include <functional> #include <thread> #include <future> void producer_set(std::promise<std::string>& promise) { promise.set_value("Hello World"); } void consumer_get(std::future<std::string>& future){ std::cout << future.get() << std::endl; }; int main(int argc, char **argv) { try { auto promise = std::promise<std::string>(); std::future<std::string> future = promise.get_future(); auto producer = std::thread(producer_set, std::r… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 https://w12.unix7.org/cpp/pth04 cpp pthreads async /* * Author, Copyright: Oleg Borodin <onborodin@gmail.com> */ #include <iostream> #include <chrono> #include <thread> using namespace std; using namespace std::this_thread; using namespace std::chrono; typedef struct { string id; string message; } pth_args_t; void *pth(void *args) { auto pth_args = (pth_args_t*)args; sleep_for(milliseconds(1000)); cout << "#pth " << pth_args->id << endl; sleep_for(milliseconds(1000)); cout << "#pth " << pt… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 C++ multi thread web server from scratch https://w12.unix7.org/cpp/pure-cpp-server cpp C++ multi thread web server from scratch Minimal server. I used only: * Unix basic syscalls: socket(), bin(), listen(), accept(), read(), write(), close() * C++11 objects: std::thread, std::mutex, std::condition_variable, std::queue, std::functions, std::move anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Thread-queued logger https://w12.unix7.org/cpp/qlogger cpp Thread-queued logger The queue is unlimited. /* * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warra… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Result network dump https://w12.unix7.org/cpp/rawsocket cpp /* * ping.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNES… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Referense and pointer differense https://w12.unix7.org/cpp/ref cpp c go Referense and pointer differense /* * Author, Copyright: Oleg Borodin <onborodin@gmail.com> */ #include <iostream> using namespace std; int main(int argc, char **argv) { int i = 1; int& n = i; int* m = &i; i = 3; cout << i << endl; cout << n << endl; cout << *m << endl; cout << &i << endl; cout << &n << endl; cout << m << endl; cout << &m << endl; return 0; } anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Compiler minimal sample with Re/flex and bison https://w12.unix7.org/cpp/reflex cpp lex flex bison Compiler minimal sample with Re/flex and bison %top{ #include "parser.hh" %} %option bison-cc %option bison-locations %option noyywrap %option namespace="compiler" %option lexer="lexer" %option lex="yylex" %option header-file="lexer.hh" %option bison-cc-namespace="compiler" NUMBER [[:digit:]]+ WORD [[:alnum:]]+ LET = DELIM ; NL .|\n SPACE [\t ] %% {NUMBER} { yylval.num = atoi(text()); return compil… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Reverce UTF8 sequense https://w12.unix7.org/cpp/revu8 cpp go Reverce UTF8 sequense C++ /* * Copyright Oleg Borodin <borodin@unix7.org> */ #include <iostream> #include <cstring> #include <codecvt> using namespace std; wstring_convert<codecvt_utf8<wchar_t>> converter; string& rev_utf8_str(string str) { auto wstr = converter.from_bytes(str); string buf; for (auto i = wstr.size(); i > 0; i-- ) { auto str = converter.to_bytes(wstr[i - 1]); buf += str; } return ref(buf); } int main(int argc, char **argv) { … anonymous@undisclosed.example.com (Anonymous) Tue, 30 Nov 2021 15:34:30 +0000 standalone Asio thread pool server https://w12.unix7.org/cpp/srv3 cpp standalone Asio thread pool server Based on C++03 Server3 I rewrote it sample with C++11 lambda functions and std::, exlcude any boost:: My regsrds Asio author, Christopher M. Kohlhoff. main.cpp /* * Author, Copyright: Oleg Borodin <onborodin@gmail.com> */ #include <iostream> #include <string> #include <asio.hpp> #include "server.hpp" int main(int argc, char* argv[]) { try { std::size_t num_threads = 10; server3::server s("0.0.0.0", "1026", num_threads); … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Asio SSL multithread server https://w12.unix7.org/cpp/ssl-srv7 cpp Asio SSL multithread server main.cpp /* * Author, Copyright: Oleg Borodin <onborodin@gmail.com> */ #include <iostream> #include <string> #include <asio.hpp> #include "server.hpp" int main(int argc, char* argv[]) { try { srv7::server server("0.0.0.0", "1026", 5); server.run(); } catch (std::exception& e) { std::cerr << "exception: " << e.what() << "\n"; } return 0; } anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 SSL variant of pure C++ web server https://w12.unix7.org/cpp/ssl-v cpp SSL variant of pure C++ web server /* * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * */ #ifndef SERVER_HPP #define SERVER_HPP #include <sys/socket.h> #include <unistd.h> #include <openssl/ssl.h> #include <openssl/err.h> #include <thread> #include <mutex> #include <memory> namespace srv5 { class server { private: struct sockaddr_storage addr; int socket; int backlog; std::queue<int> queue; std::condition_variable cv; … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Thread pool sample https://w12.unix7.org/cpp/thread-pool cpp Thread pool sample I wanted wrote very compact/light thread pool with queue. =) Total CPU utilization is around 95%. # top -H | grep qu 51482 user 52 0 13088K 3812K umtxn 2 0:07 40.38% queue6{queue6} 51482 user 52 0 13088K 3812K umtxn 2 0:03 16.16% queue6{queue6} 51482 user 52 0 13088K 3812K umtxn 2 0:03 15.97% queue6{queue6} 51482 user 76 0 13088K 3812K CPU1 1 0:03 15.97% queue6{queue6} 51482 user 52 0 13088K … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Thread-pool web (or no-web) server, pure C++, variant with bloked socket https://w12.unix7.org/cpp/thrsrv-bl cpp Thread-pool web (or no-web) server, pure C++, variant with bloked socket /* * Author, Copyright: Oleg Borodin <onborodin@gmail.com> */ #include <iostream> #include <vector> #include <queue> #include <chrono> #include <mutex> #include <condition_variable> #include <thread> #include <memory> #include <stdexcept> #include <iomanip> #include <csignal> #include <sys/socket.h> #include <arpa/inet.h> #include <netinet/in.h> #include <unistd.h> namespace srv { class stream { private: … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Ping & traceroute in one tube https://w12.unix7.org/cpp/trace cpp Ping & traceroute in one tube My raw socket usage example with Boost::Asio. /* * ping.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT … anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Sample async boost web clent https://w12.unix7.org/cpp/wclient cpp Sample async boost web clent /* * wclient.cpp * * Author, Copyright: Oleg Borodin <onborodin@gmail.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warrant… anonymous@undisclosed.example.com (Anonymous) Sat, 27 Nov 2021 13:26:11 +0000 Writers Bench https://w12.unix7.org/cpp/writer cpp go Writers Bench Both examples write 1G of data. FreeBSD, ZFS, SSD * clang, stream, -O1 - 1.002s * golang, bufio - 2.003s Linux, ext4, SSD * g++, stream, -O1 - 2.400 * golang, bufio - 1.028 WTF? cpp /* * Copyright Oleg Borodin <borodin@unix7.org> */ #include <iostream> #include <cstdlib> #include <fstream> #include <chrono> using namespace std::chrono; using namespace std; const string get_random_string(const int len) { string result; const char letters[] = … anonymous@undisclosed.example.com (Anonymous) Wed, 01 Dec 2021 07:44:26 +0000