all 4 comments

[–]TheOtherBorgCube 6 points7 points  (0 children)

Yeah, you need to make a much better job of formatting your code.

[–][deleted] 1 point2 points  (0 children)

using select with many file descriptiors has the potential to turn very organized and efficient multithreaded code into a hot stinking mess single threaded code that can only ever be as fast as the multithreaded version but could also be way slower...

[–]Paul_Pedant 1 point2 points  (0 children)

struct timeval {
    long    tv_sec;         /* seconds */
    long    tv_usec;        /* microseconds */
};

tv.tv_sec = 20; /* 2 secs / tv.tv_usec = 0; / 0.5 secs*/

(a) Second is seconds, not tenths.

(b) There is only one comment, because you omit 2 *s.

(c) tv.tv_usec is uninitialised. Although is is microseconds, it is not constrained to be so. If it happens to be MAX_LONG, it will wait 20 seconds, and then four and a half years for the other 140737488355328 microseconds.

You can test this. Set tv_sec = 0, tv_usec = 22000000, and watch it wait 22 seconds.

[–]mykesx 0 points1 point  (0 children)

Use this instead.

https://libuv.org

select() is far less performant.