Skip to content

Commit

Permalink
nitro
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Aug 31, 2015
1 parent 3df6b36 commit 7d35bd1
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013 Maxim Sokhatsky, Synrc Research Center
Copyright (c) 2013—2015 Maxim Sokhatsky, Synrc Research Center

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
49 changes: 26 additions & 23 deletions include/wf.hrl
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
-ifndef(N2O_HRL).
-define(N2O_HRL, true).

-define(CTX, (wf_context:context())).
-define(REQ, (wf_context:context())#cx.req).
-record(handler, { name, module, config, state}).
-record(cx, { handlers, actions, req, module, lang, path, session, params, form, state=[] }).

-define(ACTION(Module), ancestor=action, trigger, target, module=Module, actions, source=[]).
-define(CTX, (get(context))).
-define(REQ, (get(context))#cx.req).

% Actions
-record(wire, {?ACTION(action_wire)}).
-record(event, {?ACTION(action_event)}).
-record(jq, {?ACTION(action_jq), property, method, args=[], right, format="~s"}).
% API

-define(HANDLER_API, [init/2, finish/2]).
-define(FAULTER_API, [error_page/2]).
Expand All @@ -19,20 +17,25 @@
-define(PICKLES_API, [pickle/1, depickle/1]).
-define(MESSAGE_API, [send/2, reg/1, reg/2, unreg/1]).

-record(handler, {name, module, config, state}).
-record(cx, {handlers, actions, req, module, lang, path, session, params, form, state=[]}).
-record(ev, {module, msg, trigger, name :: api_event | control_event | event | atom() }).

%Binary messaging to browser
-record(binary, {
id = 0 :: integer(), % 4 bytes unsigned
type = 0 :: integer(), % 1 byte unsigned
app = 0 :: integer(), % 1 byte unsigned
version = 0 :: integer(), % 1 byte unsigned
from = 0 :: integer(), % 4 bytes unsigned
to = 0 :: integer(), % 4 bytes unsigned
user1 = 0 :: integer(), % 8 bytes signed float, user defined, e.g.: -define(TIMESTAMP, user1).
user2 = 0 :: integer(), % 8 bytes signed float, user defined, e.g.: -define(EXPIRES, user2).
meta = <<>> :: binary(), % binary
data = <<>> :: binary() }). % binary
% IO protocol

-record(io, { eval, data }).
-record(bin, { meta, data }).

% Client/Server protocol

-record(client, { data }).
-record(server, { data }).

% Nitrogen Protocol

-record(pickle, { source, pickled, args }).
-record(flush, { data }).
-record(direct, { data }).
-record(ev, { module, msg, trigger, name }).

% File Transfer Protocol

-record(ftp, { id, type, app, version, from, to, meta, data }).

-endif.
1 change: 1 addition & 0 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{lib_dirs,[".."]}.
{deps_dir,["deps"]}.
{deps,[
{nitro, ".*", {git, "git://github.com/synrc/nitro.git", {tag,"master"}}},
{jsone, ".*", {git, "git://github.com/sile/jsone.git", {tag,"v0.3.3"}}},
{cowboy, ".*", {git, "git://github.com/extend/cowboy", {tag,"1.0.1"}}},
{gproc, ".*", {git, "git://github.com/uwiger/gproc.git", {tag,"0.3"}}}
Expand Down
2 changes: 1 addition & 1 deletion src/n2o.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, n2o, [
{description, "N2O WebSocket Application Server"},
{vsn, "2.9"},
{applications, [kernel, stdlib, cowboy, ranch, gproc]},
{applications, [kernel, stdlib, cowboy, gproc]},
{modules, []},
{registered, []},
{mod, { n2o_app, []}},
Expand Down
9 changes: 4 additions & 5 deletions src/protocols/n2o_binary.erl → src/protocols/n2o_file.erl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-module(n2o_binary).
-module(n2o_file).
-author('Andrey Martemyanov').
-include_lib("n2o/include/wf.hrl").
-compile(export_all).
Expand All @@ -14,13 +14,12 @@ info({bin,Message}, Req, State) ->
Term = try Module:event({bin,DpkldMessage}) catch E:R -> wf:error(?MODULE,"Catch: ~p:~p~n~p", wf:stack(E, R)), <<>> end,
wf:info(?MODULE,"Raw Binary Message: ~p Result: ~p",[Message,Term]),
Res = case Term of
#binary{
#ftp{
id=Id, type=Type, app=App, version=Version,
from=From, to=To, user1=User1, user2=User2, meta=Meta, data=Data } ->
from=From, to=To, meta=Meta, data=Data } ->
MetaSize = byte_size(Meta),
<<132,Id:32,Type:8,App:8,Version:8,
From:32,To:32,User1:64/float,User2:64/float,
MetaSize:32,Meta/binary,Data/binary>>;
From:32,To:32,MetaSize:32,Meta/binary,Data/binary>>;
_ when is_binary(Term) -> Term;
_ -> term_to_binary(Term) end,
{reply,{binary,Res},Req,State};
Expand Down

0 comments on commit 7d35bd1

Please sign in to comment.