Fix bugs in logging and socket write

Reviewer: @kenchiang

I also did a cleanup pass over ofconnectionmanager.c removing unnecessary and error-prone uses of the connection ID.