select() function to avoid recv() lock