C sendto 有时可以工作...只是在一段时间后停止...没有错误
我在 C 语言中使用 sendto 函数得到了奇怪的结果。(LINUX) 我想做的是实现一种可靠的 UDP 类型的方案。
下面提供的代码片段是计时器的一部分,当数据包丢失时计时器到期,并向进程发送消息以重新传输该数据包。
我遇到的奇怪问题是,当传输大文件时...>300KB 下面给出的代码工作完美(即其他部分已执行) 但是在发送一定数量的数据包之后......它执行then部分。!!!
这很奇怪,因为代码对于大约 250 个数据包运行良好,但对于 251 个数据包则工作正常 卡布姆!!!
n = sendto(sockfd, &(forwardPeer->id), sizeof(forwardPeer->id), 0, (struct sockaddr*)&tcpd_addr, sizeof(tcpd_addr));
if(n<0)
printf("\n error sending to tcpdc");
else
printf("\n message sent to tcpdc");
请帮忙!!!! 提前致谢
Ive been getting strange results with the sendto function in C.(LINUX)
What I am trying to do is to implement a reliable UDP kind of scheme.
The snippet of code provided below is a part of the timer that expires when a packet is dropped and sends a message to a process to retransmit that packet.
The weird problem which I am having is that when transferring a large file say... >300KB
The code given below works perfectly (i.e. THE ELSE PART IS EXECUTED)
But after a certain number of packets are sent...it executes the then part.!!!
THIS IS STRANGE BECAUSE THE CODE WORKED FINE FOR ABOUT 250 PACKETS BUT WITH THE 251 PACKET
kabooom!!!
n = sendto(sockfd, &(forwardPeer->id), sizeof(forwardPeer->id), 0, (struct sockaddr*)&tcpd_addr, sizeof(tcpd_addr));
if(n<0)
printf("\n error sending to tcpdc");
else
printf("\n message sent to tcpdc");
PLEASE HELP!!!!
THanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误文件描述符
错误意味着传递的sockfd
值不正确。要么:要捕获第二种情况,请在调试器下运行程序并在
sockfd
变量上设置一个观察点 - 当值发生变化时,这将中断到调试器,这应该让您看到它在哪里被更改。不应该。您还可以尝试在 valgrind 下运行该程序,并修复它报告的任何问题。
The
Bad file descriptor
error means that the passedsockfd
value is incorrect. Either:To catch the second case, run the program under a debugger and set a watchpoint on the
sockfd
variable - this will break into the debugger whenver the value changes, which should let you see where it's being changed when it shouldn't be.You could also try running the program under
valgrind
, and fixing any issues it reports.