Better domain
This commit is contained in:
@@ -33,11 +33,15 @@ type FieldLine =
|
||||
// obvious candidate to improve speed by allocating less
|
||||
this.ToString () |> Encoding.ASCII.GetBytes |> request.AddRange
|
||||
|
||||
type ContentTransfer =
|
||||
| ContentLength
|
||||
| TransferEncoding of string
|
||||
|
||||
type HttpRequest =
|
||||
{
|
||||
Request : RequestLine
|
||||
Headers : FieldLine list
|
||||
Body : byte[]
|
||||
Body : (byte[] * ContentTransfer) option
|
||||
}
|
||||
|
||||
member this.ToBytes () : byte[] =
|
||||
@@ -64,7 +68,21 @@ type HttpRequest =
|
||||
builder.Add (byte '\r')
|
||||
builder.Add (byte '\n')
|
||||
|
||||
match this.Body with
|
||||
| None -> ()
|
||||
| Some (_, ContentTransfer.TransferEncoding encoding) ->
|
||||
builder.AddRange (Encoding.ASCII.GetBytes "Transfer-Encoding: ")
|
||||
builder.AddRange (Encoding.ASCII.GetBytes encoding)
|
||||
| Some (body, ContentTransfer.ContentLength) ->
|
||||
builder.AddRange (Encoding.ASCII.GetBytes "Content-Length: ")
|
||||
builder.AddRange (Encoding.ASCII.GetBytes (body.Length.ToString ()))
|
||||
|
||||
builder.Add (byte '\r')
|
||||
builder.Add (byte '\n')
|
||||
|
||||
match this.Body with
|
||||
| None -> ()
|
||||
| Some (_body, ContentTransfer.TransferEncoding _) -> failwith "not implemented"
|
||||
| Some (body, ContentTransfer.ContentLength) -> builder.AddRange body
|
||||
|
||||
builder.ToArray ()
|
||||
|
@@ -8,6 +8,9 @@ open System.Text
|
||||
module Program =
|
||||
[<EntryPoint>]
|
||||
let main argv =
|
||||
let parentSw = Stopwatch.StartNew ()
|
||||
parentSw.Restart ()
|
||||
|
||||
let sw = Stopwatch.StartNew ()
|
||||
|
||||
let ip =
|
||||
@@ -38,7 +41,7 @@ module Program =
|
||||
Value = "close"
|
||||
}
|
||||
]
|
||||
Body = Array.Empty<_> ()
|
||||
Body = None
|
||||
}
|
||||
|> fun r -> r.ToBytes ()
|
||||
|
||||
@@ -73,6 +76,10 @@ module Program =
|
||||
|
||||
result.ToArray ()
|
||||
|
||||
Console.WriteLine (System.Text.Encoding.ASCII.GetString response)
|
||||
parentSw.Stop ()
|
||||
|
||||
Console.WriteLine (Encoding.ASCII.GetString response)
|
||||
|
||||
Printfn.time "Total time:" parentSw.ElapsedMilliseconds
|
||||
|
||||
0
|
||||
|
@@ -82,15 +82,17 @@ module Sock =
|
||||
match isDone with
|
||||
| ConnectionState.Interrupted ->
|
||||
// It's OK to get "already connected", we were previously interrupted and we can't tell
|
||||
// how far the connection had got before we retried
|
||||
// how far the connection had got before we retried.
|
||||
// I *have* seen this succeed but then a later write get ENOTCONN, and I don't know why.
|
||||
if err = Errno.EISCONN then
|
||||
Console.WriteLine "Ignoring EISCONN after EINTR"
|
||||
isDone <- ConnectionState.Done
|
||||
else
|
||||
failwithf "failed to connect: %O" err
|
||||
| _ ->
|
||||
|
||||
if err = Errno.EINTR then
|
||||
printfn "Retrying due to EINTR"
|
||||
Console.WriteLine "Retrying connect due to EINTR"
|
||||
isDone <- ConnectionState.Interrupted
|
||||
else
|
||||
failwithf "failed to connect: %O" err
|
||||
|
Reference in New Issue
Block a user