www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What would you do...

--0016e64699b6a759ad04b387f5cb
Content-Type: text/plain; charset=UTF-8

Hey peoples,

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

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.
Sounds super simple...

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

So, in a few sentences... simple problem, what would you do?

--0016e64699b6a759ad04b387f5cb
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

Hey peoples,<div><br></div><div>So this might be a bit off topic... but I&#=
39;m trying to think about the best way to write a small program in the mos=
t D-ish way possible (just to make sure I&#39;m giving myself the most real=
istic experience with the language), and I wanted to get some thoughts.</di=
v>
<div>I don&#39;t know which way to go on this. I know what I&#39;d do in va=
rious other languages, but I&#39;m curious to hear the communities opinion.=
 I think part of the problem is that D&#39;s networking libraries are prett=
y incomplete... but here it is anyway.</div>
<div><br></div><div>I basically just want to write a trivial echo server wh=
ich 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 e=
choed 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 ma=
nagement (managing the connection list for each group), and how to interrup=
t a blocking select() when a new connection has entered the group...</div>
<div>&quot;The D way&quot; to solve these questions is a mystery to me. I j=
ust feel like I&#39;m writing C code, manually managing thread safety, time=
out 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 yo=
u do?</div>

--0016e64699b6a759ad04b387f5cb--
Dec 07 2011