内核模块使用struct kvec 结构时一个疑惑
在内核模块里使用struct kvec用来TCP通信,问题如下......
struct kvec iov;
iov.iov_base = buff;
iov.iov_base = len
log_message(0, "buff addr: %x\n", iov.iov_base);
rc = recv_message(socket, &iov, 1);
log_message(0, "iov_base: %x\n", iov.iov_base);
......
打印结果为:
fca82000
fca82018
也就是iov.iov_base的地址经过我的接收函数后就变了,导致我在接收函数里想检查结果也不行,不只是和原因呢? 回复 1# Killdog1982
你接收了多少字节?18字节?
不知道是不是接收自节后,他的地址会随之偏移。具体没有研究过,不过希望你能贴出所有的代码。 代码有点长...
static size_t
recv_message(struct socket * sock, char * first_buff, struct kvec * iov, int iov_num)
{
struct msghdr msg;
int total_recv = 0, i = 0, header_done = 0;
size_t rc = 0, desired = 0;
if (!sock)
return -ENOTCONN;
memset(&msg, 0, sizeof(msg));
msg.msg_flags = MSG_DONTWAIT;
total_recv = 0;
i = 0;
desired = MSG_HDR_SIZE;
while (1)
{
rc = kernel_recvmsg(sock, &msg, iov, 1, desired, MSG_DONTWAIT);
if (rc == -EAGAIN)
{
i++;
if (i >= MAX_RETRY_TIMES)
{
log_message(0, "EAGAIN received, total_recv: %d\n", total_recv);
break;
}
msleep_interruptible(1 << i);
continue;
}
if (rc > 0)
{
total_recv += rc;
desired -= rc;
if (header_done && !desired)
break;
else
{
if (total_recv == MSG_HDR_SIZE)
{
clinet_info * info = (client_info*)first_buff;
desired = ntohl(info->ulength) - MSG_SIZE;
header_done = 1;
if (desired == 0)
break;
}
}
}
}
return total_recv;
}
上面是我改过之后的,又传一个first_buff过来才可以,不然还是不行
页:
[1]