一、木鐸
木鐸是一款開放源代碼C++網路庫,它提供了高效的並發和非同步網路編程介面。它是一個基於Reactor模式的網路庫,採用了Pimpl技術來避免頭文件的相互依賴。它是一款輕量級的網路庫,僅依賴於Boost C++庫。
二、沐朵so奶咖減肥產品能瘦嗎
沐朵so奶咖減肥產品和Muduo網路庫沒有直接的聯繫。
三、木鐸金聲
木鐸提供了多種組件,其中EventLoop是最為核心的組件,其創建了一個線程池和一個EventLoop對象池,將文件描述符上的IO事件通過Epoll機制轉發給對應的事件處理器(Channel)。EventLoop、Channel、Epoll都是多線程程序中非常重要的組件,Muduo網路庫的架構非常經典。
class EventLoop : noncopyable { public: typedef std::function 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 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 poller_; std::unique_ptr timerQueue_; int wakeupFd_; // unlike in TimerQueue, which is an internal class, // we don't expose Channel to client. std::unique_ptr wakeupChannel_; boost::any context_; ChannelList activeChannels_; Channel* currentActiveChannel_; mutable MutexLock mutex_; std::vector 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 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(data_ - arr); } } explicit SourceFile(const char* filename) : data_(filename) { const char* slash = strrchr(filename, '/'); if (slash) { data_ = slash + 1; } size_ = static_cast(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 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網路庫是一款經典、高性能、輕量級的網路庫,並且提供了很多優秀的組件、工具類庫和非同步網路編程介面,它的源碼對於對多線程、網路編程、經典網路庫的實現感興趣的開發者來說,是一份優秀的參考和學習資料。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/194620.html