<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C on Roads Less Taken</title><link>https://goran.krampe.se/categories/c/</link><description>Recent content in C on Roads Less Taken</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sat, 25 Oct 2014 00:00:00 +0000</lastBuildDate><atom:link href="https://goran.krampe.se/categories/c/index.xml" rel="self" type="application/rss+xml"/><item><title>Nim Socket Server</title><link>https://goran.krampe.se/2014/10/25/nim-socketserver/</link><pubDate>Sat, 25 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/25/nim-socketserver/</guid><description>&lt;p>In learning &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 I decided to implement a trivial Socket server, very small, as an example. Its &lt;strong>not a useful HTTP server&lt;/strong> (it just returns a hard coded HTTP response so we can benchmark it using HTTP tools), and its &lt;strong>not async&lt;/strong> - there are other such examples in the Nim examples directory and in its stdlib. No, I wanted to write a more classical threaded socket server to see how easy that is - especially with the new APIs in Nim &lt;a href="https://github.com/Araq/Nimrod/tree/bigbreak" target="_blank" rel="noopener noreferrer">&amp;ldquo;bigbreak&amp;rdquo;&lt;/a>
 - and see how it performs.&lt;/p>
&lt;p>The new &amp;ldquo;bigbreak&amp;rdquo; branch that will become Nim 0.10.0 soon-ish has a bunch of new stuff in the networking area. Its replacing the single &lt;code>sockets&lt;/code> module with a low level &lt;code>rawsockets&lt;/code> module, and a higher level &lt;code>net&lt;/code> module. And there is a new &lt;code>selectors&lt;/code> module that abstracts over different modern IO polling mechanisms. This means that a single API will use &lt;strong>epoll on Linux, kqueue on BSD/OSX, old select on the other Unices and IO Completion ports on Windows&lt;/strong>. At the moment epoll, select on &amp;ldquo;other Unices&amp;rdquo; and IO Completion ports works. kqueue is on the todo.&lt;/p>
&lt;p>So without further ado&amp;hellip;&lt;/p></description></item><item><title>Nim wrapping C</title><link>https://goran.krampe.se/2014/10/16/nim-wrapping-c/</link><pubDate>Thu, 16 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/16/nim-wrapping-c/</guid><description>&lt;p>Nim has all the language mechanisms needed to smoothly interoperate with C and C++. The rather &lt;a href="https://github.com/Araq/Nimrod/tree/devel/lib/wrappers" target="_blank" rel="noopener noreferrer">large collection of wrapped C libraries&lt;/a>
 (and that&amp;rsquo;s only those in the standard libs) is also a testament to this fact. In this article I explain my personal findings testing out the waters of wrapping a simple C library.&lt;/p>
&lt;p>The basic approach to wrapping a simple C library is:&lt;/p>
&lt;ol start="0">
&lt;li>Install Nim.&lt;/li>
&lt;li>Install c2nim using Babel or manually clone c2nim from github and build it.&lt;/li>
&lt;li>Use c2nim to translate the C header file(s) to a so called Nim wrapper.&lt;/li>
&lt;li>Make a small test showing it works.&lt;/li>
&lt;li>Write a so called &lt;em>&amp;ldquo;impure&amp;rdquo;&lt;/em> intermediary library that uses the wrapper (next article)&lt;/li>
&lt;li>Make a test green and declare Victory (next article)&lt;/li>
&lt;/ol>
&lt;p>Okidoki&amp;hellip; (roll up sleeves)&lt;/p></description></item></channel></rss>