.NET Socket *Async methods have a design flaw.

So I was attempting to make use of IO completion ports and build a high performance socket server in C# by making use of the *Async methods such as ReceiveAsync with SocketAsyncEventArgs. However I’ve encountered a problem which I cannot seem to find a solution for which involves a StackOverException being triggered by the execution of these methods. You see, at first glance everything appeared to be humming along nicely, until I decided to flood my server with about 12,000 randomly sized packets. That’s when the problem shows up.

I have a TryReceive method that makes the first call to ReceiveAsync, and if it returns FALSE, then I call the ProcessReceive directly, otherwise it gets called by the Completed event getting invoked on the SocketAsyncEventArgs. ProcessReceive then does some processing of the message and then calls TryReceive to start the process all over again. For whatever reason, the ReceiveAsync is always completing synchronously and creating a recursive loop with my two methods.

I’m not really sure what to try at this point, other than possibly trying to call it on another thread, but I’m worried that might cause some other recursive thread call issues. If anyone has any ideas feel free to hit up my contact form.

Here’s some extracted snippets of code to show how the calls are structured.

New Content!

I’ve added some new content to go along with the new host. I’m hoping I can keep adding new content over the next couple months, we’ll see how things go and how stressed out I get. I still plan on working on several projects including a forum script I had previously been fixing up. I’ll continue to get any of my old projects broken up into snippets and tutorials.

I also updated my contact form so that it actually goes to my primary email now, so if you had attempted to contact me in the past it probably got lost. The new form also includes more methods of contact.

I’m working on a few projects right now

One of them is a simple file hashing program in C#, and the other is a high-performance instant messaging server based on SocketAsyncEventArgs. I also want to get some small web-based applications up like I used to have on my older sites. I’ll also be uploading some of my older code that is still relevant. Hopefully I can get something done here this week.

Site relaunch

I’ve decided to re-launch my site. I’m not really sure what I’m going to put on it, but I’d like to release some new things rather than putting the same old 4~ year old source code and downloads on it. I haven’t had the motivation to work on this site in years, but I think I’m starting to find my creative spark again. I might work on some new plugins for the Minecraft server Bukkit. I also wanted to create my own forum/social network script and see what new ideas I could put forth on it since the conventional forum scripts out there seem antiquated. I was also going to try to post tech/gaming news on my site and possibly reviews on new products if I try them, but since i’m operating on a shoestring budget I probably won’t be reviewing too many new products/games. So with that, I hope to get something up by the end of the week as a small personal goal to myself.