sendfile() problem

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:

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
 
From sendfile(2):
[EBUSY] Completing the entire transfer would have required
disk I/O, so it was aborted. Partial data may have
been sent. (This error can only occur when
SF_NODISKIO is specified.)
 
SirDice, I agree with your quote. However my concern is that I do not wish that sendfile() resorts to disk I/O as this would hinder the zero-copy transfer mechanism.

I am interested to know If I can do anything to make sure that sendfile() does not resort to disk I/O to send all the data.

Thank you for your kind attention
 
Back
Top