anchor.diff:                                              {cacertfile,
                                                "/home/andrew/riak_test/priv/certs/cacert.org/ca/root.crt"}], 1000) of
                           {ok, SSLSock} ->
  -                            io:format("STARTTLS suceeded~n"),
                               ok = ssl:setopts(SSLSock, [{active, once}]),
  -                            start_auth(State#state{sock=SSLSock});
  +                            start_auth(State#state{sock=SSLSock, transport=ssl});
                           {error, Reason2} ->
                               {error, Reason2}
                       end;
                   #rpberrorresp{} ->
                       %% server doesn't know about STARTTLS or security is
                       %% disabled, continue as normal
  +                    ok = inet:setopts(Sock, [{active, once}]),
                       {ok, State}
               end
       end.
   
   start_auth(State=#state{credentials={User,Pass}, sock=Sock}) ->
  -    io:format("sending auth~n"),
       ssl:send(Sock, riak_pb_codec:encode(#rpbauthreq{user=User,
                                                       password=Pass})),
       receive
  
positive.code:             [MsgCode|MsgData] = Data,
              case riak_pb_codec:decode(MsgCode, MsgData) of
                  rpbauthresp ->
                      io:format("auth suceeded~n"),
                      {ok, State};
                  #rpberrorresp{} = Err ->
                      io:format("auth failed~n"),
                      fmt_err_msg(Err)
              end
      end.
  
negative.code: %% for responding to the second form of send_request.
  send_request(#request{msg = {tunneled,MsgId,Pkt}}=Msg, State) when State#state.active =:= undefined ->
      Request = Msg#request{msg = {tunneled,MsgId}},
      Transport = State#state.transport,
      case Transport:send(State#state.sock, [MsgId|Pkt]) of
          ok ->
              State#state{active = Request};
          {error, closed} ->
              Transport:close(State#state.sock),
              maybe_enqueue_and_reconnect(Msg, State#state{sock=undefined})
      end;
  %% Unencoded Request (the normal PB client path)
  send_request(Request, State) when State#state.active =:= undefined ->
      Pkt = riak_pb_codec:encode(Request#request.msg),
      Transport = State#state.transport,
      case Transport:send(State#state.sock, Pkt) of
          ok ->
              maybe_reply(after_send(Request, State#state{active = Request}));
          {error, closed} ->
              Transport:close(State#state.sock),
              maybe_enqueue_and_reconnect(Request, State#state{sock=undefined})
      end.
  
  