Dear Gustaf,
thank you for your questions.
The new version of the function I'm using is here below:
#define MAX_BUF_SIZE 16384
#define ACC_DELAY 5
static ssize_t
SendFd(Ns_Sock *sock, int fd, off_t offset, size_t length,
const Ns_Time *timeoutPtr, unsigned int flags,
Ns_DriverSendProc *sendProc)
{
char buf[MAX_BUF_SIZE + 1];
struct iovec iov;
ssize_t nwrote = 0, toRead = (ssize_t)length, result;
bool decork;
decork = Ns_SockCork(sock, NS_TRUE);
while (toRead > 0) {
ssize_t sent, nread;
nread = pread(fd, buf, MIN((size_t)toRead, MAX_BUF_SIZE), offset);
if (nread <= 0) {
break;
}
toRead -= nread;
offset += (off_t)nread;
buf[nread] = '\0';
(void) Ns_SetVec(&iov, 0, buf, (size_t)nread);
sent = (*sendProc)(sock, &iov, 1, timeoutPtr, flags);
Sleep(ACC_DELAY);
if (sent > 0) {
nwrote += sent;
}
if (sent != nread) {
break;
}
}
if (decork) {
(void) Ns_SockCork(sock, NS_FALSE);
}
if (nwrote > 0) {
result = nwrote;
} else {
result = -1;
}
return result;
}
Now the answers to your questions:
questions:
* why should making the buffer static help against a buffer overflow (as you stated above)?
because, if I do not use the buffer static, the code as it is stops working. I believe it is a timing issue. The send operation still takes place when the function is finished.
If I want to remove the static, I need to introduce a delay after the call to (*sendProc). I know this is a ugly fix, perhaps you can investigate this issue. But with this delay the code works and it is thread safe.
* what is the result of the debugging lines (that i have added to bitbucket) in your installation?
I did not check them.
* do you get the same problems with the config-file, that i have sent to you?
I did not try the binaries. I will try with the config-file and let you know.