如何将客户端的recv()部分更改为中断服务例程?
我目前有一个客户端在其自己的线程中侦听数据包。有人告诉我尝试实现 ISR,以便可以立即处理从 recv() 调用接收到的数据包,而不是等待该线程被调度。
编辑:现在是在 Windows 中,但稍后会移植到 DSP。
I currently have a client listening for packets in its own thread. I was told to try to implement an ISR so that the packet received from the recv() call can be handled immediately, instead of waiting for that thread to get scheduled.
EDIT: this is in windows now, but it will ported to a DSP later.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据定义,ISR 在内核空间中运行。除非您处于没有内存保护的嵌入式系统中,否则您需要将内核代码添加到您的项目中。此外,为了重新实现recv,它需要根据需要处理IP和TCP或UDP,以从以太网数据包中提取数据。
重新调度和切换到线程的开销是最小的,并且无论如何都需要发生,除非数据包完全在内核中处理。大多数操作系统都有最高优先级的线程设置,有时称为“实时”,这会导致用户空间代码在驱动程序接收数据后以最小的延迟运行。这通常用于音频/视频 I/O 以及网络。
ISRs by definition run in kernel space. Unless you are in an embedded system without memory protection, you will need to add kernel code to your project. Furthermore, to reimplement
recv
, it will need to handle IP and TCP or UDP as necessary to extract the data from the ethernet packets.The overhead of rescheduling and switching to a thread is minimal, and needs to happen anyway unless the packet is handled entirely in the kernel. Most operating systems have a highest-priority thread setting, sometimes called "real-time," which causes user space code to run with minimal delay after the driver receives data. This is often used for audio/video I/O as well as networking.