Q: polling a kernel socket

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



0. kernel 2-4.18-3
1. Is there a better way to sleep than sleep_on_timeout()?
2. What's the best way to achieve something like poll() (or select())
   on a kernel socket.

Right now, I'm doing something like the following, which I cobbled together
by
combining sunrpc's _recvfrom function and khttpd's use of sleep_on_timeout.


for (;;) {
 if (stop_cond)
	break;

  /* How could I exit if I blocked? */
  msg = socket->ops->recvmsg(...NOBLOCK...);
  process_msg();

  /* sleep */
  current->state = TASK_INTERRUPTIBLE;
  (void) interruptible_sleep_on_timeout(&wq, HZ);
}

wake_up(&stop_wq);


Problem is, someone else is segv'ing while trying to read my thread's /proc
entry.
It's crashing in fs/proc/array.c, within a task_lock() block. This leads me
to
suspect I'm doing something I shouldn't be.

The thread is conceptually pretty simple. The killer thread sets stop_cond,
places itself on the stop_wq, and calls sys_wait4() to cleanup the deadwood.
That seems straightforward enough.

I've seen some dialog on the kernel list about sleep_on() being something to
avoid
if you can. But I don't see wait_queue_timeout() time of routine. Hence my
two Q's
above. Is there a better way to sleep than sleep_on_timeout() that I could
use as
a drop-in replacement? Or, is there a better way to set up the whole read
loop?


--
Gary Cote
gcote@transat-tech.com


-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux