問題がありselect
ます。サーバー側で受信したデータを読み取れるようになるまで関数を使用して待機しますが、何も受信せず、タイムアウトが経過したため、正しく機能しません。
サーバー側のコード:
int fd = accept(sockfd, addr, addrlen);
if(fd > 0)
{
struct timeval tv;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(fd, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
// wait when i can read data
int ret_select = select(1, &rfds, (fd_set *) 0, (fd_set *) 0, &tv);
if(ret_select > 0)
{
// data ready to be readed. NEVER HERE!
}
else
{
// nothing. ALWAYS HERE
}
}
クライアント側:
int ret = connect(s, name, namelen);
if(ret == 0)
{
struct timeval tv;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(s, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
// wait when we can write
int ret_select = select(1, (fd_set *) 0, &rfds, (fd_set *) 0, &tv);
if(ret_select > 0)
{
int sended = send(s, my_data, size_data, 0);
if(sended > 0)
{
// all ok, data sended!
}
}
}
しかし、サーバー側の呼び出しを削除するとselect
、すべてOKで、読み取るデータが存在するためselect
、コードで正しく機能しないと思います。
私のコードの何が問題になっていますか?
ありがとう!