Skip to main content

Posts

Showing posts with the label you're doing it wrong

How to call select() - the CORRECT way!

There is a TON of broken code out on the Internet with lots of programmers who enter the world of TCP/IP socket development and think they have figured out how to write socket code. They then disseminate their broken code to others who, in turn, disseminate broken code to other people. One of the most egregious problems plaguing the world of software development today is the use, or abuse, of select(). Today, you are going to contribute to fixing this problem once and for all by reading what I have to say and then ingraining it into your brainz. There are two types of file descriptors/sockets/what-have-you: Blocking and non-blocking. Sometimes referred to as synchronous and asynchronous. If you are using select() on synchronous sockets in your code, you are doing it wrong! select() is ONLY for asynchronous sockets. Think of it this way: A synchronous socket is you telling the OS that you know the exact order of operations on that socket (e.g. POP3) and are willing to wai...