Discussion:
can't iterate over context queue more than once
Irwin Tillman
2004-11-05 16:21:39 UTC
Permalink
Platform: libnet 1.1.2.1 on Solaris 9

It seems that it's only possible to iterate over a context queue once.
Trying to iterate over it again doesn't work, because the queue
is still write-locked.

Is the intent of context queues to only allow you to iterate once,
then destroy the queue? Or is there a way to iterate again?

--

Details:

I build the context queue. After this point I don't modify it.
...
while (1) {
exit if signalled...
for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) {
...
libnet_write(l);
...
}
sleep(60);
}

libnet_cq_head() checks if the context queue is already write-locked, and if
so, returns NULL. If it is not write-locked, it write-locks the context queue,
and returns the head.

The first time through the for loop, all is well. But at the conclusion of
that loop, the context queue is still write-locked. The next call to
libnet_cq_head() returns NULL.

Should there be a way to say "I'm done iterating, please unlock the queue"?

Or have I missed the point of context queues; e.g. I'm only allowed to iterate once,
then I'm expected to destroy the context queue and build a new one?
Frédéric Raynal
2004-11-07 16:39:26 UTC
Permalink
Hello,

First of all, you should probably think to use the ng API which is
naturally designed to support multiple packets. cq was added a
posteriori to do so with the 1.1 API.

I wrote a static function clear_cq_lock() but you are right, I forgot
to complete the job.

Somthing like that should be ok:
u_int32_t libnet_cq_end_loop() {

if (! clear_cq_lock(CQ_LOCK_WRITE))
{
return (0);
}
l_cqd.current = l_cq;
return (1);
}

Sorry :(

Fred
Post by Irwin Tillman
Platform: libnet 1.1.2.1 on Solaris 9
It seems that it's only possible to iterate over a context queue once.
Trying to iterate over it again doesn't work, because the queue
is still write-locked.
Is the intent of context queues to only allow you to iterate once,
then destroy the queue? Or is there a way to iterate again?
--
I build the context queue. After this point I don't modify it.
...
while (1) {
exit if signalled...
for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next()) {
...
libnet_write(l);
...
}
sleep(60);
}
libnet_cq_head() checks if the context queue is already write-locked, and if
so, returns NULL. If it is not write-locked, it write-locks the context queue,
and returns the head.
The first time through the for loop, all is well. But at the conclusion of
that loop, the context queue is still write-locked. The next call to
libnet_cq_head() returns NULL.
Should there be a way to say "I'm done iterating, please unlock the queue"?
Or have I missed the point of context queues; e.g. I'm only allowed to iterate once,
then I'm expected to destroy the context queue and build a new one?
Loading...