Skip to content
Browse files

[fix] stdlib: Protected reconnect with cell.

  • Loading branch information...
1 parent 9c006f0 commit fa4f60fa3f87cfe93a56db718c2ad4d8261f422c @nrs135 nrs135 committed Nov 28, 2011
Showing with 24 additions and 1 deletion.
  1. +24 −1 stdlib/apis/mongo/mongo.opa
View
25 stdlib/apis/mongo/mongo.opa
@@ -60,6 +60,7 @@ type Mongo.db = {
concurrency : Mongo.concurrency;
conn : Mutable.t(option(Socket.connection));
conncell : option(Cell.cell(Mongo.sr,Mongo.srr));
+ reconncell : Cell.cell(Mongo.reconnectmsg,Mongo.reconnectresult);
pool : Mutable.t(option(SocketPool.t));
pool_max : int;
close_socket : bool;
@@ -95,6 +96,9 @@ type Mongo.srr =
/ {stopresult}
/ {reconnect}
+@private type Mongo.reconnectmsg = {reconnect:(string,Mongo.db)} / {stop}
+@private type Mongo.reconnectresult = {reconnectresult:bool} / {stopresult}
+
@private
MongoDriver = {{
@@ -194,7 +198,7 @@ MongoDriver = {{
* won't ever be used but we limit the depth of the recursion.
*/
@private
- reconnect(from:string, m:Mongo.db): bool =
+ doreconnect(from:string, m:Mongo.db): bool =
if m.depth.get() > m.max_depth
then
do if m.log then ML.error("MongoDriver.reconnect({from})","max depth exceeded",void)
@@ -221,6 +225,24 @@ MongoDriver = {{
ret(false)
@private
+ reconfn(_, msg) =
+ match msg with
+ | {reconnect=(from,m)} -> {return={reconnectresult=doreconnect(from,m)}; instruction={unchanged}}
+ | {stop} -> {return={stopresult}; instruction={stop}}
+
+ @private
+ reconnect(from, m) =
+ match (Cell.call(m.reconncell,({reconnect=((from,m))}:Mongo.reconnectmsg)):Mongo.reconnectresult) with
+ | {reconnectresult=tf} -> tf
+ | _ -> @fail
+
+ @private
+ stoprecon(m) =
+ match Cell.call(m.reconncell,({stop}:Mongo.reconnectmsg)):Mongo.reconnectresult with
+ | {stopresult} -> void
+ | _ -> @fail
+
+ @private
// Rule: for every open_socket which returns success we must call close_socket
// Property: we can stack opens and the socket will only close once the last is closed
open_socket(m:Mongo.db): outcome(Socket.connection,Mongo.failure) =
@@ -466,6 +488,7 @@ MongoDriver = {{
{ ~concurrency;
~conn;
conncell=if concurrency == {cell} then {some=(Cell.make(conn, sr):Cell.cell(Mongo.sr,Mongo.srr))} else {none};
+ reconncell=(Cell.make(void, reconfn):Cell.cell(Mongo.reconnectmsg,Mongo.reconnectresult));
pool=Mutable.make({none}); ~pool_max;
~bufsize; ~close_socket; ~log; socket_link=Mutable.make(0);
seeds=[]; hosts=Mutable.make([]); name="";

0 comments on commit fa4f60f

Please sign in to comment.
Something went wrong with that request. Please try again.