hello!
can somebody give me a short explanation, what is done if i add a poll function? Can i use it to check if something has been received at a socket?
thx a lot! (and sorry for the stupid question, if it is one :) )
best greetings,
walter
walter jenner wrote:
hello!
can somebody give me a short explanation, what is done if i add a poll function? Can i use it to check if something has been received at a socket?
Look in s_inter.c and x_net.c of the pd source.... Pd monitors registered file descriptors, which are usually sockets, and calls a user-defined function when something happens, usually data ready to read or incoming connection. The third parameter in the call is a pointer to a data structure associated with the callback function. sys_domicrosleep() in s_inter.c checks for activity on each registered socket by calling select() on each one (but only checks the read set, so errors don't get caught this way). sys_domicrosleep() is quasiperiodically called from m_scheduler(), pd's 'main loop'. In pd, socketreceiver_read() is called from sys_domicrosleep() when something has been received at a socket, so yes, you can use it for that...
It's also possible to do the same thing using timers with clock_new(), as in netclient. Timers seem to have higher priority than pollfunctions in m_scheduler().
Martin
thx a lot! (and sorry for the stupid question, if it is one :) )
best greetings,
walter
PD-dev mailing list PD-dev@iem.at http://lists.puredata.info/listinfo/pd-dev
The simplest example is in the netreceive object (x_net.c in the Pd source)... you open a socket and call sys_addpollfn to have a callback function added to it. The callback function gets called from the Pd scheduler whenever select() reports that the socket (or other selectable file descriptor) can be read without blocking. Be sure to call sys_rmpollfn() when you're deleted so the callbacks stop coming..
cheers Miller
On Tue, May 16, 2006 at 04:28:47PM +0200, walter jenner wrote:
hello!
can somebody give me a short explanation, what is done if i add a poll function? Can i use it to check if something has been received at a socket?
thx a lot! (and sorry for the stupid question, if it is one :) )
best greetings,
walter
PD-dev mailing list PD-dev@iem.at http://lists.puredata.info/listinfo/pd-dev