Skip to content

Commit

Permalink
restuctured+mongo shell comes up w/o errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlobaron committed Apr 7, 2012
1 parent a9d66cb commit 9aca16b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README
Expand Up @@ -6,8 +6,8 @@ server. I use to do "make dev" after compilation and to call

> riak_mongo:start(temporary, ["127.0.0.1", 32323]).

The mongo shell is called like "mongo --verbose -port 32323". And I get the prompt now,
though ignoring one TCP packet yet. No SSL and no IPv6 yet, just the first basics. Also
The mongo shell is called like "mongo --verbose -port 32323". And I get the prompt now.
No SSL and no IPv6 yet, just the first basics. Also
the beauty of the code can be discussed, but shouldn't be yet.

The very huge task will of course be to understand and translate to Riak all the
Expand Down
31 changes: 1 addition & 30 deletions src/riak_mongo_server.erl
Expand Up @@ -29,10 +29,6 @@

-export([add_listener/1]).

-include("mongo.hrl").

-define(ERROR, "error\n").

-behavior(gen_nb_server).

start_link() ->
Expand Down Expand Up @@ -95,31 +91,6 @@ worker(Owner, Sock) ->
gen_tcp:controlling_process(Sock, Owner).

worker(Owner, Sock, Data) ->
gen_tcp:send(Sock, process_data(Sock, Data)),
gen_tcp:send(Sock, wire_protocol:process_data(Sock, Data)),
inet:setopts(Sock, [{active, once}]),
gen_tcp:controlling_process(Sock, Owner).

process_data(Sock, ?MSG(?OP_QUERY)) ->
process_query(Sock, ID, Rest);

process_data(_, _) ->
?ERROR.

process_query(Sock, ID, ?QUERY(?CMD)) ->
process_cmd(Sock, ID, bson_binary:get_document(Rest));

process_query(_, _, _) ->
?ERROR.

process_cmd(Sock, ID, {{whatsmyuri, 1}, _}) ->
{ok, {{A, B, C, D}, P}} = inet:peername(Sock), %IPv6???
You = io_lib:format("~p.~p.~p.~p:~p", [A, B, C, D, P]),
reply(ID, {you, list_to_binary(You), ok, 1});

process_cmd(_, _, _) ->
?ERROR.

reply(ID, T) ->
Res = bson_binary:put_document(T),
L = byte_size(Res) + 36,
?REPLY(L, ID, 0, ?OP_REPLY, 8, 0, 0, 1, Res).

0 comments on commit 9aca16b

Please sign in to comment.