Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
svn-r7: satisfied with static performance, for now
darcs-hash:20070416220946-e5a07-58527017f4c0949edbe386974811c9288b59be2b.gz
- Loading branch information
Showing
14 changed files
with
110 additions
and
65 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,3 +23,4 @@ mlflags+=-I +threads | |
$(ocamlc) -c $< | ||
|
||
junk=*.cm? *~ | ||
sizes=01 02 04 08 16 32 64 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,56 @@ | ||
|
||
type t = { chan: out_channel; | ||
buf: Buffer.t; | ||
size: int } | ||
|
||
let create chan size = | ||
{ chan = chan; | ||
buf = Buffer.create size; | ||
size = size } | ||
|
||
let flush out = | ||
match Buffer.length out.buf with | ||
0 -> () | ||
| k -> | ||
Printf.fprintf out.chan "%x\r\n" k; | ||
Buffer.output_buffer out.chan out.buf; | ||
output_string out.chan "\r\n"; | ||
Buffer.clear out.buf | ||
|
||
let puts out str = | ||
Buffer.add_string out.buf str; | ||
if Buffer.length out.buf >= out.size | ||
then flush out | ||
|
||
let putc out char = | ||
Buffer.add_char out.buf char; | ||
if Buffer.length out.buf >= out.size | ||
then flush out | ||
|
||
let finish out = | ||
flush out; | ||
output_string out.chan "0\r\n" | ||
type t = | ||
{ fd: Unix.file_descr; | ||
buf: string; | ||
size: int; | ||
mutable pos: int | ||
} | ||
|
||
let descr fd size = | ||
{ fd = fd; | ||
buf = String.create size; | ||
size = size - 2; (* so there is always room for CR/LF *) | ||
pos = 0 } | ||
|
||
let channel ch size = | ||
flush ch; | ||
descr (Unix.descr_of_out_channel ch) size | ||
|
||
let write fd s n = | ||
let k = Unix.write fd s 0 n in | ||
if n <> k then failwith "Chunked.write: incomplete" | ||
|
||
let write_string fd s = | ||
write fd s (String.length s) | ||
|
||
let write_chunk_header fd n = | ||
write_string fd (Printf.sprintf "%x\r\n" n) | ||
|
||
let add_crlf s k = | ||
String.set s k '\r'; | ||
String.set s (k+1) '\n' | ||
|
||
let flush stream = | ||
let n = stream.pos in | ||
if n > 0 then | ||
(write_chunk_header stream.fd n; | ||
add_crlf stream.buf n; | ||
write stream.fd stream.buf (n+2); | ||
stream.pos <- 0) | ||
|
||
let puts stream text = | ||
let n = String.length text in | ||
if stream.pos + n > stream.size then | ||
flush stream; | ||
if n > stream.size then | ||
(write_chunk_header stream.fd n; | ||
write_string stream.fd text; | ||
write_string stream.fd "\r\n") | ||
else | ||
(String.blit text 0 stream.buf stream.pos n; | ||
stream.pos <- stream.pos + n) | ||
|
||
let finish stream = | ||
flush stream; | ||
write_string stream.fd "0\r\n" | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
type t | ||
val create : out_channel -> int -> t | ||
val channel : out_channel -> int -> t | ||
val descr : Unix.file_descr -> int -> t | ||
val puts : t -> string -> unit | ||
val flush : t -> unit | ||
val finish : t -> unit | ||
val puts : t -> string -> unit | ||
val putc : t -> char -> unit |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type code = Request.req -> (string -> unit) -> unit | ||
val run : code StringMap.t -> Server.handler | ||
val redirect : code StringMap.t -> Server.handler |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
open Unix | ||
|
||
let bufsize = 4096 | ||
|
||
module TMap = Map.Make | ||
(struct | ||
type t = Thread.t | ||
|
This file contains 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