如何创建一个新的线程,使pcap_loop()和gtk_main()函数兼容? [英] How do I create a new thread to make pcap_loop() and gtk_main() compatible?

查看:471
本文介绍了如何创建一个新的线程,使pcap_loop()和gtk_main()函数兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个功能都是无限循环,

These two functions are both infinite loops,

和PROGRAME挂起一度被称为在同一个线程。

and the programe hangs once called in the same thread.

gtk_main(); 
...
pcap_loop(adhandle, 0, packet_handler, NULL);

当我点击开始按钮,我想 PCAP 开始的工作;而如果我preSS停止按钮, PCAP 停止

When I click the "start" button,I want pcap to start working;And if I press the "stop" button,pcap stop.

如何创建一个子线程,并运行 pcap_loop(adhandle,0,packet_handler,NULL); 而不是

How do I create a child thread and run pcap_loop(adhandle, 0, packet_handler, NULL); instead?

推荐答案

除非我失去了一些东西,你的问题是,无论是GTK +和
libpcap的是围绕从主循环触发的事件举办。没有
翻翻文件,我不知道GTK +,但有
是libpcap的另一种操作模式:可以使用 pcap_next()
pcap_next_ex()没有在你的程序流程放弃控制权。

Unless I am missing something, your problem is that both GTK+ and libpcap are organized around events fired from a main loop. Without looking through the documentation, I don't know about GTK+, but there is another mode of operation for libpcap: You can use pcap_next() or pcap_next_ex() without giving up control over your program flow.

有应该是可能的登记定期调用一个函数
使用这两个功能之一 g_timeout_add() g_idle_add()
一个线程和互斥机制,不再需要浪费时间
干脆。

It should be possible to register a function that periodically calls one of these two functions using g_timeout_add() or g_idle_add(), removing the need to mess around with threads and mutex mechanisms altogether.

这篇关于如何创建一个新的线程,使pcap_loop()和gtk_main()函数兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆