Reimplemented the timeout to actually work. It is implemented by making the socket non-block, select() for it, wait until something happens or timeout.