[swift-server-dev] Prototype of the discussed HTTP API Spec

Carl Brown carl.brown.swift at linuxswift.com
Tue May 30 13:24:02 CDT 2017


> On May 30, 2017, at 12:02 PM, Johannes Weiss via swift-server-dev <swift-server-dev at swift.org> wrote:
> if you use kqueue/(e)poll/select you get inversion of control, ie. you block only one (or a few) threads in kqueue/epoll/select and then invoke code to handle the event (which can be 'file descriptor XYZ can be read/written').
> 
> So the echo server becomes more like this (this is extreme pseudo code and ignores most of the real challenges)
> 
> func echoServer(socket: Socket) {
>    socket.whenReadable { bytes in
>        socket.whenWritable {
>            socket.write(bytes)
>        }
>    }
> }
> 
> If you want a more realistic example check out DispatchSources and DispatchIO from Dispatch. 

For whatever it's worth, the implementation we posted uses DispatchSources for reading from the Socket (see https://github.com/carlbrown/HTTPSketch/blob/master/Sources/HTTPSketch/BlueSocketDriver/BlueSocketConnectionListener.swift#L166-L169 <https://github.com/carlbrown/HTTPSketch/blob/master/Sources/HTTPSketch/BlueSocketDriver/BlueSocketConnectionListener.swift#L166-L169>), although in my testing using an additional DispatchSource for writing didn't seem to affect the performance at all (but did increase complexity) so I pulled it out.

I'd love to get more eyes on that code, if anyone has the time.

-Carl

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-server-dev/attachments/20170530/0bd30d3d/attachment.html>


More information about the swift-server-dev mailing list