Bufferbloat プロジェクトに関連するネットワーク ベンチマークを作成しようとしています。ほとんどの場合は機能しますが、継続的に書き込まれているソケットに送信される 1 バイトのキャンセル信号を読み取るのに問題があります。
私の最初の試みは次のようなものでした:
rv = send(sockfd, buffer, 65536, 0);
if(rv < 0) {
printf("Hard shutdown of spew()!\n");
goto bail;
}
if(recv(sockfd, &cancel, 1, MSG_DONTWAIT) == 1) {
// other end asking us to stop
cancel = 1;
}
Tcpdump は、クライアントによって送信された 1 バイトのパケットを示しましたが、サーバーはそれに応答しませんでした。奇妙なことに、クライアントを手動で終了すると、サーバーは「ハード シャットダウン」パスに到達せずにキャンセル パケットに応答します。
私の次の反復は、poll() を使用することでした。
if(!poll(&pfd, 1, 120000)) {
printf("Timeout in spew()!\n");
goto bail;
}
if(pfd.revents & (POLLOUT|POLLERR|POLLHUP)) {
rv = send(sockfd, buffer, 65536, 0);
if(rv < 0) {
printf("Hard shutdown of spew()!\n");
goto bail;
}
}
if(pfd.revents & POLLIN) {
if(recv(sockfd, &cancel, 1, MSG_WAITALL) == 1) {
// other end asking us to stop
cancel = 1;
}
}
これは、以前のコードと同じように動作しました。
どうすれば修正できますか?