~ubuntu-branches/ubuntu/saucy/rabbitmq-server/saucy

« back to all changes in this revision

Viewing changes to plugins-src/cowboy-wrapper/cowboy-git/test/http_handler_long_polling.erl

  • Committer: Package Import Robot
  • Author(s): Emile Joubert
  • Date: 2012-11-19 11:42:31 UTC
  • mfrom: (0.2.18) (0.1.32 sid)
  • Revision ID: package-import@ubuntu.com-20121119114231-hvapkn4akng09etr
Tags: 3.0.0-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%% Feel free to use, reuse and abuse the code in this file.
 
2
 
 
3
-module(http_handler_long_polling).
 
4
-behaviour(cowboy_http_handler).
 
5
-export([init/3, handle/2, info/3, terminate/2]).
 
6
 
 
7
init({_Transport, http}, Req, _Opts) ->
 
8
        erlang:send_after(500, self(), timeout),
 
9
        {loop, Req, 9, 5000, hibernate}.
 
10
 
 
11
handle(_Req, _State) ->
 
12
        exit(badarg).
 
13
 
 
14
info(timeout, Req, 0) ->
 
15
        {ok, Req2} = cowboy_http_req:reply(102, Req),
 
16
        {ok, Req2, 0};
 
17
info(timeout, Req, State) ->
 
18
        erlang:send_after(500, self(), timeout),
 
19
        {loop, Req, State - 1, hibernate}.
 
20
 
 
21
terminate(_Req, _State) ->
 
22
        ok.