<div class="gmail_quote">On 8 December 2011 00:20, Manu <span dir="ltr"><<a href="mailto:turkeyman@gmail.com">turkeyman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hey peoples,<div><br></div><div>So this might be a bit off topic... but I'm trying to think about the best way to write a small program in the most D-ish way possible (just to make sure I'm giving myself the most realistic experience with the language), and I wanted to get some thoughts.</div>
<div>I don't know which way to go on this. I know what I'd do in various other languages, but I'm curious to hear the communities opinion. I think part of the problem is that D's networking libraries are pretty incomplete... but here it is anyway.</div>
<div><br></div><div>I basically just want to write a trivial echo server which may have hundreds of thousands of connections split into small groups, and whenever data is received from a member in any group, it is basically echoed to the others in that group.</div>
<div>Sounds super simple...</div><div><br></div><div>My instinct is to have a listener on the main thread, and spawn a thread per group, each blocking on a select().. I think the questions is around thread safety and group management (managing the connection list for each group), and how to interrupt a blocking select() when a new connection has entered the group...</div>
<div>"The D way" to solve these questions is a mystery to me. I just feel like I'm writing C code, manually managing thread safety, timeout logic. I feel like D offers some fundamental features that should make solving this problem a whole lot simpler that I must be completely missing...</div>
<div><br></div><div>So, in a few sentences... simple problem, what would you do?</div>
</blockquote></div><br><div>Nobody at all? :(</div><div><br></div><div>Quite seriously. I'm trying to work out how D's threading/thread safety architecture can help me here.. Also since there's no collections, I'm using the associative arrays. How do I manage thread safety when accessing those? Is there a generic lock mechanism that I've missed along the way without manually creating semaphores? Networking does seem to be pretty bare, I'm basically writing C sockets code.</div>
<div>One of the results of my experiment here is to identify some critical things that appear to be missing from the language. Places libraries should really step in and make the task simple. This is a super simple network app, but so far, it's just as complicated as if it were written in C.</div>