@@ -13,7 +13,7 @@ open Suave
1313/// and that can be closed.
1414type Connection =
1515 { mutable socketBinding : SocketBinding
16- transport : TcpTransport
16+ transport : ITransport
1717 reader : HttpReader
1818 pipe : Pipe
1919 lineBuffer : byte array
@@ -30,7 +30,9 @@ type Connection =
3030 member inline this.flush () =
3131 task {
3232 if this.lineBufferCount> 0 then
33- let! _ = this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount))
33+ match ! this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount)) with
34+ | Ok () -> ()
35+ | Result.Error _ -> ()
3436 // Clear the buffer to prevent information leakage
3537 Array.Clear( this.lineBuffer, 0 , this.lineBufferCount)
3638 this.lineBufferCount <- 0
@@ -45,7 +47,9 @@ type Connection =
4547 if maxByteCount > this.lineBuffer.Length then
4648 // Flush current buffer first
4749 if this.lineBufferCount > 0 then
48- let! _ = this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount))
50+ match ! this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount)) with
51+ | Ok () -> ()
52+ | Result.Error _ -> ()
4953 this.lineBufferCount <- 0
5054
5155 // Use ArrayPool for large strings
@@ -55,14 +59,18 @@ type Connection =
5559 let mutable bytesUsed = 0
5660 let mutable completed = false
5761 this.utf8Encoder.Convert( str.ToCharArray(), 0 , str.Length, tempBuffer, 0 , maxByteCount, true , & charsUsed, & bytesUsed, & completed)
58- let! _ = this.transport.write ( new Memory<_>( tempBuffer, 0 , bytesUsed))
62+ match ! this.transport.write ( new Memory<_>( tempBuffer, 0 , bytesUsed)) with
63+ | Ok () -> ()
64+ | Result.Error _ -> ()
5965 return ()
6066 finally
6167 ArrayPool< byte>. Shared.Return( tempBuffer)
6268
6369 elif this.lineBufferCount + maxByteCount > this.lineBuffer.Length then
6470 // Flush buffer and encode into it
65- let! _ = this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount))
71+ match ! this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount)) with
72+ | Ok () -> ()
73+ | Result.Error _ -> ()
6674 let mutable charsUsed = 0
6775 let mutable bytesUsed = 0
6876 let mutable completed = false
@@ -89,19 +97,23 @@ type Connection =
8997 member inline this.asyncWriteBytes ( b : byte []) =
9098 task {
9199 if b.Length > 0 then
92- let! _ = this.transport.write ( new Memory<_>( b, 0 , b.Length))
93- ()
100+ match ! this.transport.write ( new Memory<_>( b, 0 , b.Length)) with
101+ | Ok () -> ()
102+ | Result.Error _ -> ()
94103 }
95104
96105 member inline this.asyncWriteBufferedBytes ( b : byte []) =
97106 task {
98107 if this.lineBufferCount + b.Length > this.lineBuffer.Length then
99108 // flush lineBuffer
100109 if this.lineBufferCount > 0 then
101- let! _ = this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount))
102- ()
110+ match ! this.transport.write ( new Memory<_>( this.lineBuffer, 0 , this.lineBufferCount)) with
111+ | Ok () -> ()
112+ | Result.Error _ -> ()
103113 // don't waste time buffering here
104- let! _ = this.transport.write ( new Memory<_>( b, 0 , b.Length))
114+ match ! this.transport.write ( new Memory<_>( b, 0 , b.Length)) with
115+ | Ok () -> ()
116+ | Result.Error _ -> ()
105117 this.lineBufferCount <- 0
106118 else
107119 Buffer.BlockCopy( b, 0 , this.lineBuffer, this.lineBufferCount, b.Length)
@@ -143,4 +155,15 @@ module Connection =
143155 cn.transport.read buf
144156
145157 let inline send ( cn : Connection ) ( buf : ByteSegment ) =
146- cn.transport.write buf
158+ task {
159+ match ! cn.transport.write buf with
160+ | Ok () -> return Ok ()
161+ | Result.Error e -> return Result.Error e
162+ }
163+
164+ let inline shutdown ( cn : Connection ) =
165+ task {
166+ match ! cn.transport.shutdown() with
167+ | Ok () -> ()
168+ | Result.Error _ -> ()
169+ }
0 commit comments