chenshuo / muduo Goto Github PK
View Code? Open in Web Editor NEWEvent-driven network library for multi-threaded Linux server in C++11
Home Page: https://github.com/chenshuo/muduo
License: Other
Event-driven network library for multi-threaded Linux server in C++11
Home Page: https://github.com/chenshuo/muduo
License: Other
Muduo is a multithreaded C++ network library based on the reactor pattern. http://github.com/chenshuo/muduo Copyright (c) 2010, Shuo Chen. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the License file. Requires: Linux kernel version >= 2.6.28. GCC >= 4.7 or Clang >= 3.5 Boost (for boost::any only.) Tested on: Debian 7 and above Unbuntu 14.04 and above CentOS 7 and above Install required packages: # Debian, Ubuntu, etc. $ sudo apt install g++ cmake make libboost-dev # CentOS $ sudo yum install gcc-c++ cmake make boost-devel See .travis.yml for additional packages for building more examples. To build, run: ./build.sh See https://github.com/chenshuo/muduo-tutorial for how to use muduo in your project. __ __ _ | \/ | | | | \ / |_ _ __| |_ _ ___ | |\/| | | | |/ _` | | | |/ _ \ | | | | |_| | (_| | |_| | (_) | |_| |_|\__,_|\__,_|\__,_|\___/
在例子pingpong/bench.cc中,g_channels使用完毕后,它每个成员所指向的channel对象没有进行diableAll和remove操作,析构的时候~Channel()里的assert失败导致程序abort。
It's unsafe to use StringPiece::data() directly in functions that expect null-terminated string, like fopen(), since the actual string may contain more characters than size(), or even not be null-terminated
I think StringPiece should be only used in performance-critical code, because people
tempts to write code like below:
fopen(name.data(), "rb"); // name is a StringPiece
This code works perfectly most time, but fails because you want to pick the filename from a bigger StringPiece, like an html document.
I patched clang.diff and MacOSX.diff, then ./build.sh -j2 and ./build.sh install, and many errors occur, so my question is Muduo is support OSX?
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:22:5: error: expected
function body after function declarator
THROW __attribute ((noreturn));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:57:5: error: use of
undeclared identifier 'assert_perror_fail'
MCHECK(pthread_mutex_init(&mutex_, NULL));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:63:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_mutex_destroy(&mutex));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:81:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_mutex_lock(&mutex));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:88:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_mutex_unlock(&mutex));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.cc:1:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.h:4:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/BlockingQueue.h:9:
/Users/apple/Desktop/muduo-master/muduo/base/Condition.h:23:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_cond_init(&pcond, NULL));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.cc:1:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.h:4:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/BlockingQueue.h:9:
/Users/apple/Desktop/muduo-master/muduo/base/Condition.h:28:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_cond_destroy(&pcond));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.cc:1:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.h:4:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/BlockingQueue.h:9:
/Users/apple/Desktop/muduo-master/muduo/base/Condition.h:34:5: error: use of
undeclared identifier 'assert_perror_fail'
MCHECK(pthread_cond_wait(&pcond, mutex.getPthreadMutex()));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.cc:1:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.h:4:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/BlockingQueue.h:9:
/Users/apple/Desktop/muduo-master/muduo/base/Condition.h:42:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_cond_signal(&pcond));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, LINE_...
^
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.cc:1:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.h:4:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/BlockingQueue.h:9:
/Users/apple/Desktop/muduo-master/muduo/base/Condition.h:47:5: error: use of
undeclared identifier '_assert_perror_fail'
MCHECK(pthread_cond_broadcast(&pcond));
^
/Users/apple/Desktop/muduo-master/muduo/base/Mutex.h:28:26: note: expanded from
macro 'MCHECK'
__assert_perror_fail (errnum, __FILE, _LINE...
^
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.cc:1:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/AsyncLogging.h:8:
In file included from /Users/apple/Desktop/muduo-master/muduo/base/Thread.h:10:
/Users/apple/Desktop/muduo-master/muduo/base/Types.h:8:10: fatal error:
'ext/vstring.h' file not found
gardenia:muduo zhouchao$ ./build.sh
++ pwd
https://travis-ci.org/trymuduo/muduo/jobs/36501811
https://travis-ci.org/trymuduo/muduo/jobs/36501815
seems to be the problem of hiredis api
How to build and run muduo on eclipse? Thank you!
代码:
int main()
{
muduo::net::EventLoop loop;
muduo::net::InetAddress listenAddr(2007);
muduo::net::TcpServer server(&loop, listenAddr, "test");
return 0;
}
运行报错ERROR Protocol not available (errno=92) SO_REUSEPORT failed. - Socket.cc:112。
内核版本:
root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
几次更新都是例子更新,核心块很少变化了。
加入 protocol buffer 2.5 后编译失败
环境:centos 6.3(64位),gcc 4.4.6,cmake 3.0
chenshuo你好,
是否可以在TcpConnection::handleRead中,当readFd返回0,调用handleClose前,多调用一次messageCallback_?这样用户在messageCallback_可以感知到对方已经关闭了连接(比如判断buffer的readable bytes为0),可以做些特殊处理。因为TcpServer用户没法设置close callback。不知道我这个想法是否合适?请硕哥评判下,谢谢。
void TcpConnection::handleRead(Timestamp receiveTime)
{
loop_->assertInLoopThread();
int savedErrno = 0;
ssize_t n = inputBuffer_.readFd(channel_->fd(), &savedErrno);
if (n > 0)
{
messageCallback_(shared_from_this(), &inputBuffer_, receiveTime);
}
else if (n == 0)
{
messageCallback_(shared_from_this(), &inputBuffer_, receiveTime); // 增加一次调用
handleClose();
}
else
{
errno = savedErrno;
LOG_SYSERR << "TcpConnection::handleRead";
handleError();
}
}
Here, i met a build error, whose error message is displayed as follow:
[ 46%] Built target zlibstream_unittest
[ 46%] Built target muduo_protobuf_codec
[ 46%] Built target muduo_protobuf_codec_cpp11
[ 46%] Generating rpc.pb.cc, rpc.pb.h
/bin/sh: 1: protoc: not found
make[2]: *** [muduo/net/protorpc/rpc.pb.cc] Error 127
make[1]: *** [muduo/net/protorpc/CMakeFiles/muduo_protorpc_wire.dir/all] Error 2
make: *** [all] Error 2
It seems not helpful to install libprotoc-dev
Here is my environment:
Linux ubuntu 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 16:19:23 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
代码如下
int main(int argc, char* argv[])
{
{
EventLoopThread thread;
EventLoop* loop = thread.startLoop();
TcpClient client(loop, InetAddress(9982), "client");
client.connect();
// waiting for connect
usleep(1000);
client.disconnect();
}
usleep(1000 * 1000);
return 0;
}
20140929 08:22:58.727901Z 9259 INFO TcpClient::TcpClient[client] - connector 0x18A0860 - TcpClient.cc:71
20140929 08:22:58.727965Z 9259 INFO TcpClient::connect[client] - connecting to 0.0.0.0:9982 - TcpClient.cc:109
20140929 08:22:58.729087Z 9259 INFO TcpClient::~TcpClient[client] - connector 0x18A0860 - TcpClient.cc:77
client: muduo/net/Channel.cc:61: void muduo::net::Channel::remove(): Assertion `isNoneEvent()' failed.
看在https://github.com/chenshuo/muduo/blob/master/examples/asio/chat/client.cc#L98 用sleep来避免竞争。
examples/simple/timeclient/timeclient.cc
第61行:
Timestamp ts(time * Timestamp::kMicroSecondsPerSecond);
显示时间有问题,server回射的时间是19691231
做了以下修改:
Timestamp ts(implicit_cast<uint64_t>(time) * Timestamp::kMicroSecondsPerSecond);
时间就正常显示了。
HI,你在文档中提及,这个库只适合内网环境,那么你所定义的内网和公网环境下,具体有些什么区别呢?
void ThreadPool::stop() 函数通知(条件变量)所有线程,running_ 已经为 false,
等待的线程执行完当前绑定的函数后,会退出。
for_each(threads_.begin(),threads_.end(),boost::bind(&muduo::Thread::join, _1));
使用 pthread_join 去确认线程完全退出。
退出的条件是:
void ThreadPool::runInThread() 函数结束。
所以,有可能导致函数队列里面要执行的函数有些没有执行完成。
所以,应该确保送到线程池内执行的函数,都是非阻塞,或者能安全退出(超时,无异常)的函数。
I have looked at a few source files for your current software. I have noticed that some checks for return codes are missing.
Would you like to add more error handling for return values from functions like the following?
Are any more improvements possible since the previous request?
CHECK_NOTNULL in muduo/base/Logging.h conflicts with CHECK_NOTNULL in Google's glog library.
Maybe change to MUDUO_CHECK_NOTNULL?
如果服务器不停发数据给客户端(比如传输大文件),客户端没有崩溃断开连接,但是就是不收取数据,会不会把服务器端的Buffer撑爆了? 看你muduo书里也没讲这一部分内容。
chenshuo你好,
我在单独使用和编译Singleton.h的Singleton 'no_destroy'相关代码时,遇到了如下的编译错误:
error: ISO C++ forbids in-class initialization of non-const static member 'test'
把下面这行代码:
template <typename C> static char test(typeof(&C::no_destroy)); // or decltype in C++11
修改为:
template <typename C> static char test(__typeof__(&C::no_destroy)); // or decltype in C++11
就能编译通过了。
我看到gnu文档里说:
”If you are writing a header file that must work when included in ISO C programs, write __typeof__ instead of typeof.“
搞不太明白编译失败的原因。代码是c++代码,centos,编译器是gcc 4.4.7
if EvenLoopThread don't call startLoop the loop is NULL, when the EvenLoopthread destroy a core will be caused.
请问如何编译arm版本啊
系统:ubuntu12.04
cmake版本:2.8.7
boost版本:1.53
gcc,g++版本:4.6.4
之前编译0.9.3版本没问题,按照编译说明,执行./build.sh -j2,报错如下(最后部分截取):
/usr/local/boost_1_53_0/boost/ptr_container/detail/move.hpp: 在构造函数‘boost::ptr_container_detail::move_ptrs::move_source::move_source(Ptr&) [with Ptr = boost::ptr_container_detail::static_move_ptrmuduo::detail::FixedBuffer<4000000, boost::ptr_container_detail::clone_deleterboost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<muduo::detail::FixedBuffer<4000000, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_clone_allocator > >]’中:
/usr/local/boost_1_53_0/boost/ptr_container/detail/move.hpp:39:37:自‘boost::ptr_container_detail::move_ptrs::move_source boost::ptr_container_detail::move(T&) [with T = boost::ptr_container_detail::static_move_ptrmuduo::detail::FixedBuffer<4000000, boost::ptr_container_detail::clone_deleterboost::ptr_container_detail::reversible_ptr_container<boost::ptr_container_detail::sequence_config<muduo::detail::FixedBuffer<4000000, std::vector<void*, std::allocator<void*> > >, boost::heap_clone_allocator>::null_clone_allocator > >]’实例化
/home/sourcetest/muduo/muduo/base/AsyncLogging.cc:42:62:从此处实例化
/usr/local/boost_1_53_0/boost/ptr_container/detail/move.hpp:23:5: 错误: ‘ptr’的声明隐藏了‘this’的一个成员 [-Werror=shadow]
cc1plus: all warnings being treated as errors
make[2]: *** [muduo/base/CMakeFiles/muduo_base_cpp11.dir/AsyncLogging.cc.o] 错误 1
make[2]: *** 正在等待未完成的任务....
make[1]: *** [muduo/base/CMakeFiles/muduo_base_cpp11.dir/all] 错误 2
make: *** [all] 错误 2
muduo-master/examples/asio/chat
里面的./asio_chat_client 进入死循环。看到客户端表现如下,不断的重新连接。
20150323 10:03:38.336293Z 6660 INFO 169.254.10.12:34128 -> 169.254.10.12:26888 is UP - client.cc:53
20150323 10:03:38.336324Z 6660 INFO 169.254.10.12:34128 -> 169.254.10.12:26888 is DOWN - client.cc:53
20150323 10:03:38.857066Z 6660 INFO TcpClient::connect[ChatClient] - Reconnecting to 169.254.10.12:26888 - TcpClient.cc:178
20150323 10:03:38.857196Z 6660 INFO 169.254.10.12:34130 -> 169.254.10.12:26888 is UP - client.cc:53
20150323 10:03:38.857328Z 6660 INFO 169.254.10.12:34130 -> 169.254.10.12:26888 is DOWN - client.cc:53
20150323 10:03:38.857345Z 6660 INFO TcpClient::connect[ChatClient] - Reconnecting to 169.254.10.12:26888 - TcpClient.cc:178
测试过程如下:
我使用的是git apply armlinux.diff的,但是patch失败,clang的也patch不了,然后armlinux.diff即使patch成功了也不能直接在raspberry pi上用成功吧,默认的c++ compiler还是g++而不是arm-g++
Hi Chen,
I took a quick look at you project and so far it appears to me as a very promising one.
I'm currently working on a MMO server for a mobile game, which would obviously need to use UDP for its network interface impl. So far I have two questions:
Thanks in advance for your feedback.
Stephane Gleizes
根据你blog http://blog.csdn.net/solstice/article/details/26363901 中描述的“muduo 的 C1000k 实验”,请问,客户端绑定10个IP,这方面的客户端代码在哪里啊?能share一下么?
我看现在的muduo代码中TcpClient没有提供绑定ip接口。
非常感谢!
RT,代码里只有network到 大端的转换
acceptChannel_.setReadCallback(boost::bind(&Acceptor::handleRead, this));
其中对象实例acceptChannel_属于Channel,setReadCallback函数声明是
void Channel::setReadCallback(const ReadEventCallback& cb);
但是 Acceptor::handleRead 是无参数的声明和定义
void Acceptor::handleRead();
按理
acceptChannel_.setReadCallback(boost::bind(&Acceptor::handleRead, this));
应该增加 std::placeholders::_1 更好吧。
在Singleton类中的init函数中的::atexit(destroy)如果调用失败呢?那么资源就可能出现泄漏了。我觉得如果使用一个内部的Gc类来实现回收资源可能更加的好~
Hi,giant.chen:
Programs which have many services,may need the ability to start and stop every single service.For now ,the only way to stop a TcpServer is to stop the loop,this may not be a problem when one loop only support one Tcpserver.But i think different TcpServer attach on one loop is need,so TcpServer::stop may be needed.
Your idea?
当短时间内进行多次EventLoop::wakeup()操作, 会阻塞在write上.
客户端模式下并发想Server发起请求的时候会coredump,具体信息见下面
#0 0x0000003a85e328a5 in raise () from /lib64/libc.so.6
#1 0x0000003a85e34085 in abort () from /lib64/libc.so.6
#2 0x0000003a85e2ba1e in __assert_fail_base () from /lib64/libc.so.6
#3 0x0000003a85e2bb40 in __assert_perror_fail () from /lib64/libc.so.6
#4 0x000000000041a871 in lock (this=0x65d6a0, conn=...) at /home/project/muduo/muduo/base/Mutex.h:81
#5 MutexLockGuard (this=0x65d6a0, conn=...) at /home/project/muduo/muduo/base/Mutex.h:143
#6 muduo::net::TcpClient::removeConnection (this=0x65d6a0, conn=...) at /home/project/muduo/muduo/net/TcpClient.cc:170
#7 0x000000000041fc89 in operator() (this=0x2b2f540047c0) at /usr/include/boost/function/function_template.hpp:1013
#8 muduo::net::TcpConnection::handleClose (this=0x2b2f540047c0) at /home/project/muduo/muduo/net/TcpConnection.cc:372
#9 0x000000000041ffb8 in muduo::net::TcpConnection::handleRead (this=0x2b2f540047c0, receiveTime=...) at /home/project/muduo/muduo/net/TcpConnection.cc:310
#10 0x00000000004280f9 in operator() (this=0x2b2f54004970, receiveTime=) at /usr/include/boost/function/function_template.hpp:1013
#11 muduo::net::Channel::handleEventWithGuard (this=0x2b2f54004970, receiveTime=) at /home/project/muduo/muduo/net/Channel.cc:107
#12 0x0000000000428479 in muduo::net::Channel::handleEvent (this=0x2b2f54004970, receiveTime=) at /home/project/muduo/muduo/net/Channel.cc:79
#13 0x00000000004146b5 in muduo::net::EventLoop::loop (this=0x2b2f4c3f09d0) at /home/project/muduo/muduo/net/EventLoop.cc:125
#14 0x000000000042b503 in muduo::net::EventLoopThread::threadFunc (this=0x648ff0) at /home/project/muduo/muduo/net/EventLoopThread.cc:72
#15 0x000000000042ff41 in operator() (this=0x649130) at /usr/include/boost/function/function_template.hpp:1013
#16 muduo::detail::ThreadData::runInThread (this=0x649130) at /home/project/muduo/muduo/base/Thread.cc:94
#17 0x000000000042fd4e in muduo::detail::startThread (obj=) at /home/project/muduo/muduo/base/Thread.cc:124
#18 0x0000003a86207851 in start_thread () from /lib64/libpthread.so.0
#19 0x0000003a85ee767d in clone () from /lib64/libc.so.6
Mutex析构函数中的断言失败只要调用Condition::wait.是否UnassignGuard中的unassignHolder和assignHolder调用顺序有问题?
I run asio chat example on Debian 7.4,gcc 4.7.2. I run one chat server, and two chat client in it. I use one of the client to send messages and both of the client can receive messages. And then I add the third chat client to this server, but it can not receive any messages. Any methods to repair it?
操作系统 centos-release-6-5.el6.centos.11.2.x86_64,源码编译版本 cmake version 2.8.12.2,编译时出现以下错误:
-- Boost version: 1.55.0
-- Looking for include file pthread.h
CMake Error at /usr/local/share/cmake-2.8/Modules/CheckIncludeFiles.cmake:58 (try_compile):
Unknown extension ".c" for file
/root/opensource/chenshuo/build/release/CMakeFiles/CMakeTmp/CheckIncludeFiles.c
try_compile() works only for enabled languages. Currently these are:
CXX
See project() command to enable other languages.
Call Stack (most recent call first):
/usr/local/share/cmake-2.8/Modules/FindThreads.cmake:39 (CHECK_INCLUDE_FILES)
/usr/local/share/cmake-2.8/Modules/FindProtobuf.cmake:162 (find_package)
/usr/local/share/cmake-2.8/Modules/FindProtobuf.cmake:204 (_protobuf_find_threads)
CMakeLists.txt:47 (find_package)
-- Looking for include file pthread.h - not found
-- Could NOT find Threads (missing: Threads_FOUND)
Built-in inspector is a very useful feature, and it will be nice to show commands as hyper-links, like:
proc/stats help string
proc/stats is a hyperlink, so user can click it directly.
比如我调用send之后,可否可以设置这个消息多久没有收到回复就超时的回调,谢谢~
错误见附件中的日志文件。
如果客户端调用shutdown关闭写,服务端handleRead将读取到0,并调用handleClose。 而handleClose中会调用channel_->disableAll();
停止监听该TcpConnection上的所有事件(包括POLLOUT)。并且最后的closeCallback_(guardThis);
将会把channel从eventloop中移除。 如果这时TcpConnection还有数据在outputBuffer_中,那么这些在buf中的数据将没有机会发送到客户端了。
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
OSX: 10.9.2
muduo: Version 1.0.1
I want to write a hello world, just like:
using namespace muduo;
using namespace muduo::net;
int main(int argc, const char * argv[])
{
// insert code here...
std::cout << "Hello, World!\n";
EventLoop loop;
loop.loop();
std::cout << "end\n";
return 0;
}
but linker error occurs:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::_1::char_traits, std::1::allocator >::compare(char const) const", referenced from:
muduo::detail::readTimeZoneFile(char const, muduo::TimeZone::Data) in libmuduo_base.a(TimeZone.cc.o)
"std::__1::__vector_base_common::__throw_length_error() const", referenced from:
void std::__1::vector<boost::function<void ()>, std::__1::allocator<boost::function<void ()> > >::__push_back_slow_path<boost::function<void ()> const>(boost::function<void ()> const&) in libmuduo_net.a(EventLoop.cc.o)
void std::__1::vector<std::_1::pair<muduo::Timestamp, muduo::net::Timer>, std::__1::allocator<std::__1::pair<muduo::Timestamp, muduo::net::Timer*> > >::__push_back_slow_path<std::__1::pair<muduo::Timestamp, muduo::net::Timer*> const>(std::__1::pair<muduo::Timestamp, muduo::net::Timer*> const&) in libmuduo_net.a(TimerQueue.cc.o)
void std::__1::vector<pollfd, std::__1::allocator >::__push_back_slow_path(pollfd const&) in libmuduo_net.a(PollPoller.cc.o)
void std::__1::vector<muduo::net::Channel*, std::__1::allocatormuduo::net::Channel* >::__push_back_slow_path<muduo::net::Channel* const>(muduo::net::Channel* const&) in libmuduo_net.a(PollPoller.cc.o)
void std::__1::vector<muduo::detail::Transition, std::__1::allocatormuduo::detail::Transition >::__push_back_slow_path<muduo::detail::Transition const>(muduo::detail::Transition const&) in libmuduo_base.a(TimeZone.cc.o)
void std::__1::vector<muduo::detail::Localtime, std::__1::allocatormuduo::detail::Localtime >::__push_back_slow_path<muduo::detail::Localtime const>(muduo::detail::Localtime const&) in libmuduo_base.a(TimeZone.cc.o)
void std::__1::vector<int, std::__1::allocator >::__push_back_slow_path(int const&) in libmuduo_base.a(TimeZone.cc.o)
I am have some sever based on muduo and after some time i get:
20150301 19:25:40.340338Z 8594 ERROR Too many open files (errno=24) in Acceptor::handleRead - Acceptor.cc:77
20150301 19:25:40.340362Z 8594 ERROR Too many open files (errno=24) in Socket::accept - SocketOps.cc:123
And the server dont accept more incoming connections (on error there was only 8 connected clients)
I have looked at a few source files for your current software. I have noticed that some checks for return codes are missing.
Would you like to add more error handling for return values from functions like the following?
在服务端RpcChannel和TcpConnection绑定,当TcpConnection断开的时候,RpcChannel被销毁,在这之后触发Callback会访问非法内存。
muduo doesn't parse http body right now...
void Connector::connecting(int sockfd)
{
setState(kConnecting);
assert(!channel_);
channel_.reset(new Channel(loop_, sockfd));
channel_->setWriteCallback(
boost::bind(&Connector::handleWrite, this)); // FIXME: unsafe
channel_->setErrorCallback(
boost::bind(&Connector::handleError, this)); // FIXME: unsafe
// channel_->tie(shared_from_this()); is not working,
// as channel_ is not managed by shared_ptr
channel_->enableWriting();
}
assert(!channel_) 应该是 assert(channel_ != NULL) 或 assert(channel_)吧?
#include <stdio.h>
#include <unistd.h>
#include <muduo/base/Types.h>
#include <muduo/base/Logging.h>
#include <boost/algorithm/string.hpp>
#include <muduo/net/TcpServer.h>
#include <muduo/net/EventLoop.h>
#include <muduo/net/InetAddress.h>
#include <muduo/net/Buffer.h>
#include <muduo/base/Timestamp.h>
#include <vector>
using namespace std;
using namespace muduo;
using namespace muduo::net;
#include <boost/bind.hpp>
using namespace boost::algorithm;
#include <stdio.h>
#include <time.h>
#include <errno.h>
class Svr
{
public:
Svr(EventLoop* loop,InetAddress& addr);
void Start();
void Stop();
void LogicLoop();
void OnConnected(const TcpConnectionPtr& conn);
void OnMessage(const TcpConnectionPtr& conn,Buffer* msg,Timestamp ts);
private:
TcpServer svr_;
};
Svr::Svr(EventLoop* loop,InetAddress& addr): svr_(loop,addr,"svr"){}
void Svr::Start()
{
svr_.setConnectionCallback(boost::bind(&Svr::OnConnected,this,_1));
svr_.setMessageCallback(boost::bind(&Svr::OnMessage,this,_1,_2,_3));
svr_.start();
svr_.getLoop()->runEvery(0.01f,boost::bind(&Svr::LogicLoop,this));
svr_.getLoop()->loop();
}
void Svr::Stop()
{
svr_.getLoop()->quit();
}
void Svr::LogicLoop()
{
static int i;
printf("loop...%d\n",++i);
}
void Svr::OnConnected(const TcpConnectionPtr& conn)
{
printf("Connected\n");
}
void Svr::OnMessage(const TcpConnectionPtr& conn,Buffer* msg,Timestamp ts)
{
printf("recv\n");
}
int main(int argc, char* argv[])
{
EventLoop loop;
InetAddress saport(8000);
Svr saac(&loop,saport);
saac.Start();
return 0;
}
SIGILL发生处:
Program received signal SIGILL, Illegal instruction.
0x00000000004037f8 in SaacSvr::Start() ()
Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6_5.2.x86_64 libgcc-4.4.7-11.el6.x86_64 libstdc++-4.4.7-11.el6.x86_64
(gdb)
(gdb)
(gdb)
(gdb) where
#0 0x00000000004037f8 in SaacSvr::Start() ()
#1 0x0000000000403990 in main ()
(gdb)
1、E5系列的服务器编译的demo在I7的PC上运行正常
2、I7的PC上编译的demo放在E5上则发生SIGILL
3、2个系统均为centos6.5 x86_64
4、g++版本为
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
thirdparty/muduo-1.0.0/muduo/net/boilerplate.cc:10:35: fatal error: muduo/net/BoilerPlate.h: No such file or directory
都应该是小写的啊
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.