anchor.diff:  -spec upgrade(pid(), module(), any(), cowboy_req:req()) -> closed.
   upgrade(ListenerPid, Handler, Opts, Req) ->
   	ranch_listener:remove_connection(ListenerPid),
  -	case catch websocket_upgrade(#state{handler=Handler, opts=Opts}, Req) of
  -		{ok, State, Req2} -> handler_init(State, Req2);
  +	{ok, Transport, Socket} = cowboy_req:transport(Req),
  +	State = #state{socket=Socket, transport=Transport,
  +		handler=Handler, opts=Opts},
  +	case catch websocket_upgrade(State, Req) of
  +		{ok, State2, Req2} -> handler_init(State2, Req2);
   		{'EXIT', _Reason} -> upgrade_error(Req)
   	end.
   
  
positive.code: 
  %% @private
  -spec handler_loop(#state{}, cowboy_req:req(), any(), binary()) -> closed.
  handler_loop(State=#state{messages={OK, Closed, Error}, timeout_ref=TRef},
  		Req=#http_req{socket=Socket}, HandlerState, SoFar) ->
  	receive
  		{OK, Socket, Data} ->
  			websocket_data(State, Req, HandlerState,
  
negative.code: 
  -spec websocket_close(#state{}, cowboy_req:req(), any(), {atom(), atom()})
  	-> closed.
  websocket_close(State=#state{socket=Socket, transport=Transport, version=0},
  		Req, HandlerState, Reason) ->
  	Transport:send(Socket, << 255, 0 >>),
  	handler_terminate(State, Req, HandlerState, Reason);
  %% @todo Send a Payload? Using Reason is usually good but we're quite careless.
  websocket_close(State=#state{socket=Socket, transport=Transport},
  		Req, HandlerState, Reason) ->
  	Transport:send(Socket, << 1:1, 0:3, 8:4, 0:8 >>),
  	handler_terminate(State, Req, HandlerState, Reason).
  
  