小编Tom*_*son的帖子

C++中断UDP侦听器.在Xcode中使用oscpack编译

我已成功将UDPreceive功能合并到我的应用程序中.然而!我无法弄清楚如何阻止UDP侦听器无限运行.OSCPack库内置了Break()和AsynchronousBreak(),但我无法实现这些.

在oscpack中的udpSocket.cpp文件中:

void Run() //the listener function (WORKING!)
{
    break_ = false; 
    //UDP Listener Code

    void Break()
    {
        break_ = true;
    }
    void AsynchronousBreak()
    {
        break_ = true;
        // Send a termination message to the asynchronous break pipe, so select() will return
        write( breakPipe_[1], "!", 1 );
    }
}
Run Code Online (Sandbox Code Playgroud)

尽管编译器建议正确调用所有内容,但我尝试从数据包Listener类调用Break()似乎没有做任何事情:

SocketReceiveMultiplexer s;
s.Break();
Run Code Online (Sandbox Code Playgroud)

我尝试过的另一种方法是根据RunUntilSigInt()函数引发中断标志.在数据包监听器类中:

raise(SIGINT);
Run Code Online (Sandbox Code Playgroud)

但这会终止整个程序,而不是仅仅打破UDPListener.作为参考,这里是udpSocket.cpp中的RunUntilSigInt()代码:

void SocketReceiveMultiplexer::RunUntilSigInt()
{
    assert( multiplexerInstanceToAbortWithSigInt_ == 0 ); /* at present we support only one multiplexer instance running until sig int */
    multiplexerInstanceToAbortWithSigInt_ = …
Run Code Online (Sandbox Code Playgroud)

c++ sockets udp osc

5
推荐指数
1
解决办法
887
查看次数

标签 统计

c++ ×1

osc ×1

sockets ×1

udp ×1