从epoll构建muduo-8 加入发送缓冲区和接收缓冲区

从epoll构建muduo-1 mini-muduo介绍 前段时间看了陈硕写的muduo网络库(github, 书, blog),觉得这是一个学习网络编程的非常好的素材。为了更好的了解这个库,自己花了点时间,模仿其源码从零开始编写了一个极小的mini-muduo(起这名字没版权问题吧:-)),代码编写过程中有很多收获,我打算写几篇文章记录下心得。有几个问题先说明一下: Q1:网络库很多,为什么选择muduo?     1 库的功能相对完整,基 阅读详情
从epoll构建muduo-6 加入EventLoop和Epoll mini-muduo v0.05版本,完整可运行的示例可从github下载,使用命令git checkout v0.05可切换到此版本,在线浏览此版本到这里 本版将程序的主要类都加入进来了,这个版本可以作为一个里程碑版本,最重要的修改是加入了两个类EventLoop和Epoll。加入这两个类后,程序代码逻辑就相对清晰多了。为了有个更直观的了解,我们对照之前介绍的最简单epoll示例(从epoll构 阅读详情

相关推荐

从epoll构建muduo-4 加入Channel

mini-muduo v 0.03版本,这是个版本最重要的修改是加入了一个名为Channel的类。完整可运行的示例可从github下载,使用命令git checkout v0.03可切换到此版本,在线浏览此版本到这里 介绍一下Channel类,先看其声明,这里特别要注意_events和_revents,前者是要关注的事件,后者是发生的事件,不仔细看容易混淆。名字的来源是poll(2)的struc

voidccc的专栏 4617

从epoll构建muduo-2 最简单的epoll

mini-muduo v 0.01版本,这是mini-muduo的第一个版本,整个程序是一个100行的epoll示例 下面粘贴的代码省略了头文件引用,完整可运行的示例可从github下载,使用命令git checkout v0.01可切换到此版本,在线浏览到这里 #define MAX_LINE 100 #define MAX_EVENTS 500 #define MAX_LISTENFD

voidccc的专栏 6181

从epoll构建muduo-3 加入第一个类,顺便介绍reactor

mini-muduo v 0.02版本,这个版本添加的内容非常少,完整可运行的示例可从github下载,使用命令git checkout v0.02可切换到此版本,在线浏览到这里 #include "TcpServer.h" int main(int args, char** argv) { TcpServer tcpserver; tcpserver.start();

voidccc的专栏 4683

从epoll构建muduo-9 加入onWriteComplate回调和Buffer

mini-muduo v0.08版本,这个版本完善了缓冲区的实现。mini-muduo完整可运行的示例可从github下载,使用命令git checkout v0.08可切换到此版本,在线浏览此版本到这里  本版本有两处重要修改,首先实现了IMuduoUser的onWriteComplate回调,这样当用户一次传送大量数据到网络库时,用户会在数据发送完成后收到通知。当然了发送小量数据完成时也

voidccc的专栏 3046

从epoll构建muduo-7 加入IMuduoUser

mini-muduo v0.06版本,这个版本应该算是一个里程碑版本,最重要的修改是将库和库的用户分离。完整可运行的示例可从github下载,使用命令git checkout v0.06可切换到此版本,在线浏览此版本到这里 1 在这个版本中,我们的网络库才真正的能被称为“库”。整个mini-muduo程序现在被分成了两部分,一边是库,另一边是库的用户。EchoServer这个类就是用户了,用户关

voidccc的专栏 3161

从epoll构建muduo-5 加入Acceptor和TcpConnection

mini-muduo v0.04版本,这是个版本最重要的修改是加入了两个类Acceptor和TcpConnection。完整可运行的示例可从github下载,使用命令git checkout v0.04可切换到此版本,在线浏览此版本到这里 1 回顾下v0.03版本,所有的socket事件都是在TcpServer::OnIn(命名不规范后续会改动)里处理的,包括接受新连接和读写数据,那实在是没

voidccc的专栏 3505

从epoll构建muduo-12 多线程入场

多线程代码被加入到mini-muduo,本篇主要介绍Linux多线程编程的5个类 1 Mutex 2 Condition 3 BlockingQueue 4 Thread 5 ThreadPool

voidccc的专栏 5040

从epoll构建muduo-10 Timer定时器

mini-muduo v0.09版本,实现了Timer定时器。mini-muduo完整可运行的示例可从github下载,使用命令git checkout v0.09可切换到此版本,在线浏览此版本到这里。 这个版本是一个里程碑版本,到这个版本为止,可以说一个单线程的Reactor模式网络库基本成型,程序里的类各司其职,协同完成网络数据的首发。后续版本只是在此基础上增加了多个工作线程(耗费CPU

voidccc的专栏 6313

从epoll构建muduo-11 单线程Reactor网络模型成型

mini-muduo v0.10版本,修整代码版本。mini-muduo完整可运行的示例可从github下载,使用命令git checkout v0.10可切换到此版本,在线浏览此版本到这里。 这个版本的改动不大,主要修改了命名规范问题,借着这个版本重点分析一下muduo里的三个文件描述符。

voidccc的专栏 4011

STM32进入HardFault_Handler时,如何找到问题所在?

当STM32进入HardFault_Handler时,定位问题发生的点

m0_60831979的博客 2153

信贷风控分析—征信数据源

详解企业和个人征信报告,以及信贷风控之指标构造案例参考

csdnbt的博客 3647

LAMMPS ReaxFF模拟后处理:如何用Python精准追踪C-N键的断裂与形成?

本文详细介绍了如何利用Python对LAMMPS ReaxFF模拟结果进行后处理,精准追踪C-N键的断裂与形成过程。通过解析键级输出文件、构建原子类型映射字典,并实现C-N键的统计与可视化,为材料科学和催化反应研究提供了高效的数据分析解决方案。文章特别强调了ReaxFF力场在断键分析中的关键作用,并提供了完整的Python代码实现。

weixin_28706923的博客 356

2025年人形机器人产业研究

人形机器人是一种模仿人类外形、动作和行为的机器人,旨在替代或辅助人类完成各种任务。其显著特征包括人类外形、动作模仿和智能交互能力。根据形态和功能,人形机器人可分为小型、中型、大型以及服务型、工业型、救援型和娱乐型等类别。发展历程经历了初始阶段、高度集成系统阶段和突破性进展阶段,技术不断进步。关键技术包括执行系统、控制系统和感知与交互系统,涉及机械结构、运动控制、平衡控制、任务执行控制以及感知与交互能力。主要研究方向包括外部仿人化和内部仿生,前者关注外观设计、动作控制和任务执行能力,后者致力于模拟人类核心机制

一名80后IT人的成长记录,记录自己在工作、学习中的点点滴滴,在成长的喜悦与忧心的故事里,铭记反脆弱的勇气。 1573

从零到一:ESP32与豆包大模型的RTC连续对话实现指南

文本实现ESP32S3 SparkBot与豆包大模型的RTC连续对话

举世誉之而不加劝,举世非之而不加沮,定乎内外之分,辩乎荣辱之境,斯已矣。 4370

深度测评:Accio Work——目前普通用户最友好的多 Agent 协同工具

摘要:Accio Work是阿里国际站推出的多Agent协同工具,通过借鉴古代"三省六部制"构建高效协作框架。该工具支持主流大模型,可配置专业Agent角色,实现40分钟内完成复杂产品PRD等高效协作。其亮点在于直观的UI设计和流程驱动机制,能强制各Agent从专业视角深度思考。虽然超长对话稳定性有待优化,但作为目前最用户友好的多Agent工具,显著降低了构建复杂AI团队的门槛,成为提升个人和小微企业生产力的利器。

Maynor的博客 1748

《UDS协议从入门到精通》系列——图解0x34:请求下载

上传下载类服务之0x34-请求下载,图解请求+响应格式,直观易懂,快速上手!!

车载系统攻城狮 4931

开发具有情感分析能力的AI Agent

本文将深入探讨开发具有情感分析能力的AI Agent的各个方面。我们将首先介绍情感分析的基础知识,包括定义、背景和应用领域。接着,我们将详细讲解情感分析的核心概念、数据处理方法和算法原理。随后,文章将展示如何设计情感分析系统架构,并进行项目实战,包括环境安装、源代码实现和案例分析。最后,我们将总结最佳实践和注意事项,为读者提供进一步学习的资源。情感分析(Sentiment Analysis),也称为意见挖掘,是自然语言处理(NLP)的一个分支。

SuperAGI2025 1146

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 从epoll构建muduo-7 加入IMuduoUser
下一篇: 从epoll构建muduo-9 加入onWriteComplate回调和Buffer
voidccc
博客等级 码龄14年 149粉丝 28原创
评论 5
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值