WSK - using RECEIVE_EVENT and sending back data

Hi,

i’m stuck in the middle of a small project. This is my first time working with WSK. My goal was achieve some communication beetween a socket client and server (my driver). My first approach worked pretty smooth, the single purpose was to send a text string from my socket client to the server and then send it back to the client, pretty much an echo server, to speed up my project I’m using a wrapper I found on github (wskudp/tcp):

CreateSocket -> Bind -> Accept (wait for incoming connection) -> Receive (loop) -> Send back what I received inside that loop.

This worked perfectly but while reading the documentation I found out about the PFN_WSK_RECEIVE_EVENT callback function. Therefore I decided to implement a receive callback instead of using a loop because this approach seemed cleaner to me. So I just enabled event callbacks for WSK_EVENT_RECEIVE and implemented the callback function. This worked pefectly as the callback events fires every time I’m sending something to the server but when I tried to send back the message to my client from within the receive event callback function the client only receives the first message and then it immediately BSODs, usually I’m getting MULTIPLE_IRP_COMPLETE_REQUESTS. While it works perfectly when sending back data in a receive loop it doesn’t work when using the event callback. Am I getting something wrong here, is this not a viable approach?

Best
Tom

So it looks like you cannot send reply directly from the callback, because the callback is not called in a suitable context (at DISPATCH, maybe)

– pa

Hm, I’m still wondering how you would approach something like this. Code examples for WSK are pretty rare but I haven’t found ANY example where someone is even using the RECEIVE_EVENT callback. I’m pretty sure my original approach doesn’t work because the send event expects some completion routine while the receive callback won’t wait for the completion of my send call.
One idea I had was to start a seperate thread to send data from there and then terminate it when the data was sent successfully but this leads to other issues, where I also get a bluescreen after 1 or 2 sucessful answers to the client.