i am writing a TCP client with kqueue. The events i would like to subscribe to are EVFILT_READ and EVFILT_WRITE. From freebsd, '''Combinations may be made by OR'ing the desired values. For instance, EV_ADD | EV_ENABLE | EV_ONESHOT would translate to "Add the event, enable it and return only the first occurrence of the filter being triggered. After the user retrieves the event from the kqueue, delete it."''' (http://wiki.netbsd.org/tutorials/kqueue_tutorial/). This to me, makes EVFILT_READ| EVFILT_WRITE valid kqueue code. This doesn't seem to be the case as kevent hangs indefinitely when i use both at the same time. However, using one in a seperate thread (EVFILT_READ in one thread and EVFILT_WRITE) in another works fine. This defeats the purpose of using kqueue though... Most examples (limited) are server examples which means it is ideal to only subscribe to EVFILT_READ then when a socket is accepted then needs to be written to itll call EVFILT_WRITE. This is not ideal for me since i would be doing both with no real wait time. The kqueue code, while not able to be compiled, looks like this
struct kevent ev[socketAmount];
struct kevent actionlist[socketAmount];
for (uint16_t x = 0; x < socketAmount; ++x) {
EV_SET(&ev[x], socketRelationArr[x].sock, EVFILT_READ | EVFILT_WRITE, EV_ADD | EV_ENABLE | EV_ONESHOT, 0, 0, 0);
kq = kqueue();
there will be x sockets that will be sending/recieving then i add them all to the kqueue by calling EV_SET with the events mentioned above (EV_ADD implies EV_ENABLE but for clarity i have it added)
int numberEV = kevent(kq, ev, socketAmount, actionlist, socketAmount, NULL);
Again, this makes kevent hang indefintely, so my question is: Is it possible to add EVFILT_READ and EVFILT_WRITE at the same time to the same socket and make it not hang? Is it normal behavior to hang?