Better domain
This commit is contained in:
@@ -33,11 +33,15 @@ type FieldLine =
|
|||||||
// obvious candidate to improve speed by allocating less
|
// obvious candidate to improve speed by allocating less
|
||||||
this.ToString () |> Encoding.ASCII.GetBytes |> request.AddRange
|
this.ToString () |> Encoding.ASCII.GetBytes |> request.AddRange
|
||||||
|
|
||||||
|
type ContentTransfer =
|
||||||
|
| ContentLength
|
||||||
|
| TransferEncoding of string
|
||||||
|
|
||||||
type HttpRequest =
|
type HttpRequest =
|
||||||
{
|
{
|
||||||
Request : RequestLine
|
Request : RequestLine
|
||||||
Headers : FieldLine list
|
Headers : FieldLine list
|
||||||
Body : byte[]
|
Body : (byte[] * ContentTransfer) option
|
||||||
}
|
}
|
||||||
|
|
||||||
member this.ToBytes () : byte[] =
|
member this.ToBytes () : byte[] =
|
||||||
@@ -64,7 +68,21 @@ type HttpRequest =
|
|||||||
builder.Add (byte '\r')
|
builder.Add (byte '\r')
|
||||||
builder.Add (byte '\n')
|
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 '\r')
|
||||||
builder.Add (byte '\n')
|
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 ()
|
builder.ToArray ()
|
||||||
|
@@ -8,6 +8,9 @@ open System.Text
|
|||||||
module Program =
|
module Program =
|
||||||
[<EntryPoint>]
|
[<EntryPoint>]
|
||||||
let main argv =
|
let main argv =
|
||||||
|
let parentSw = Stopwatch.StartNew ()
|
||||||
|
parentSw.Restart ()
|
||||||
|
|
||||||
let sw = Stopwatch.StartNew ()
|
let sw = Stopwatch.StartNew ()
|
||||||
|
|
||||||
let ip =
|
let ip =
|
||||||
@@ -38,7 +41,7 @@ module Program =
|
|||||||
Value = "close"
|
Value = "close"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
Body = Array.Empty<_> ()
|
Body = None
|
||||||
}
|
}
|
||||||
|> fun r -> r.ToBytes ()
|
|> fun r -> r.ToBytes ()
|
||||||
|
|
||||||
@@ -73,6 +76,10 @@ module Program =
|
|||||||
|
|
||||||
result.ToArray ()
|
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
|
0
|
||||||
|
@@ -82,15 +82,17 @@ module Sock =
|
|||||||
match isDone with
|
match isDone with
|
||||||
| ConnectionState.Interrupted ->
|
| ConnectionState.Interrupted ->
|
||||||
// It's OK to get "already connected", we were previously interrupted and we can't tell
|
// 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
|
if err = Errno.EISCONN then
|
||||||
|
Console.WriteLine "Ignoring EISCONN after EINTR"
|
||||||
isDone <- ConnectionState.Done
|
isDone <- ConnectionState.Done
|
||||||
else
|
else
|
||||||
failwithf "failed to connect: %O" err
|
failwithf "failed to connect: %O" err
|
||||||
| _ ->
|
| _ ->
|
||||||
|
|
||||||
if err = Errno.EINTR then
|
if err = Errno.EINTR then
|
||||||
printfn "Retrying due to EINTR"
|
Console.WriteLine "Retrying connect due to EINTR"
|
||||||
isDone <- ConnectionState.Interrupted
|
isDone <- ConnectionState.Interrupted
|
||||||
else
|
else
|
||||||
failwithf "failed to connect: %O" err
|
failwithf "failed to connect: %O" err
|
||||||
|
Reference in New Issue
Block a user