Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Sept/Oct 2019 Issue of The NT Insider available

Download PDF here:

It’s a particularly BIG issue, too: 40 pages of technical goodness, ranging from WDF to Minifilters. Check it out.
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

WSK - using RECEIVE_EVENT and sending back data

thomas_pthomas_p Member Posts: 2


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?



  • Pavel_APavel_A Member Posts: 2,687

    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

  • thomas_pthomas_p Member Posts: 2

    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.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
Writing WDF Drivers 21 Oct 2019 OSR Seminar Space & ONLINE
Internals & Software Drivers 18 Nov 2019 Dulles, VA
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 27 Apr 2020 OSR Seminar Space & ONLINE