2011/7/18 Casey Marshall <[email protected]>: > Hi! > > I'm writing a new software project, and am using enet for part of the > transport protocol, and had a few questions. > > The biggest question I have is how to use enet in a select-based (or, more > likely, epoll-based) loop: waiting for events via an interface like epoll, > and on activity, drive the enet connections. > > Now, it makes sense that I can run a selection on a ENetHost's socket for > readability, and invoke enet_host_service then. What I'm missing, though, is > when to call enet_host_service for writable events: I assume, from looking a > bit at the code, that enet_host_service needs to be called regularly to > dispatch both incoming and outgoing messages, but I don't think you want to > call enet_host_service on *every* writable event, if there is nothing going > out, because that would lead to a busy-loop, which I want to avoid (the idea > here is that I would call enet_host_service with a very small timeout, > probably zero). Is there a way to tell from an ENetHost or a bunch of > ENetPeers whether or not there is pending outgoing messages?
ENet was developed for a fast multiplayer gaming environment (but not limited to that). Such games consist of a gameloop, which is executed fairly often (the framerate for example is limited to the execution frequency of the gameloop, althought the gameloop may be executed even more often). In such an evironment, it makes sense, to call enet_host_service in the gameloop with a timeout of 0. To my understanding, that is the purpose of enet. With that in mind, you can decide, if and how it makes sense to use enet in your project. Bottomline is, you can call enet_host_service very often, even if there's nothing to do, without a significant penalty. > The short answer to why I want to do this is because I want to write an addon > for Node that wraps enet, and Node has its fairly specific way of doing > things. I suppose this can also be accomplished by doing the enet service > calls in a separate thread, but I was hoping to avoid that. > > A related question is how many simultaneous peers can enet support? 100? > 1,000? 10,000? Interesting question. Lee? > And lastly, any idea what the behavior should be for a "simultaneous > connect"? That is, two peers attempt to connect to one another at the same > time, on the same ports? Would the ENetPeer objects returned by > enet_host_connect both be valid? You cannot connect a peer to another peer, but a peer to a host. Thus, if you have two machines with two hosts and peers, you can connect the peers to the other host and have two valid connections, i suppose. But that's probably not what you want. You need to think of a mechanism to manage your connections. > Thanks! > _______________________________________________ > ENet-discuss mailing list > [email protected] > http://lists.cubik.org/mailman/listinfo/enet-discuss > _______________________________________________ ENet-discuss mailing list [email protected] http://lists.cubik.org/mailman/listinfo/enet-discuss
