Sign in to follow this  
Afr0m@n

IOCP is NOT hard!

Recommended Posts

Ach, I'm tired of the general perception in this forum that 'IOCP is hard to learn, and ever harder to use!' Thought I'd post a few steps; 1. Create a listening socket, and an IOCP instance (for the uninvited, IOCP 'instances' are just instances of the HANDLE value in 'Windows.h') 2. Assign the listening socket to the IOCP handle using CreateIoCompletionPort(). 3. Using WSASyncSelect() in your server's mainloop, determine when to call accept(), as a call to WSASyncSelect will be able to tell you if a call to accept() will be able to complete 100% asynchronously. 4. If you passed your IOCP instance as a parameter to WSASyncSelect(), one of the threads connected to said IOCP instance will receive a notification whenever you can call accept() to 'receive' new client connections. 5. Make a thread function for calling accept() on the listening socket whenever you receive the abovementioned notification through your IOCP handle. That's just for accepting new connections for now. I'll post more later on. I wish I had some code to post, but I'm having some link issues, and the code is currently residing on my laptop which is being driven home by my family as of the time of writing this.

Share this post


Link to post
Share on other sites
Quote:
Original post by Crazyfool
Please enlighten us more.


I will, trust me! :)

I'm kind of regretting the time of date that this post was posted on right now, as personal problems as well as the slow, but gradually expanding start of a new project has taken it's toll on my ability to devote time to anything outside of school and extremely personally relevant hobby stuff (said project being of such a character, amongst a few others).

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Getting IOCP to work is easy, but getting it to work nicely with OOP code and so it's usable in a "normal" way is hard.


Not for me - I tried in vain (though I was very inexperienced) and now I decided to just do what works now, and explain to IOCP when I need it.

I think my biggest problem then was I was a complete noob to windows programming.

Share this post


Link to post
Share on other sites
iocp connecting and sending is not so difficult (there are a few good reads on codeprojects) - but it's in the details.

- disconnecting bruteforce is not a problem - but what when there is
a write request pending (we should really let that finish and only
after that disconnect)...

- What about data arriving in the same order in which it is being sent?
(not because of tcp/ip - but rather what happens if two iocp write
events are being handled and the 2nd packet just happens to be handled
first by one of the threads serving the iocp port... )

- Same for reading, what happens if two iocp read requests are handled,
both actually have the data and wanna call a 'callback' to pass the
data to the client - here there is a threadswitch and now we receive
the 2nd packet before the 1st.. (I guess it would be possible, right?)

Regards

Share this post


Link to post
Share on other sites
Quote:
Original post by Afr0m@n
Quote:
Original post by Crazyfool
Please enlighten us more.


I will, trust me! :)

I'm kind of regretting the time of date that this post was posted on right now, as personal problems as well as the slow, but gradually expanding start of a new project has taken it's toll on my ability to devote time to anything outside of school and extremely personally relevant hobby stuff (said project being of such a character, amongst a few others).

So where's our enlightenment?

Share this post


Link to post
Share on other sites
Right now, it's in the hands of my shrink, my drinking problems, my constant thoughts about taking suicide and in whether or not I'll ever be able to get over my ex girlfriend. :)

As I said though... it'll be there, eventually.

Share this post


Link to post
Share on other sites
Speak of the devil, was just dealing with a bit of IOCP thismorning myself!

Must say, to say IOCP is not hard can be argued to be true, but it's certainly the hardest of the networking methods [then again it can be argued that none of them are hard]. IOCP has a certain amount of nastiness, thats for certain, and the code is a huge mess compared to old fashion socket programming. And even once you get it working, to get bend it into something 'acceptable' and useful, as evil steve described, is pretty nasty at times.

Powerful stuff though, but one of those kinds of things that you just have to sit down, and devote a weekend to building a wrapper around, so you never have to deal with it again.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this