multi-threaded socket app
-
i want to make my own multi-thread socket classes (really really simple ones, so i can use them in my small games and such, and just to learn) i want to create a thread that will call select() and will allow for me to wait for feedback on a set of sockets however, i want to interrupt select() so that i can add sockets to the select list when the user calls AddSocket() how would i do that? i dont want to forcefully end the thread, nor do i want to create a thread per-socket hmm?
r -€
-
i want to make my own multi-thread socket classes (really really simple ones, so i can use them in my small games and such, and just to learn) i want to create a thread that will call select() and will allow for me to wait for feedback on a set of sockets however, i want to interrupt select() so that i can add sockets to the select list when the user calls AddSocket() how would i do that? i dont want to forcefully end the thread, nor do i want to create a thread per-socket hmm?
r -€
Well, I don't think you can interrupt select. But, if you want to start a thread to respond to socket events on a set of sockets, you may consider calling WSAEventSelect instead. Associate an event handle with each socket, register for events you are interested in with WSAEventSelect for each socket, then to wait for the events, call WSAWaitFormultipleEvents. The thing about this is that the array of event handles can include other events besides socket events. So, maybe the 0th event handle could be an event that another thread could use to signal the thread that is waiting for the sockets to do something else, like shutdown, or whatever else.