Some fixes in blocking and synchronization for binary protocol and gateway