[SDL] [Framework] Event-based Networking

Nathaniel J Fries nfries88 at yahoo.com
Thu Mar 21 17:33:22 PDT 2013


Glocke wrote:
> I will redesign my "thread-use":
> 
> 	 Server: 1 recv-thread (including incomming-client-accept), 1 send-thread
> 
> 	 Client: 1 thread for send-&-recv
> 
> 

In the case of a multi-core server without using system-specific I/O routines (kqueue, epoll, IOCP, etc), this is probably the simplest setup, if a little bit conservative.
I should note that on most modern systems, send() with a packet <1kb isn't non-blocking even if a non-blocking socket is used. Sending multiple packets together in "mega" packets is the optimal solution. If you absolutely need to send packets <1kb immediately (say, for a FPS), you can just pad the remaining bytes with garbage.

For the client, since this is seemingly just supposed to be a network framework, you should not create any threads at all. Often, the cost of programming (and debugging) time in ensuring proper synchronization is not worth the marginal improvement in performance; and over-synchronization (wrapping way more code in locks than needs to be) may even impair performance.

------------------------
Nate Fries




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20130321/47e6cadf/attachment-0009.htm>


More information about the SDL mailing list