Minor changes to the main loop for certain shutdown scenarios

When stopping a fake_ftp server I was experiencing problems where sockets were still be listened to after being closed, or methods were being called on objects which had been nilified.  These changes add extra guard conditions to prevent these problems.