1

C の sendto 関数で奇妙な結果が得られました (LINUX) 私がやろうとしているのは、信頼できる UDP のようなスキームを実装することです。

以下に示すコード スニペットは、パケットがドロップされたときに期限切れになるタイマーの一部であり、そのパケットを再送信するためにプロセスにメッセージを送信します。

私が抱えている奇妙な問題は、大きなファイルを転送するときに...> 300KB以下のコードは完全に機能します(つまり、ELSE部分が実行されます)しかし、特定の数のパケットが送信された後...それを実行します部。!!!

コードが約 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");     

助けてください!!!!前もって感謝します

4

1 に答える 1

1

The Bad file descriptor error means that the passed sockfd value is incorrect. Either:

  • The file descriptor has been closed; or
  • The value of that variable has been overwritten by junk, probably due to a bounds overflow somewhere in your program.

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.

于 2011-03-11T03:20:54.003 に答える