poll() and select()
Hey, I'm currently pondering an ALSA interface for Ruby
(http://ruby-lang.org). Unfortunately, to do what I want, I need to be able to have a file descriptor for select(). I've tried using the fds returned by snd_seq_poll_descriptors(), but (not suprisingly) they didn't work: select blocks indefinitely.
The interface would be for writing a MIDI sequencer. Any thoughts on the issue?
Signature · 12 lines
Ryan Pavlik <[email protected]> "They don't *appear* to be in league with some nameless *horror* from the nether-dimensions I inadvertendtly pissed off by trying to enslave." - 8BT ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php
At Mon, 13 Oct 2003 10:53:24 -0700,
Quoted 6 lines · Ryan Pavlik
Hey, I'm currently pondering an ALSA interface for Ruby
(http://ruby-lang.org). Unfortunately, to do what I want, I need to be able to have a file descriptor forselect(). I've tried using the fds returned bysnd_seq_poll_descriptors(), but (not suprisingly) they didn't work: select blocks indefinitely.
if i understand correctly, it should work. fd field in the returned pollfd struct is the file descriptor for select().
Takashi
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
Quoted 11 lines · On Tue, 14 Oct 2003 11:49:37 +0200 Takashi Iwai <[email protected]> wrote:
At Mon, 13 Oct 2003 10:53:24 -0700,
Quoted 6 lines · Ryan Pavlik
Hey, I'm currently pondering an ALSA interface for Ruby
(http://ruby-lang.org). Unfortunately, to do what I want, I need to be able to have a file descriptor forselect(). I've tried using the fds returned bysnd_seq_poll_descriptors(), but (not suprisingly) they didn't work: select blocks indefinitely.if i understand correctly, it should work. fd field in the returned pollfd struct is the file descriptor for
select().
This is what I had hoped. However, it doesn't seem to work correctly, and I'm thinking it's because the file descriptor isn't actually for reading and writing, but some other form of communication I'm not familiar with.
I'm using the "seqdemo.c" example from the HOWTO as a testbase. The main bit of code looks like this:
while (1) {
FD_ZERO(&rfds);
FD_SET(pfd[0].fd, &rfds);
if (select(npfd, &rfds, NULL, NULL, NULL)) {
midi_action(seq_handle);
}
}Basically, a replacement of the old while() loop with a bridge from the poll() structs to select(). I've used select() before with no problems, but this simply hangs indefinitely, while the poll() version works as advertised.
Quoted 1 line
From the select manpage:
Three independent sets of descriptors are watched. Those listed in
readfds will be watched to see if characters become available for read- ing (more precisely, to see if a read will not block - in particular, a file descriptor is also ready on end-of-file), [...]
I'm thinking it may not be the case that /proc/snd/dev/seq may not be something that you read() from, but I'm not sure. I've attached my version of seqdemo, perhaps I'm doing something wrong.
thanks,
Signature · 4 lines
Ryan Pavlik <[email protected]> "I'll *prove* to you that sword-chucks are the single greatest advancement in all weaponology." - 8BT
Hi,
Quoted 4 lines · Ryan Pavlik
I'm using the "
seqdemo.c" example from the HOWTO as a testbase. The main bit of code looks like this:
Quoted 8 lines
while (1) {
FD_ZERO(&rfds);
FD_SET(pfd[0].fd, &rfds);
if (select(npfd, &rfds, NULL, NULL, NULL)) {
midi_action(seq_handle);
}
}Silly question, but is 'npfd' the file descriptor you are polling + 1?
Signature · 8 lines
Ryan Underwood, <nemesis at icequake.net>, icq=10317253 ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php
Quoted 1 line · On Tue, 14 Oct 2003 20:06:00 -0500 Ryan Underwood <[email protected]>…
Silly question, but is 'npfd' the file descriptor you are polling + 1?
I AM DUMB.
I totally overlooked this. Simple fix, and it works great. Thanks. :-) You'd think I had never done this before.
So the select() version works fine, with the bridge from the poll() file structure. This should integrate with ruby just fine then.
thanks,
Signature · 11 lines
Ryan Pavlik <[email protected]> "I'll *prove* to you that sword-chucks are the single greatest advancement in all weaponology." - 8BT ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php
Hi,
Quoted 9 lines · Ryan Pavlik
Quoted 1 line · On Tue, 14 Oct 2003 20:06:00 -0500 Ryan Underwood <[email protected]>…
Silly question, but is 'npfd' the file descriptor you are polling + 1?
I AM DUMB.
I totally overlooked this. Simple fix, and it works great. Thanks. :-) You'd think I had never done this before.
I guess there is after all some benefit to asking the silly question from time to time... ;) At least, I know I also made that particular stupid mistake in past code.
Good luck!
Signature · 8 lines
Ryan Underwood, <nemesis at icequake.net>, icq=10317253 ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php
Quoted 5 lines · Ryan Pavlik
Quoted 1 line · On Tue, 14 Oct 2003 20:06:00 -0500 Ryan Underwood <[email protected]>…
Silly question, but is 'npfd' the file descriptor you are polling + 1?
Quoted 7 lines
I AM DUMB.
I totally overlooked this. Simple fix, and it works great. Thanks. :-) You'd think I had never done this before.
So the
select()version works fine, with the bridge from thepoll()file structure. This should integrate with ruby just fine then.
Don't use select() if possible. You don't know which direction is required for a file descriptor. You must use snd_seq_poll_descriptors_revents() which mangles the used direction and reports the correct one to the application (and yes, it might be an opposite or both directions in real if we implementing some complex devices behind this API).
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php
On Thu, 16 Oct 2003 19:54:20 +0200 (CEST)
Jaroslav Kysela <[email protected]> wrote:
<snip>
Quoted 6 lines
Don't use
select()if possible. You don't know which direction is required for a file descriptor. You must usesnd_seq_poll_descriptors_revents()which mangles the used direction and reports the correct one to the application (and yes, it might be an opposite or both directions in real if we implementing some complex devices behind this API).
<snip>
Unfortunately it's necessary... I'm trying to write a ruby module, and ruby uses soft threads for portability's sake. It's also unfortunately not threadsafe, or I could just dump the sequencer stuff in a pthread and go from there.
It does provide rb_thread_select(), which uses select() but schedules its own threads while blocking.
The pollfd struct does provide the 'events' member which can have POLLIN and/or POLLOUT, so I should still be able to put the descriptors in the right group for select, no?
thanks,
Signature · 11 lines
Ryan Pavlik <[email protected]> "Prepare to face the unparalleled force of a master of all twelve zodiac kenshido styles!" - 8BT ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services: Click here: http://sourceforge.net/supporters.php
Quoted 17 lines · Ryan Pavlik
On Thu, 16 Oct 2003 19:54:20 +0200 (CEST)
Jaroslav Kysela <[email protected]> wrote:<snip>
Quoted 6 lines
Don't use
select()if possible. You don't know which direction is required for a file descriptor. You must usesnd_seq_poll_descriptors_revents()which mangles the used direction and reports the correct one to the application (and yes, it might be an opposite or both directions in real if we implementing some complex devices behind this API).<snip>
Unfortunately it's necessary... I'm trying to write a ruby module, and ruby uses soft threads for portability's sake. It's also unfortunately not threadsafe, or I could just dump the sequencer stuff in a pthread and go from there.
Quoted 6 lines
It does provide
rb_thread_select(), which usesselect()but schedules its own threads while blocking.The pollfd struct does provide the 'events' member which can have POLLIN and/or POLLOUT, so I should still be able to put the descriptors in the right group for select, no?
Yes, but you have to create revents for snd_seq_poll_descriptors_revents() to get the right event then. Don't use values from select() directly.
Jaroslav
-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SuSE Labs
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. SourceForge.net hosts over 70,000 Open Source Projects. See the people who have HELPED US provide better services:
Click here: http://sourceforge.net/supporters.php