• 欢迎浏览“String me = Creater\忠实的资深Linux玩家;”,请文明浏览,理性发言,有侵犯你的权益请邮件我(creater@vip.qq.com).
  • 把任何的失败都当作一次尝试,不要自卑;把所有的成功都想成是一种幸运,不要自傲。
  •    5年前 (2013-07-01)  Socket library |   6 条评论  13 
    文章评分 0 次,平均分 0.0

    这是我最近阅读的一个开源项目,但是我发现一个BUG,所以向作者提交了该问题。

    Thank you very much!
    I will try to recreate your problem with using the standard SocketHandlerEp class. I have
    only myself used it as a base class for specialized handlers, so there is a problem left to
    be discovered!
    Best regards
    /ah

    On Sat, Jul 6, 2013 at 5:23 AM, Unix8.net,Unix吧 wrote:
    Dear autor!
    When I read the source of "C++ Socket Library", i wirted a test, but have a "Segmentation fault" error.

    When i use SocketHandler as the handler, there is no error.
    When i write a class which inherit from SocketHandlerEp as the handler, there is no error.
    When i use SocketHandlerEp as the handler, there is a fatal error.

    【I am a Chinese person, please forgive my English is not good】

    Code:

    #include <stdio.h>
    #include <SocketHandler.h>
    #include <SocketHandlerEp.h>
    #include <TcpSocket.h>
    #include <Mutex.h>
    #include <StdoutLog.h>
    #include <ListenSocket.h>
    #include <Lock.h>
    
    
    class MyHandler;
    class InfoSocket : public TcpSocket
    {
    public:
    	InfoSocket(ISocketHandler& h) : TcpSocket(h) {}
    	~InfoSocket() {}
    
    	void OnAccept() {
    		printf("Accept\n");
    	}
    
    	//Don't use OnRawData
    	void OnRead()
    	{
    		TcpSocket::OnRead();
    		size_t n = ibuf.GetLength();
    		printf("ibuf have %d bytes\n", n);
    		if (n > 0)
    		{
    			char tmp[100];
    			ibuf.Read(tmp,n);
    			printf("Read %d bytes:\n",n);
    			for (size_t i = 0; i < n; i++)
    			{
    				printf("%c",isprint(tmp[i]) ? tmp[i] : '.');
    			}
    			printf("\n");
    
    		}
    	}
    };
    
    class MyHandler : public SocketHandlerEp
    {
    public:
    	MyHandler(IMutex& m,StdoutLog *p) : SocketHandlerEp(m, p) {}
    	~MyHandler() {}
    };
    
    // use SocketHandlerEp
    #define TEST_SOCKETHANDLEREP
    
    //use SocketHandler
    //#define TEST_SOCKETHANDLER
    
    //use MyHandler, inherit SocketHandlerEp or SocketHandler
    //#define TEST_INHERIT_SOCKETHANDLEREP
    
    
    int main(int argc,char *argv[])
    {
    	Mutex lock;
    	StdoutLog log;
    
    #if  defined(TEST_SOCKETHANDLEREP)
    	SocketHandlerEp h(lock, &log);
    #elif defined(TEST_SOCKETHANDLER)
    	SocketHandler h(lock, &log);
    #elif defined(TEST_INHERIT_SOCKETHANDLEREP)
    	MyHandler h(lock, &log);
    #endif
    
    	ListenSocket<InfoSocket> l(h);
    	if (l.Bind(11002))
    	{
    		printf("Bind() failed\n");
    		exit(-2);
    	}
    	h.Add(&l);
    	
    	bool quit = false;
    	while (!quit)
    	{
    		h.Select(1, 0);
    	}
    }
    

    When I debug found that cause of the error is "m_mutex.Lock()".

    Thank you!
    Best Regards!
    2013-07-06

     

    除特别注明外,本站所有文章均为String me = "Creater\忠实的资深Linux玩家";原创,转载请注明出处来自http://unix8.net/home.php/1674.html

    关于

    发表评论

    暂无评论

    切换注册

    登录

    忘记密码 ?

    切换登录

    注册

    扫一扫二维码分享