Skip to content

Commit

Permalink
ayy server
Browse files Browse the repository at this point in the history
  • Loading branch information
steinuil committed Aug 25, 2019
1 parent a760148 commit 86ef7a4
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,10 +1,12 @@
_build
.merlin
.mirage.config
config/
key_gen.ml
main.ml
main.native
Makefile
mirage-unikernel-*.install
mirage-unikernel-*.opam
myocamlbuild.ml
vxrrks
13 changes: 11 additions & 2 deletions config.ml
Expand Up @@ -2,14 +2,23 @@ open Mirage

let packages = [
package "duration";
package "logs";
package "lwt_ppx";
package "cohttp";
package "cohttp-mirage";
package "mirage-conduit";
]

let main =
foreign
"Unikernel.Main"
~packages
(time @-> job)
(http @-> job)

let stack =
socket_stackv4 [Ipaddr.V4.any]

let http_srv = cohttp_server @@ conduit_direct stack

let () =
register "vxrrks" [main $ default_time]
register "vxrrks" [main $ http_srv]
2 changes: 1 addition & 1 deletion default.nix
Expand Up @@ -3,7 +3,7 @@ with pkgs;
stdenv.mkDerivation rec {
name = "aaaaaaa";

buildInputs = [ clang m4 binutils pkgconfig ];
buildInputs = [ clang m4 binutils pkgconfig gmp autoconf ];

shellHook = ''
eval $(opam env)
Expand Down
17 changes: 17 additions & 0 deletions dune
@@ -0,0 +1,17 @@
(executable
(public_name vxrrks)
(name main)
(modules unikernel main key_gen)
(libraries
vxrrks_server
cohttp-mirage
functoria-runtime
mirage-bootvar-unix
mirage-clock-unix
mirage-conduit
mirage-logs
mirage-runtime
mirage-types-lwt
mirage-unix
nocrypto.lwt
tcpip.stack-socket))
1 change: 1 addition & 0 deletions dune-project
@@ -0,0 +1 @@
(lang dune 1.11)
4 changes: 4 additions & 0 deletions server/dune
@@ -0,0 +1,4 @@
(library
(name vxrrks_server)
(libraries lwt cohttp-lwt)
(preprocess (pps lwt_ppx)))
13 changes: 13 additions & 0 deletions server/server.ml
@@ -0,0 +1,13 @@
module type SERVER = Cohttp_lwt.S.Server

module Make (Cohttp_server : SERVER) = struct
let make () =
let callback _conn _req _body =
let%lwt res, body =
Cohttp_server.respond_string ~status:`OK ~body:"ayy" ()
in
Lwt.return @@ `Response (res, body)
in
let conn_closed _ = () in
Cohttp_server.make_response_action ~callback ~conn_closed ()
end
15 changes: 7 additions & 8 deletions unikernel.ml
@@ -1,11 +1,10 @@
module T = Mirage_types_lwt
module type HTTP = Cohttp_lwt.S.Server

module Main (Time : T.TIME) = struct
let start _time =
let rec loop () =
Logs.info (fun f -> f "soap");
Time.sleep_ns (Duration.of_sec 1);%lwt
loop ()
in
loop ()
module Main (Http : HTTP) = struct
module Server = Vxrrks_server.Server.Make(Http)

let start http =
let tcp = `TCP 8080 in
http tcp @@ Server.make ()
end

0 comments on commit 86ef7a4

Please sign in to comment.