Refactor CastSocket code for the following:
- Refactor the Write code to avoid recursion
- Refactor the read code to avoid recursion
- With read code refactored, hook it up appropriately with connection flow
  to avoid re-entrancy of DoConnectLoop

Review URL: https://codereview.chromium.org/79673003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242158 0039d316-1c4b-4281-b951-d872f2087c98
SVN changes up to revision 242158