websocketpp / boost:endpoint.get_connection(uri)上的SIGSEGV

时间:2012-05-30 12:01:11

标签: boost connection websocket sigsegv

我正在开发一个C ++的loadtest应用程序,用于测试我们的音频服务器的流媒体功能。对于这个客户端,我正在使用websocketpp并遵循此example

我总是在行中获得一个sigsegv

con = endpoint.get_connection(connection_string);
我的Workthread :: Work方法的

主应用程序在伪代码中看起来像这样

namespace blah
{
    TestmanagerClass::run()
    {
        start (additional) threads until limit n is reached;
        call workthread::work() method of each thread;
        handle finished threads;
        goto 1;
    }
}

这是WorkThread :: work(),我用伪代码替换了认证代码......

namespace blah {
void WorkThread::work()
{
    AudioStreamHandlerPtr handler(new AudioStreamHandler());
    websocketpp::client::connection_ptr con;
    websocketpp::client endpoint(handler);

    try
    {
        // authenticate
        // get login/access token from webservice

        if( !worksOutFine )
        {
            logError();
        }
        else
        { // got access token :D

            // now obtain session token from session service

            if( !worksOutFine )
            {
                logError();
            }
            else
            { // process this session's calls

                std::string connection_string = "ws://localhost";//boost::str(boost::format("ws://%1%/data?user_id=%2%&session_token=%3%") % serverAddressNoPort % session_.userId % sessionToken);
                std::cout << "CONNECTIONSTRING " << connection_string << std::endl;
                con = endpoint.get_connection(connection_string);
                std::cout << "1" << std::endl;
                endpoint.connect(con);
                std::cout << "2" << std::endl;
                boost::thread t(boost::bind(& websocketpp::client::run, &endpoint, false));
                more code....
}
}

连接字符串的输出是最后一个有用的东西。 “1”没有被发出,但是发生了sigsegv。

这是传递给端点构造函数的处理程序代码:

部首:

#ifndef __AUDIOSTREAMHANDLER_H__
#define __AUDIOSTREAMHANDLER_H__

#include <boost/shared_ptr.hpp>

#include <websocketpp/roles/client.hpp>
#include <websocketpp/websocketpp.hpp>

namespace blah
{
class AudioStreamHandler : public websocketpp::client::handler
{
    private:
        connection_ptr con_;

    public:
        AudioStreamHandler();
        virtual ~AudioStreamHandler();

        void on_fail(connection_ptr con);
        void on_open(connection_ptr con);
        void on_close(connection_ptr con);
        void on_message(connection_ptr con, message_ptr msg);
        void send(const std::string &msg);
        void close();
};

typedef boost::shared_ptr<AudioStreamHandler> AudioStreamHandlerPtr;
}

#endif  //__AUDIOSTREAMHANDLER_H__

实现:

#include "AudioStreamHandler.h"

namespace blah
{
AudioStreamHandler::AudioStreamHandler()
{
}

AudioStreamHandler::~AudioStreamHandler()
{
}

void AudioStreamHandler::on_fail(connection_ptr con)
{
    std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>> WebSocket connection failed <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
}

void AudioStreamHandler::on_open(connection_ptr con)
{
    con_ = con;
    std::cout << ">>>>>>>>>>>>>>>>>>>>>>>>>>>>> WebSocket connection established <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" << std::endl;
}

void AudioStreamHandler::on_close(connection_ptr con)
{
    con_ = websocketpp::client::connection_ptr();
    std::cout << "WebSocket connection terminated" << std::endl;
}

void AudioStreamHandler::on_message(connection_ptr con, message_ptr msg)
{
    std::cout << "Got WebSocket message: " << msg->get_payload() << std::endl;
}

void AudioStreamHandler::send(const std::string &msg)
{
    if( con_ ) {
        std::cerr << "Error: no connected session" << std::endl;
        return;
    }

    if( msg == "/close" ) {
        close();
    } else {
        con_->send(msg);
    }
}

void AudioStreamHandler::close() {
    if( !con_ ) {
        std::cerr << "Error: no connected session" << std::endl;
        return;
    }
    con_->close(websocketpp::close::status::GOING_AWAY,"");
}
}

最后我从gdb获得了栈跟踪:

(gdb) where
#0  0x00000000004aeabd in boost::re_detail::perl_matcher<char const*,         std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char,   boost::cpp_regex_traits<char> > >::match_all_states() ()
#1  0x00000000004af293 in boost::re_detail::perl_matcher<char const*, std::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp() ()
#2  0x00000000004afeb4 in bool boost::regex_match<char const*, std::allocator<boost::sub_match<char const*> >, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, char const*, boost::match_results<char const*, std::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) ()
#3  0x00000000004a9c47 in websocketpp::uri::uri(std::string const&) ()
#4  0x0000000000441254 in websocketpp::role::client<websocketpp::endpoint<websocketpp::role::client, websocketpp::socket::plain, websocketpp::log::logger> >::get_connection(std::string const&) (this=0x7ffff2501450)
at /usr/include/c++/4.4/bits/stl_vector.h:313
#5  0x0000000000426130 in blah::WorkThread::work (this=0x7c4250) at workthread.cpp:93
#6  0x000000000049658d in boost::_mfi::mf0<void, blah::WorkThread>::operator()(blah::WorkThread*) const (this=0x789cc8) at /usr/include/c++/4.4/ext/new_allocator.h:66
#7  0x0000000000495ffc in void boost::_bi::list1<boost::_bi::value<blah::WorkThread*> >::operator()<boost::_mfi::mf0<void, blah::WorkThread>, boost::_bi::list0>(boost::_bi::type<void>, boost::_mfi::mf0<void, blah::WorkThread>&, boost::_bi::list0&, int) (this=0x789cd8) at /usr/include/c++/4.4/ext/new_allocator.h:66
#8  0x00000000004957eb in boost::_bi::bind_t<void, boost::_mfi::mf0<void,   blah::WorkThread>, boost::_bi::list1<boost::_bi::value<blah::WorkThread*> > >::operator()() (this=0x800000) at /usr/include/c++/4.4/ext/new_allocator.h:66
#9  0x0000000000493a26 in boost::detail::thread_data<boost::_bi::bind_t<void, boost::_mfi::mf0<void, blah::WorkThread>, boost::_bi::list1<boost::_bi::value<blah::WorkThread*> > > >::run() (this=0x789b40)
at /usr/include/c++/4.4/ext/new_allocator.h:66
#10 0x00007ffff79b1693 in thread_proxy () from /usr/lib/libboost_thread.so.1.49.0
#11 0x00007ffff5ade9ca in start_thread (arg=<value optimized out>) at pthread_create.c:300
#12 0x00007ffff5ddbcdd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#13 0x0000000000000000 in ?? ()

我已经尝试使用boost的调试版本但没有获得进一步的错误信息。我是否只使用“ws:// localhost”或真正的连接字符串/ uri也没关系。

有没有人遇到过同样的问题,或者有人知道我在这里做错了什么? 任何帮助都是非常有用的。 感谢您抽出宝贵时间阅读这篇长篇文章。

0 个答案:

没有答案