Change socket read from blocking to non-blocking and using select, add timeout return value.