Git Product home page Git Product logo

muduo's Issues

time的例子有个小问题

examples/simple/timeclient/timeclient.cc
第61行:

Timestamp ts(time * Timestamp::kMicroSecondsPerSecond);

显示时间有问题,server回射的时间是19691231
做了以下修改:

Timestamp ts(implicit_cast<uint64_t>(time) * Timestamp::kMicroSecondsPerSecond);

时间就正常显示了。

ASIO_CHAT example problem

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?

handleClosed可能导致服务端的数据不能完整的发送到客户端?

如果客户端调用shutdown关闭写,服务端handleRead将读取到0,并调用handleClose。 而handleClose中会调用channel_->disableAll(); 停止监听该TcpConnection上的所有事件(包括POLLOUT)。并且最后的closeCallback_(guardThis);将会把channel从eventloop中移除。 如果这时TcpConnection还有数据在outputBuffer_中,那么这些在buf中的数据将没有机会发送到客户端了。

ERROR Protocol not available (errno=92) SO_REUSEPORT failed. - Socket.cc:112

代码:

include <muduo/net/EventLoop.h>

include <muduo/net/TcpServer.h>

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

CHECK_NOTNULL conflict

CHECK_NOTNULL in muduo/base/Logging.h conflicts with CHECK_NOTNULL in Google's glog library.

Maybe change to MUDUO_CHECK_NOTNULL?

UDP Support

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:

  • Do you plan do support UDP ? I have only seen TCP, but as I said, I took a quick look
  • Do you think your project would make sense in a Mobile, Massive, Multi-player Online Game ? As I think it would be so (if UDP support is planned), I would like it to be confirmed by someone more familiar with this project :-)

Thanks in advance for your feedback.

Stephane Gleizes

maybe we should add TcpServer::stop

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?

void ThreadPool::stop() 有可能导致函数队列内的函数不能完全执行完

void ThreadPool::stop() 函数通知(条件变量)所有线程,running_ 已经为 false,
等待的线程执行完当前绑定的函数后,会退出。
for_each(threads_.begin(),threads_.end(),boost::bind(&muduo::Thread::join, _1));
使用 pthread_join 去确认线程完全退出。
退出的条件是:
void ThreadPool::runInThread() 函数结束。
所以,有可能导致函数队列里面要执行的函数有些没有执行完成。
所以,应该确保送到线程池内执行的函数,都是非阻塞,或者能安全退出(超时,无异常)的函数。

1.0.0编译出错

系统: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

Support Mac OSX?

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

include <ext/vstring.h>

Acceptor.cc里面的Acceptor::Acceptor构造函数内setReadCallback问题

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 更好吧。

Socket are not closing properly

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)

muduo 1.0.0 编译出现错误

thirdparty/muduo-1.0.0/muduo/net/boilerplate.cc:10:35: fatal error: muduo/net/BoilerPlate.h: No such file or directory

都应该是小写的啊

I7的CPU(PC)编译的muduo程序,在E5(服务器)系列上运行发生SIGILL

#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)

muduo-master/examples/asio/chat 里面的./asio_chat_client 进入死循环

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

测试过程如下:

  1. 使用了 nginx 的TCP反向代理插件,https://github.com/yaoweibin/nginx_tcp_proxy_module
  2. 配置了 nginx 的 TCP 反向代理后,开始启动服务测试。
  3. 启动 asio_chat_server
  4. 启动 nginx
  5. 启动 asio_chat_client,发送数据,一切正常.
  6. 然后把 nginx 关闭或者重启(../sbin/nginx -s reload;../sbin/nginx -s reopen)
    ,重新把 nginx 起来,asio_chat_client 再发送数据进入了死循环。
  7. 就是关闭 asio_chat_client ,再起来,也一直是死循环。需要过了nginx 的自检时间,
    也就是过了 nginx 和 asio_chat_server 的检查时间才能正常。

v1.04 加入 protocol buffer 2.5 后编译失败,找不到 pb 可以成功。

加入 protocol buffer 2.5 后编译失败
环境:centos 6.3(64位),gcc 4.4.6,cmake 3.0

  1. 因为 /usr/local/protocol-2.5-m64 安装的路径不是默认路径,所以增加了变量
    set(PROTOBUF_LIBRARY "/usr/local/protocol-2.5-m64/lib")
    set(PROTOBUF_INCLUDE_DIR "/usr/local/protocol-2.5-m64/include")
    运行 build.sh 后失败,还是找不到 include 目录。
    后面修改
    if(PROTOBUF_FOUND)
    message(STATUS "found protobuf")
    include_directories(${PROTOBUF_INCLUDE_DIR})
    link_directories(${PROTOBUF_LIBRARY})
    endif()
    这段后,编译正常了。
  2. 中途出现找不到 protoc 这个可执行文件,这个需要设置一下 系统环境变量 PATH
    ,当然,最好是有个这样的变量最好 PROTOBUF_BIN,这个可能需要 cmake 修改了。
  3. gcc 4.4.6下编译有出现
    错误:‘int’转换自‘long int’时可能改变值
    这个是 CXX_FLAGS 参数里面 -Wconversion 设置严格,可以考虑去掉。

TcpConnection::handleRead中readFd为0时,增加一次messageCallback_调用?

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();
  }
}

这几个diff文件都不能apply了

我使用的是git apply armlinux.diff的,但是patch失败,clang的也patch不了,然后armlinux.diff即使patch成功了也不能直接在raspberry pi上用成功吧,默认的c++ compiler还是g++而不是arm-g++

misusing StringPiece

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.

Linker error in Mac

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:

include

include <muduo/net/EventLoop.h>

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)

muduo coredump

客户端模式下并发想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

公网环境 or 内网环境?

HI,你在文档中提及,这个库只适合内网环境,那么你所定义的内网和公网环境下,具体有些什么区别呢?

不停发送数据的问题

如果服务器不停发数据给客户端(比如传输大文件),客户端没有崩溃断开连接,但是就是不收取数据,会不会把服务器端的Buffer撑爆了? 看你muduo书里也没讲这一部分内容。

Build error: protoc: not found

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

Singleton 'no_destroy'编译错误

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

源码编译版本 cmake version 2.8.12.2 编译不通过

操作系统 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)

如何安全地析构TcpClient

代码如下

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来避免竞争。

Connector.cc 中断言有误

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_)吧?

muduo installation on Mac

gardenia:muduo zhouchao$ ./build.sh
++ pwd

  • SOURCE_DIR=/Users/zhouchao/workspace/muduo
  • BUILD_DIR=../build
  • BUILD_TYPE=debug
  • INSTALL_DIR=../debug-install
  • BUILD_NO_EXAMPLES=0
  • mkdir -p ../build/debug
  • cd ../build/debug
  • cmake -DCMAKE_BUILD_TYPE=debug -DCMAKE_INSTALL_PREFIX=../debug-install -DCMAKE_BUILD_NO_EXAMPLES=0 /Users/zhouchao/workspace/muduo
    -- Boost version: 1.49.0
    -- Could NOT find PROTOBUF (missing: PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR)
    -- CXX_FLAGS = -g -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Werror -Wconversion -Wno-unused-parameter -Wold-style-cast -Woverloaded-virtual -Wpointer-arith -Wshadow -Wwrite-strings -march=native -rdynamic -O0
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /Users/zhouchao/workspace/build/debug
  • make
    [ 0%] Building CXX object muduo/base/CMakeFiles/muduo_base.dir/AsyncLogging.cc.o
    /Users/zhouchao/workspace/muduo/muduo/base/AsyncLogging.cc:1: error: bad value (native) for -march= switch
    /Users/zhouchao/workspace/muduo/muduo/base/AsyncLogging.cc:1: error: bad value (native) for -mtune= switch
    make[2]: *** [muduo/base/CMakeFiles/muduo_base.dir/AsyncLogging.cc.o] Error 1
    make[1]: *** [muduo/base/CMakeFiles/muduo_base.dir/all] Error 2
    make: *** [all] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.