Nginx: hijack `read` and `write`.

Since libssl calls `read` and `write` when SSL handshake, we must
hijack these two functions, so that the network IO can pass through
f-stack.
This commit is contained in:
logwang 2017-09-26 17:00:20 +08:00
parent b7d857a29d
commit 20be49f608
1 changed files with 31 additions and 0 deletions

View File

@ -112,6 +112,9 @@ 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 ssize_t (*real_read)(int, void *, size_t);
static ssize_t (*real_write)(int, const void *, size_t);
static int (*real_ioctl)(int, int, void *);
static int (*real_gettimeofday)(struct timeval *tv, struct timezone *tz);
@ -374,6 +377,34 @@ readv(int sockfd, const struct iovec *iov, int iovcnt)
}
}
ssize_t
read(int sockfd, void *buf, size_t count)
{
if (unlikely(inited == 0)) {
return SYSCALL(read)(sockfd, buf, count);
}
if (ff_fdisused(sockfd)) {
return ff_read(sockfd, buf, count);
} else {
return SYSCALL(read)(sockfd, buf, count);
}
}
ssize_t
write(int sockfd, const void *buf, size_t count)
{
if (unlikely(inited == 0)) {
return SYSCALL(write)(sockfd, buf, count);
}
if (ff_fdisused(sockfd)) {
return ff_write(sockfd, buf, count);
} else {
return SYSCALL(write)(sockfd, buf, count);
}
}
int
ioctl(int sockfd, int request, void *p)
{