I am trying to use a zero-copy mechanism for transferring a file through a socket and wish to use sendfile() as it is the most efficient function for zero-copy.
Currently I am working on a client/server program in C on FreeBSD Release 7.0, where I use sendfile().
The problem that I have encountered is, that sometimes sendfile works perfectly fine, other times I am being given the EBUSY error.
The current implementation is:
where;
intFileDesc: is an integer file descriptor referring to the file to be transferred,
sockfd: is the integer file descriptor of the socket,
fileOffset: is the offset of the file pointer,
MAX_BUF: is the number of bytes to be read from the file (varying from 1K to 8K bytes),
NULL, NULL: refers to optional header files which I am not using,
SF_NODISKIO: is a Flag that does not allow disk I/O
I do not know, why this code is not always working. Could it be that some buffers used by sendfile() are getting full and need to be cleared out? Is there any function how to do this? Could it be some other problem?
Any advice will be really appreciated.
Thanks in advance
Currently I am working on a client/server program in C on FreeBSD Release 7.0, where I use sendfile().
The problem that I have encountered is, that sometimes sendfile works perfectly fine, other times I am being given the EBUSY error.
The current implementation is:
Code:
sendfile(intFileDesc,sockfd,fileOffset,MAX_BUF,NULL,NULL,SF_NODISKIO);
where;
intFileDesc: is an integer file descriptor referring to the file to be transferred,
sockfd: is the integer file descriptor of the socket,
fileOffset: is the offset of the file pointer,
MAX_BUF: is the number of bytes to be read from the file (varying from 1K to 8K bytes),
NULL, NULL: refers to optional header files which I am not using,
SF_NODISKIO: is a Flag that does not allow disk I/O
I do not know, why this code is not always working. Could it be that some buffers used by sendfile() are getting full and need to be cleared out? Is there any function how to do this? Could it be some other problem?
Any advice will be really appreciated.
Thanks in advance