これは、ファイルを読みたい関数の私のコードです:
int sendByByte(int filed,int sockfd,int filesize)
{
int i=0;
int sent=0;
char buf[BUFSIZE];
while(i<filesize)
{
printf("fd is : %d\n",filed);
printf("i: %d\n",i);
int byte_read=read(filed,buf,BUFSIZE);
if(byte_read == -1)
{
printf("MOSHKEL dar read\n");
return -1;
}
int byte_send=send(sockfd,buf,byte_read,0);
if(byte_send==-1)
{
printf("MOSHKEL dar send\n");
return -1;
}
close(filed);
i+=byte_read;
sent+=byte_read;
}
return sent;
}
問題は、i=0
動作してファイルを読み取ったが、read()
-1 を返す場合です。コードの問題は何ですか?
socketfd
=> サーバーのソケットfiled
=> ファイル記述子
ファイル記述子が有効であることを確認します。