eventmachine/eventmachine — pull request #272 by abrody (2011-10-13 02:07:53+00:00)
Title: Add a method to stop EM gracefully.

EventMachine_t::ScheduleHalt() currently will break out of the main event loop even if there is data that still remains to be written to sockets. The new method ScheduleGracefulHalt schedules a close of all open sockets and waits until they have closed to actually exit.

This behavior can be seen with a very simple server: https://gist.github.com/1283144

The server replies to each message the client sends, but the client never actually receives the message when stop is called instead of graceful_stop.

```
andy@zara:~$ nc localhost 8081
Hello!
hi
Received 3 bytes
graceful_stop
Received 14 bytes
andy@zara:~$
```
```
andy@zara:~$ nc localhost 8081
Hello!
hi
Received 3 bytes
stop
andy@zara:~$
```