<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I think a very good reference for the conversation regarding concurrency is libdill:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/sustrik/libdill" class="">https://github.com/sustrik/libdill</a></div><div class=""><br class=""></div><div class="">And dsock:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/sustrik/dsock" class="">https://github.com/sustrik/dsock</a></div><div class=""><br class=""></div><div class="">dosck has a work-in-progress RFC:</div><div class=""><br class=""></div><div class=""><a href="https://github.com/sustrik/dsock/blob/master/rfc/sock-api-revamp-01.txt" class="">https://github.com/sustrik/dsock/blob/master/rfc/sock-api-revamp-01.txt</a></div><div class=""><br class=""></div><div class="">Libdill's biggest concept is structured concurrency:</div><div class=""><br class=""></div><div class=""><a href="http://libdill.org/structured-concurrency.html" class="">http://libdill.org/structured-concurrency.html</a></div><div class=""><br class=""></div><div class="">libdill is an elegant solution for one of the biggest problems of concurrency, cancelation.</div><div class="">It uses coroutines, procs and CSP to deal with communication.</div><div class="">On the other hand dsock solves the problem of protocol composition. The RFC explains</div><div class="">the concept in great detail. I really love the approach and I think we can get a lot of</div><div class="">inspiration from these sources.</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Oct 27, 2016, at 9:27 PM, Michael Chiu via swift-server-dev &lt;<a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class=""><pre style="white-space: pre-wrap;" class="">On 27 Oct 2016, at 15:27:56 CDT 2016, <span style="white-space: normal;" class=""><font face="Menlo" class="">Helge </font></span><font face="Menlo" class=""><span style="white-space: normal;" class="">Heß</span><span style="font-size: inherit; white-space: normal;" class="">&nbsp;&lt;</span><span class="">me at <a href="http://helgehess.eu/" class="">helgehess.eu</a></span></font><span class="">&gt; wrote:</span></pre></pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">&gt; I can see (and essentially agree) with your point, but then I’m also back at wondering why there is a need for a common socket API at _such_ a low level. </pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">I think one of the reason why common socket api is necessary since socket is not standardized across platforms (WINSOCK, BSD Socket, Linux Socket…) at all.&nbsp;</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">Another reason is probably because of the sockaddr struct family. They have different sizes, different alignment(on different os), often need to cast the pointer around, and incredibly hard to use in pure swift manner. </pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">Nevertheless I think swift is a great language for both high and low level programming, if we have some swift-like yet low level api we essentially open up the opportunities for other developers.<br class=""> </pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">&gt; A framework choosing a custom event loop certainly can work just fine today with the Posix functions available?</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">I’m not quite sure what you mean here.</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">&gt; I don’t understand what you are saying here :-) Are you just describing an abstract Socket base class which has a ‘RawSocket’ subclass in which read/write is directly invoking Posix.read/write and a ‘SSLSocket’ subclass which has another implementation of that dealing with the encryption?
&gt; Or do you really want to subclass a socket in say a PostgreSQLSocket and then override a function like `handleData(…)`. That would sound wrong to me. A PGConnection should interact using a socket object, but not inherit from one.</pre><div class=""><br class=""></div><div class=""><font face="Menlo" class="">Sorry for my bad explanation, override is definitely not a good word choice. What I mean is&nbsp;</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; protocol Readable {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; func read() -&gt; Data?// how do we read</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;protocol Writable {</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; func write(data: Data) // how do we write (send, sendfile, …)&nbsp;</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;}&nbsp;</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp;protocol Socket: Readable, Writable {}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">so we can easily make something like:</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class=""><br class=""></pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">class TLSSocket: Socket {</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">    func read() -&gt; Data? {</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">    … ssl_read….</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">    }</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">  &nbsp; func write(data: Data) {</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">    … ssl_write….</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">    }    </pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">}</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class=""><br class=""></pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">such that we can easily implement low level optimization and extent to different socket interfaces.</pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class=""><br class=""></pre><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class=""><br class=""></pre></div></div>_______________________________________________<br class="">swift-server-dev mailing list<br class=""><a href="mailto:swift-server-dev@swift.org" class="">swift-server-dev@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-server-dev<br class=""></div></blockquote></div><br class=""></body></html>