From 9aca16b198a8e900d300cd5705cf7e825bd855ea Mon Sep 17 00:00:00 2001 From: pavlobaron Date: Sat, 7 Apr 2012 14:48:58 +0200 Subject: [PATCH] restuctured+mongo shell comes up w/o errors --- README | 4 ++-- src/riak_mongo_server.erl | 31 +------------------------------ 2 files changed, 3 insertions(+), 32 deletions(-) diff --git a/README b/README index 1ce673d..4b03241 100644 --- a/README +++ b/README @@ -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 diff --git a/src/riak_mongo_server.erl b/src/riak_mongo_server.erl index dbcd3dd..8350e44 100644 --- a/src/riak_mongo_server.erl +++ b/src/riak_mongo_server.erl @@ -29,10 +29,6 @@ -export([add_listener/1]). --include("mongo.hrl"). - --define(ERROR, "error\n"). - -behavior(gen_nb_server). start_link() -> @@ -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).