CTL_DATA_NOWAKEUP not working as expected
CTL_DATA_NOWAKEUP not working as expected
- Subject: CTL_DATA_NOWAKEUP not working as expected
- From: Markus Hanauska <email@hidden>
- Date: Wed, 20 Aug 2008 17:58:03 +0200
Hi everyone,
CTL_DATA_NOWAKEUP does not work as expected after reading the
documentation. The documentation implies that this flag only means
whether a thread blocking on a recv call is woken up or not. Let me
show you some code
for (i = 0; i <= max; i++) {
// ... some code left out ...
result = ctl_enqueuedata(
ctlref,
unit,
&packed,
sizeof(packed),
i < max ? CTL_DATA_NOWAKEUP : CTL_DATA_EOR
);
// ... some code left out ...
}
Since I'm sending two packets to user space (in this example max ==
1), each represented by packed struct, I don't want the user space
process waiting on recv to wake up before both packages are there.
I'd assume after en-queuing the data, the data is copied to the
receive buffer of the socket, however on the first call the data is
just copied there, on the second call the data is copied there as
well and this time the thread is woken up.
So far this works as expected. After both packets are enqueued the
recv call in user space unblocks (it won't unblock after the first
packet is enqueued). However, the code looks like this:
for (;;) {
if (
recv(
KextSocket,
&packed,
sizeof(packed),
MSG_WAITALL
) != sizeof(packed)
) {
// ... handle short read ...
}
// ... process read data ...
}
I want to read the packets one by one, not all of them at once. What
happens is, it wakes up and reads the first of the two enqueued
packets. But when it tries to read the second packets, it blocks
again. Why? The data for two packets is there(!), it should be able
to run recv call above twice *WITHOUT* blocking. When I always use
CTL_DATA_EOR, it can read both as expected, but then it will already
wake up after the first enqueued packet.
So does using several enqueue calls with CTL_DATA_NOWAKEUP and
finally one without that flag only works if the receiver side then
reads all the enqueued data in ONE call? As that is not clear from
the documentation. Also I fail to see how CTL_DATA_NOWAKEUP should
have any influence if no thread is blocked by the socket at all. If
the thread is currently processing something else and I add data with
CTL_DATA_NOWAKEUP to the socket, I'd expect that if it later gets
back to the recv call, it can read the data at once without blocking,
as a thread should never block on a socket if it has data ready to
read and it has data ready to read (I just asked the kernel to not
wake up blocking threads, but there were no threads blocking for this
socket).
I tried the above example with a bigger max. When I enqueue 10
packets, using CTL_DATA_NOWAKEUP on all, but the last packet, the
thread wakes up, can read the first one and then blocks again, till
some other data is enqueued without CTL_DATA_NOWAKEUP flag. After the
whole process runs twice, I have enqueued 20 pakets, the user space
process has read 2 of them, 18 should still be in the queue and it
blocks on the recv call.
--
Best Regards,
Markus Hanauska
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden