IOCP is NOT hard!

Started by
9 comments, last by cdoty 16 years, 12 months ago
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.
_______________________Afr0Games
Advertisement
Please enlighten us more.

I'm sure I'm not the only one who has had intense trouble with IOCP.
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.
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).
_______________________Afr0Games
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.
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
visit my website at www.kalmiya.com
I find that the biggest problem with IOCP programming is the semantics of CancelIo. On Vista, we have CancelIoEx (yay!) but that's Vista only (boo!).

enum Bool { True, False, FileNotFound };
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?

Beginner in Game Development?  Read here. And read here.

 

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.
_______________________Afr0Games
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.

This topic is closed to new replies.

Advertisement