Hold deque lock when popping in asyncore

In multithreaded environments, this could result in corruption of the
deque, leading to malformed messages.

Additionally, this change attempts multiple writes whenever select()
reports that the FD is available for writing, similar to what is already
done for libev.