From f1ff6b8b279f104a2772b895e476d17bf2bbe158 Mon Sep 17 00:00:00 2001 From: pavlobaron Date: Sun, 15 Apr 2012 12:41:38 +0200 Subject: [PATCH] Rebuilt code base, supervised worker (need tests), merged with drkrab --- include/riak_mongo_sock.hrl | 23 +++++++++++++++++++++++ src/riak_mongo_sock.erl | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 include/riak_mongo_sock.hrl create mode 100644 src/riak_mongo_sock.erl diff --git a/include/riak_mongo_sock.hrl b/include/riak_mongo_sock.hrl new file mode 100644 index 0000000..40affd2 --- /dev/null +++ b/include/riak_mongo_sock.hrl @@ -0,0 +1,23 @@ +%% +%% This file is part of riak_mongo +%% +%% Copyright (c) 2012 by Pavlo Baron (pb at pbit dot org) +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% + +%% @author Pavlo Baron +%% @doc Some reusable socket stuff +%% @copyright 2012 Pavlo Baron + +-define(SOCK_OPTS, [binary, {active, once}, {packet, 0}, {reuseaddr, true}]). diff --git a/src/riak_mongo_sock.erl b/src/riak_mongo_sock.erl new file mode 100644 index 0000000..3d9706e --- /dev/null +++ b/src/riak_mongo_sock.erl @@ -0,0 +1,32 @@ +%% +%% This file is part of riak_mongo +%% +%% Copyright (c) 2012 by Pavlo Baron (pb at pbit dot org) +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% + +%% @author Pavlo Baron +%% @doc Some socket stuff +%% @copyright 2012 Pavlo Baron + +-module(riak_mongo_sock). + +-export([change_control/3, give_control/2]). + +change_control(Sock, OldOwner, NewOwner) -> + OldOwner ! {controlling_process, Sock, NewOwner}. + +give_control(Sock, NewOwner) -> + gen_tcp:controlling_process(Sock, NewOwner), + NewOwner ! {control, Sock}.