cancel
Showing results for 
Search instead for 
Did you mean: 

callback for shared library feedhandler

joshmyzie2
New Contributor
Hello,I trying to write a basic shared library feedhandler, but as a C novice,I'm struggling to understand the use of sd1() with a callback.Say I have a q function defined in my main thread:upd:{insert[`quotes;x]}If I were just sending data to a remote q process, I would usek(-h, (S)"upd", data, (K)0);But I want to use a single process without a TCP socket. What eventfddo I pass to sd1 and how do I actually get my data from C into my updfunction via a callback?I'm using 32bit linux.Thanks,Josh
1 REPLY 1

effbiae
New Contributor

> What eventfd do I pass to sd1

create a new one:
 d=eventfd(x->j,0)
every new file descriptor registered with sd1 needs a callback

>how do I actually get my data from C into my upd  with write/read

the example from the wiki:
 k(0,(S)"onCallback",ki(d),kj(a),(K)0)

instead, use the required callback:
 k(0,(S)"upd",data,(K)0)

when data comes in to c, use write(d), with the address of the data to send to q and trigger the callback
 write(x->i,&data,4) //4 byte address for l32

the registered callback for d can then use the address of data and call upd 
 K data;read(d,&data,4);k(0,(S)"upd",data,(K)0)

hope that helps - untested code above.
jack