Fix #51: nginx readv errors.

When use nginx as a proxy, nginx error logs always print 'readv() failed
(9: Bad file descriptor) while reading upstream'.
In previous commit: 10c5711ed2, i removed
`readv`, caused this issue.
This commit is contained in:
logwang 2017-08-04 11:24:40 +08:00
parent 7544d3aff0
commit a43cdca49a
1 changed files with 42 additions and 0 deletions

View File

@ -79,7 +79,11 @@ static int (*real_accept)(int, struct sockaddr *, socklen_t *);
static int (*real_accept4)(int, struct sockaddr *, socklen_t *, int);
static ssize_t (*real_recv)(int, void *, size_t, int);
static ssize_t (*real_send)(int, const void *, size_t, int);
static ssize_t (*real_sendto)(int, const void *, size_t, int,
const struct sockaddr*, socklen_t);
static ssize_t (*real_sendmsg)(int, const struct msghdr*, int);
static ssize_t (*real_writev)(int, const struct iovec *, int);
static ssize_t (*real_readv)(int, const struct iovec *, int);
static int (*real_ioctl)(int, int, void *);
@ -103,7 +107,10 @@ ff_mod_init(int argc, char * const *argv) {
INIT_FUNCTION(accept4);
INIT_FUNCTION(recv);
INIT_FUNCTION(send);
INIT_FUNCTION(sendto);
INIT_FUNCTION(sendmsg);
INIT_FUNCTION(writev);
INIT_FUNCTION(readv);
INIT_FUNCTION(ioctl);
INIT_FUNCTION(select);
@ -166,6 +173,30 @@ send(int sockfd, const void *buf, size_t len, int flags)
}
}
ssize_t
sendto(int sockfd, const void *buf, size_t len, int flags,
const struct sockaddr *dest_addr, socklen_t addrlen)
{
if (CHK_FD_BIT(sockfd)) {
sockfd = CLR_FD_BIT(sockfd);
return ff_sendto(sockfd, buf, len, flags,
(struct linux_sockaddr *)dest_addr, addrlen);
} else {
return real_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
}
}
ssize_t
sendmsg(int sockfd, const struct msghdr *msg, int flags)
{
if (CHK_FD_BIT(sockfd)) {
sockfd = CLR_FD_BIT(sockfd);
return ff_sendmsg(sockfd, msg, flags);
} else {
return real_sendmsg(sockfd, msg, flags);
}
}
ssize_t
recv(int sockfd, void *buf, size_t len, int flags)
{
@ -252,6 +283,17 @@ writev(int sockfd, const struct iovec *iov, int iovcnt)
}
}
ssize_t
readv(int sockfd, const struct iovec *iov, int iovcnt)
{
if (CHK_FD_BIT(sockfd)) {
sockfd = CLR_FD_BIT(sockfd);
return ff_readv(sockfd, iov, iovcnt);
} else {
return real_readv(sockfd, iov, iovcnt);
}
}
int
ioctl(int sockfd, int request, void *p)
{