Commits

Anonymous committed 4141369

topoman init, now works as 'echo' on dumbstreaming protocol

Comments (0)

Files changed (5)

 (* OASIS_START *)
-(* DO NOT EDIT (digest: e318d64c36e2ed4d6c0f450d80206080) *)
+(* DO NOT EDIT (digest: 576f62a02a97352dc9872f6b0ef27f52) *)
 This is the INSTALL file for the parvel distribution.
 
 This package uses OASIS to generate its build system. See section OASIS for
 * monad_io
 * substrings
 * cadastr
+* iteratees for executable topoman
+* dumbstreaming for executable topoman
 
 Installing
 ==========
   Type:     hg
   Location: https://bitbucket.org/gds/parvel/
   
+Executable topoman
+  Path:       .
+  BuildTools: ocamlbuild
+  MainIs:     topoman.ml
+  Install:    false
+  BuildDepends: iteratees, dumbstreaming.it, dumbstreaming.io
 # OASIS_START
-# DO NOT EDIT (digest: f02666ee37a48fded1c4483839e15c8e)
+# DO NOT EDIT (digest: fb20100e30623c6468a2641577dbdcd0)
 # Ignore VCS directories, you can use the same kind of rule outside 
 # OASIS_START/STOP if you want to exclude directories that contains 
 # useless stuff for the build process
 "tests.byte": pkg_lwt.unix
 "tests.byte": pkg_lwt
 "tests.byte": pkg_cadastr
+# Executable topoman
+"topoman.byte": pkg_unix
+"topoman.byte": pkg_substrings
+"topoman.byte": pkg_monad_io.lwt
+"topoman.byte": pkg_monad_io
+"topoman.byte": pkg_lwt.unix
+"topoman.byte": pkg_lwt
+"topoman.byte": pkg_iteratees
+"topoman.byte": pkg_dumbstreaming.it
+"topoman.byte": pkg_dumbstreaming.io
+"topoman.byte": pkg_cadastr
 <*.ml{,i}>: pkg_unix
 <*.ml{,i}>: pkg_substrings
 <*.ml{,i}>: pkg_monad_io.lwt
 <*.ml{,i}>: pkg_monad_io
 <*.ml{,i}>: pkg_lwt.unix
 <*.ml{,i}>: pkg_lwt
+<*.ml{,i}>: pkg_iteratees
+<*.ml{,i}>: pkg_dumbstreaming.it
+<*.ml{,i}>: pkg_dumbstreaming.io
 <*.ml{,i}>: pkg_cadastr
 # OASIS_STOP
 
 (* setup.ml generated for the first time by OASIS v0.2.1~alpha1 *)
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: 8f57c82dcb3f66ff543af6cae387461c) *)
+(* DO NOT EDIT (digest: 2137ed5b38c10fe6900c86dcf2240e42) *)
 (*
    Regenerated by OASIS v0.2.1~alpha1
    Visit http://oasis.forge.ocamlcore.org for more information and
                       bs_nativeopt = [(OASISExpr.EBool true, [])];
                       },
                    {exec_custom = false; exec_main_is = "tests.ml"; });
+               Executable
+                 ({
+                     cs_name = "topoman";
+                     cs_data = PropList.Data.create ();
+                     cs_plugin_data = [];
+                     },
+                   {
+                      bs_build = [(OASISExpr.EBool true, true)];
+                      bs_install = [(OASISExpr.EBool true, false)];
+                      bs_path = ".";
+                      bs_compiled_object = Byte;
+                      bs_build_depends =
+                        [
+                           FindlibPackage ("unix", None);
+                           FindlibPackage ("lwt", None);
+                           FindlibPackage ("lwt.unix", None);
+                           FindlibPackage ("monad_io", None);
+                           FindlibPackage ("monad_io.lwt", None);
+                           FindlibPackage ("substrings", None);
+                           FindlibPackage ("cadastr", None);
+                           FindlibPackage ("iteratees", None);
+                           FindlibPackage ("dumbstreaming.it", None);
+                           FindlibPackage ("dumbstreaming.io", None)
+                        ];
+                      bs_build_tools = [ExternalTool "ocamlbuild"];
+                      bs_c_sources = [];
+                      bs_data_files = [];
+                      bs_ccopt = [(OASISExpr.EBool true, [])];
+                      bs_cclib = [(OASISExpr.EBool true, [])];
+                      bs_dlllib = [(OASISExpr.EBool true, [])];
+                      bs_dllpath = [(OASISExpr.EBool true, [])];
+                      bs_byteopt = [(OASISExpr.EBool true, [])];
+                      bs_nativeopt = [(OASISExpr.EBool true, [])];
+                      },
+                   {exec_custom = false; exec_main_is = "topoman.ml"; });
                SrcRepo
                  ({
                      cs_name = "default";
+open Cd_All; open Cdt;
+
+
+open Unix
+;
+
+value listen_interface = inet_addr_loopback
+;
+
+value listen_port = 22528
+;
+
+value listen_addr : sockaddr =
+  ADDR_INET listen_interface listen_port
+;
+
+
+module I = Iteratees.Make(IO_Lwt);
+module IO = I.It_IO;
+open I.Ops;
+
+module Ds_it = Dumbstreaming_it.Make(I);
+module Ds_io = Dumbstreaming_io.Make(IO_Lwt);
+
+
+value proc_request rq =
+  ["echo"; String.concat ";" & List.map String.escaped rq]
+;
+
+
+value rq_max_totalsize = 10240L
+;
+
+exception Srv of string
+;
+
+value get_request =
+    (
+       Ds_it.read
+         ~get_piece_it:
+            (fun ~totalsize
+                 ~totalcount
+                 ~piecesize
+                 ~piecenumber ->
+               let () = ( ignore totalcount ; ignore piecesize
+                        ; ignore piecenumber )
+               in
+               if totalsize > rq_max_totalsize
+               then
+                 I.throw_err & Srv "request too long"
+               else
+                 I.gather_to_string
+            )
+         ~combine_it:
+            I.stream2list
+    )
+;
+
+
+value send_response outch rs =
+  Ds_io.write outch rs >>% fun () -> IO_Lwt.flush outch
+;
+
+value send_error outch err =
+  let rec str err =
+    match err with
+    [ I.Iteratees_err_msg e -> str e
+    | e -> Printexc.to_string e
+    ]
+  in
+  Ds_io.write outch
+    [ "error"
+    ; str err
+    ]
+;
+
+
+value proc_conn (inch, outch) : unit = Lwt_main.run &
+  (I.enum_fd inch &
+        inner ()
+        where rec inner () =
+          get_request >>= fun
+          [ None -> I.return ()
+          | Some rq ->
+              let rs = proc_request rq in
+              I.lift (send_response outch rs) >>= fun () ->
+              inner ()
+          ]
+  )
+  >>% fun i ->
+  IO.catch
+    (fun () -> I.run i)
+    (fun e -> send_error outch e)
+  >>% fun () ->
+  IO_Lwt.close_out outch
+;
+
+
+value (server : IO_Lwt.server) = IO_Lwt.establish_server
+  ~buffer_size:4096
+  ~backlog:5
+  listen_addr
+  proc_conn
+;
+
+value () = Lwt_main.run (IO_Lwt.wait_server server)
+;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.