- Clone https://github.com/MLstate/opalang
- Install bld with
make install-bld - In the opalang root directory, compile opa_scheduler.ml with
bld opa_scheduler.native - Run it with
_build/opa_scheduler.native
Created
October 10, 2011 12:44
-
-
Save cedricss/1275216 to your computer and use it in GitHub Desktop.
OPA scheduler serving an http "Hello world" page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let _ = | |
| let header = | |
| "HTTP/1.1 200 OK\r\n\ | |
| Connection: close\r\n\ | |
| Expires: Fri, 31 Dec 2012 14:36:01 GMT\r\n\ | |
| Content-Length: 20\r\n\ | |
| Content-Type: text/html\r\n\ | |
| Server: OPA/7508\r\n\ | |
| Date: Fri, 31 Dec 2012 14:36:01 GMT\r\n\r\n" | |
| in | |
| let body = "<h1>Hello world</h1>" in | |
| let r = Printf.sprintf "%s%s" header body in | |
| let sched = Scheduler.make () in | |
| let port_spec = Network.make_port_spec ~protocol:"HTTP" (Unix.inet_addr_of_string "0.0.0.0") 8080 in | |
| let answer_hello conn = | |
| Scheduler.write sched conn r (fun _ -> Scheduler.remove_connection sched conn); | |
| in | |
| let new_client _ conn = | |
| Scheduler.read sched conn (fun (_, _) -> answer_hello conn) | |
| in | |
| let _ = Network.listen sched port_spec Network.Unsecured new_client in | |
| Network.loop sched; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment