Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 34 lines (31 sloc) 0.76 kb
ef18247f »
2012-01-07 Initial commit
1 open Unix
2 open Printf
3 open Thread
4
5 let conn_main s =
6 let cout = out_channel_of_descr s in
7 let rec count n =
8 match n with
9 | 0 ->
10 fprintf cout "Bye!\r\n%!"
11 | _ ->
12 fprintf cout "Hello %d\r\n%!" n;
13 Thread.delay 0.5;
14 count (n - 1)
15 in
16 count 10;
17 printf "Closing the connection.\n%!";
18 flush cout;
19 close s
20
21 let rec accept_loop sock =
22 let (s, _) = accept sock in
23 printf "Accepted a connection.\n%!";
24 let _ = Thread.create conn_main s in
25 accept_loop sock
26
27 let _ =
c952c33e »
2012-01-08 Catch and ignore SIGPIPE
28 Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
ef18247f »
2012-01-07 Initial commit
29 let sock = socket PF_INET SOCK_STREAM 0 in
30 setsockopt sock SO_REUSEADDR true;
31 bind sock (ADDR_INET (inet_addr_of_string "0.0.0.0", 8989));
32 listen sock 5;
33 printf "Entering accept loop...\n%!";
34 accept_loop sock
Something went wrong with that request. Please try again.