一、木铎
木铎是一款开放源代码C网络库,它提供了高效的并发和异步网络编程接口。它是一个基于Reactor模式的网络库,采用了Pimpl技术来避免头文件的相互依赖。它是一款轻量级的网络库,仅依赖于Boost C库。
二、沐朵so奶咖减肥产品能瘦吗
沐朵so奶咖减肥产品和Muduo网络库没有直接的联系。
三、木铎金声
木铎提供了多种组件,其中EventLoop是最为核心的组件,其创建了一个线程池和一个EventLoop对象池,将文件描述符上的IO事件通过Epoll机制转发给对应的事件处理器(Channel)。EventLoop、Channel、Epoll都是多线程程序中非常重要的组件,Muduo网络库的架构非常经典。
class EventLoop : noncopyable {
public:
typedef std::function<void()> Functor;
EventLoop();
~EventLoop();
void loop();
void quit();
Timestamp pollReturnTime() const { return pollReturnTime_; }
int64_t iteration() const { return iteration_; }
void runInLoop(Functor cb);
void queueInLoop(Functor cb);
TimerId runAt(const Timestamp& time, TimerCallback cb);
TimerId runAfter(double delay, TimerCallback cb);
TimerId runEvery(double interval, TimerCallback cb);
void cancel(TimerId timerId);
void wakeup();
void updateChannel(Channel* channel);
void removeChannel(Channel* channel);
bool hasChannel(Channel* channel);
void assertInLoopThread() {
if (!isInLoopThread()) {
abortNotInLoopThread();
}
}
bool isInLoopThread() const { return threadId_ == CurrentThread::tid(); }
bool eventHandling() const { return eventHandling_; }
void setContext(const boost::any& context) {
context_ = context;
}
const boost::any& getContext() const { return context_; }
boost::any* getMutableContext() { return &context_; }
static EventLoop* getEventLoopOfCurrentThread();
private:
void abortNotInLoopThread();
void handleRead();
void doPendingFunctors();
void printActiveChannels() const; // DEBUG
typedef std::vector<Channel*> ChannelList;
bool looping_; /* atomic */
bool quit_; /* atomic */
bool eventHandling_; /* atomic */
bool callingPendingFunctors_; /* atomic */
int64_t iteration_;
const pid_t threadId_;
Timestamp pollReturnTime_;
std::unique_ptr<EpollPoller> poller_;
std::unique_ptr<TimerQueue> timerQueue_;
int wakeupFd_;
// unlike in TimerQueue, which is an internal class,
// we don't expose Channel to client.
std::unique_ptr<Channel> wakeupChannel_;
boost::any context_;
ChannelList activeChannels_;
Channel* currentActiveChannel_;
mutable MutexLock mutex_;
std::vector<Functor> pendingFunctors_;
};
四、母多少笔画
“母”字笔画为五画,和Muduo网络库没有直接关系。
五、木铎之心
Muduo网络库的作者是Chen Shuo,在此之前,他开发了Hawdjon,一款聚焦并发编程对C++11标准库进行封装的库,并在Hawdjon的基础上,最终编写了Muduo网络库。
六、目多读什么
Muduo网络库适合对高性能网络编程感兴趣的开发者阅读,关注网络编程、多线程编程实现的细节和经验。
七、木铎有心
Muduo网络库提供了很多高性能的类库,如内存池,日志组件,可重入包装、时间戳和定时器等等工具类库。在日志库方面,Muduo提供了对异步、基于线程的文件输出,和基于UDP输出日志的两种输出方式,这些输出方式都可以按照不同优先级级别挂载到Logger对象中,并且提供了对日志文件的自动分割机制。
class Logger : noncopyable {
public:
enum LogLevel {
TRACE,
DEBUG,
INFO,
WARN,
ERROR,
FATAL,
NUM_LOG_LEVELS,
};
// compile time calculation of basename of source file
class SourceFile {
public:
template <int n>
inline SourceFile(const char (&arr)[N])
: data_(arr),
size_(N - 1) {
const char* slash = strrchr(data_, '/'); // builtin function
if (slash) {
data_ = slash + 1;
size_ -= static_cast<int>(data_ - arr);
}
}
explicit SourceFile(const char* filename)
: data_(filename) {
const char* slash = strrchr(filename, '/');
if (slash) {
data_ = slash + 1;
}
size_ = static_cast<int>(strlen(data_));
}
const char* data_;
int size_;
};
Logger(SourceFile file, int line);
Logger(SourceFile file, int line, LogLevel level);
Logger(SourceFile file, int line, LogLevel level, const char* func);
Logger(SourceFile file, int line, bool toAbort);
~Logger();
static LogLevel logLevel();
static void setLogLevel(LogLevel level);
static void setOutput(OutputFunc);
static void setFlush(FlushFunc);
static void setTimeZone(const TimeZone& tz);
// FIXME: replace fixed array with dynamic allocation
typedef FixedBuffer<KSmallBuffer> Buffer;
void finish();
// no copyable
Logger(const Logger&) = delete;
Logger& operator=(const Logger&) = delete;
Logger(Logger&&) = default;
Logger& operator=(Logger&&) = default;
// Eg. LOG_INFO << "Hello world";
static void log(SourceFile file, int line, LogLevel level, const char* fmt, ...);
static void formatLog(const char* fmt, va_list ap, Buffer& buf, LogLevel level);
private:
class Impl {
public:
typedef Logger::LogLevel LogLevel;
Impl(LogLevel level, int old_errno, const SourceFile& file, int line);
void formatTime();
void finish();
Timestamp time_;
LogStream stream_;
LogLevel level_;
int line_;
SourceFile basename_;
};
Impl impl_;
};
#define LOG_TRACE if (muduo::Logger::logLevel() <= muduo::Logger::TRACE) \
muduo::Logger(__FILE__, __LINE__, muduo::Logger::TRACE, __func__).stream()
#define LOG_DEBUG if (muduo::Logger::logLevel() <= muduo::Logger::DEBUG) \
muduo::Logger(__FILE__, __LINE__, muduo::Logger::DEBUG, __func__).stream()
#define LOG_INFO if (muduo::Logger::logLevel() <= muduo::Logger::INFO) \
muduo::Logger(__FILE__, __LINE__).stream()
#define LOG_WARN muduo::Logger(__FILE__, __LINE__, muduo::Logger::WARN).stream()
#define LOG_ERROR muduo::Logger(__FILE__, __LINE__, muduo::Logger::ERROR).stream()
#define LOG_FATAL muduo::Logger(__FILE__, __LINE__, muduo::Logger::FATAL).stream()
#define LOG_SYSERR muduo::Logger(__FILE__, __LINE__, false).stream()
#define LOG_SYSFATAL muduo::Logger(__FILE__, __LINE__, true).stream()
八、母多少画
“母”字笔画为五画,和Muduo网络库没有直接关系。
九、木铎什么意思
据网络上的资料,Muduo是“基于Linux操作系统MULtiple DOor的一种高性能C++服务器开发框架”。 总体来说,Muduo网络库是一款经典、高性能、轻量级的网络库,并且提供了很多优秀的组件、工具类库和异步网络编程接口,它的源码对于对多线程、网络编程、经典网络库的实现感兴趣的开发者来说,是一份优秀的参考和学习资料。