Fix hang when sending packets on closed connection

credit to Michael Schrijver <michael@hating.biz> for finding the problem