Select | developer.brewmp.com Select | developer.brewmp.com

Developer

Select

Forums:

Is it possible to create an unix-like SELECT call in BREW 3.1 to check for data on a set of sockets ?

aruldeepak wrote:Is it possible to create an unix-like SELECT call in BREW 3.1 to check for data on a set of sockets ?
Sort of, but you'd need to wrap it in your own class. Let's imagine you've implemented the IMYSOCKET_Interface, which inherits from ISOCKET but adds IMYSOCKET_IsReadable()
The implementation of IMYSOCKET_IsReadable then reads a byte using ISOCKET_Read. If that actually returns a byte of data, it caches it, and returns TRUE, otherwise it returns FALSE. If you call IMYSOCKET_IsReadable twice in succession without an intervening IMYSOCKET_Read, then it should not read any data, but just return TRUE - because the cached byte is available to be read.
When the client then calls IMYSOCKET_Read, we interpose the cached data.
Clearly you can now implement some sort of select() call by making use of IMYSOCKET_IsReadable().
This only works for checking readability though. We can't check writeability in the same way.

aruldeepak wrote:Is it possible to create an unix-like SELECT call in BREW 3.1 to check for data on a set of sockets ?
Sort of, but you'd need to wrap it in your own class. Let's imagine you've implemented the IMYSOCKET_Interface, which inherits from ISOCKET but adds IMYSOCKET_IsReadable()
The implementation of IMYSOCKET_IsReadable then reads a byte using ISOCKET_Read. If that actually returns a byte of data, it caches it, and returns TRUE, otherwise it returns FALSE. If you call IMYSOCKET_IsReadable twice in succession without an intervening IMYSOCKET_Read, then it should not read any data, but just return TRUE - because the cached byte is available to be read.
When the client then calls IMYSOCKET_Read, we interpose the cached data.
Clearly you can now implement some sort of select() call by making use of IMYSOCKET_IsReadable().
This only works for checking readability though. We can't check writeability in the same way.