backport socks codec to 3 branch