
2010/8/26 Brandon S Allbery KF8NH
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 8/26/10 05:13 , Vo Minh Thu wrote:
Is is possible to get Network.Socket.ByteString.recv to be non-blocking (i.e. return directly even if no data is available) ?
"What are you really trying to do?"
The Haskelly solution to this is to use threads; let the thread reading the socket block and the main thread synchronize with it somehow. (Haskell threads are very inexpensive; don't be afraid of them.)
Well, I have written the FFI and it works fine. What I'm doing is the networking part of a game loop following some nice ressource[0]. I'll wait a bit to have more experience with the code before changing how it is designed (e.g. using light threads). Fast paced 3D action games (and physics) networking seems quite involved. At first sight for instance, it seems easier to have an 'update' function for the networking code to detect timeout than to have it implemented on top of a waiting thread. (Such an update function is quite pervasive in a (imperative) game loop). Also the same socket is used both to read and write, so this would need additional synchronization. But thanks for the suggestion, it might be a good one later on. Cheers, Thu [0] http://gafferongames.wordpress.com/networking-for-game-programmers/