7 ms·
Facil.io: A micro-framework for C web applications
- scegit 8y agoPretty cool! but it doesn't support HTTP2 which is a bit disappointing
- lukeqsee 8y agoVery few folks don’t run some reverse proxy in front of their application servers (or a whole string of them to load balance), so lack of http/2 on an application server is rarely a dealbreaker for a web framework. I’ll take a solid framework with only h/1.1 over an iffy one with h/2 any day of the week.
- loeg 8y agoThe FreeBSD project has been dealing with HTTP2 interoperability hell over the last month. (Curl 7.62 may or may not talk to Phabricator if HTTP2 is enabled; it seems to depend on some local conditions and the phase of the moon whether it works or not. HTTP1.1 just works.) Given that experience with HTTP2, I'm quite happy to stick to HTTP1.1 for now.
- scegit 8y agoHTTP1.1 is expected to just work it has been here for a very long time. It takes time to understand, support and adopt new technology. I'm not sure if the blame should be on HTTP2 in this case.
- loeg 8y agoRegardless of who the blame should land on — I don't have a strongly held opinion about that — the point remains that HTTP1.1 is a super old, well understood, relatively simple protocol that everyone has done correctly for years. In comparison, HTTP2 is the new, more complex thing and it's understandable there are growing pains and incompatibilities. I just don't want to debug those issues in something that worked great for me on HTTP1.1.
- polotics 8y agoThe example has functions' string parameters and separate parameters for the string's length. Is this really necessary what happens if the declared length is more than the actual length?
- tom_mellior 8y agoKnowing nothing about this, I would guess that this is to allow sending binary data that contains embedded null bytes? Though I guess it would be good to have nicer wrappers for the common case where you do only send text.
- loeg 8y agoProbably they use length-prefixed strings internally (which is probably a requirement for taking a C web framework seriously), but allow C nul-terminated strings at the API boundary for convenience of use.
- pantalaimon 8y agoNo it is not necessary. If no length is given, the string is assumed to be NULL-terminated. It's a bit unfortunate that they use two code paths for that which are basically just copy & paste. https://github.com/boazsegev/facil.io/blob/master/lib/facil/http/http.c#L193 https://github.com/boazsegev/facil.io/blob/master/lib/facil/...
- bowild 8y agoThis approach moves an `if` statement out of the loop, so there's no need to repeat it.
- bowild 8y agoActually, it's to allow for non-NUL terminated strings. A good example is when using a String supplied by a scripting language such as Ruby or JavaScript. Normally, you might need to copy the string to add a NUL byte, or request that the scripting engine provide a NUL terminated string (which might result in the same action performed). Using this optional approach, a potential copy of the data can be avoided.
- tom_mellior 8y agoI like the use of keyword argument syntax to specify optional arguments. I haven't seen anything like this before in C or C++, and now I would wish for it to become standard. It's simulated cleverly using a macro that wraps variable arguments in a struct literal: See the definition of http_set_cookie in https://github.com/boazsegev/facil.io/blob/master/lib/facil/http/http.h https://github.com/boazsegev/facil.io/blob/master/lib/facil/...
- saagarjha 8y ago> I haven't seen anything like this before in C or C++, and now I would wish for it to become standard. I've seen people try to simulate this in C++ with tags.
- mafm 8y agoI think this trick comes from Ben Klemens' "21st Century C". If you like this, the book has some other tricks in it you might also like. (One example: you can define generic functions in C11).
- jolmg 8y agoThat's really cool, but don't unassigned fields have undefined values? How would the function know what was set? I imagine that in practice they're almost always 0, but that's not guaranteed, right? You'd need to set the struct as {0}, to have everything be 0. Is this a feature of a new(ish) standard?
- hawski 8y agoIt is guaranteed per C99. It's a compound initializer. Also if you set a struct with {1} the first field is set to 1 and the rest to 0. AFAIR it was always like that (at least since standardized C, but probably earlier).
- loeg 8y agoC99 specifies that struct literals with absent fields are assigned a zero value. (Notably unspecified is the value of any implicit padding bytes in the struct.)
- beefhash 8y agoIf you want to do web applications in C, you may also be interested in the kcgi[1] and ksql[2]. kcgi takes a more traditional approach by using CGI rather than embedding a static file server in the final binary. [1] https://kristaps.bsd.lv/kcgi/ https://kristaps.bsd.lv/kcgi/ [2] https://kristaps.bsd.lv/ksql/ https://kristaps.bsd.lv/ksql/
- jondubois 8y agoCGI adds simplicity and interoperability but takes away control and performance. FastCGI suffers from the same fundamental issue as well but to a lesser extent.
- EdSchouten 8y agoThere is also Ulfius: https://github.com/babelouest/ulfius/ https://github.com/babelouest/ulfius/
- pvtmert 8y agoonly thing i did not understand is port being string/char* other than that, clever api
- loeg 8y agoProbably for getaddrinfo(): http://beej.us/guide/bgnet/html/single/bgnet.html#getaddrinfo http://beej.us/guide/bgnet/html/single/bgnet.html#getaddrinf...
- badrabbit 8y agoHonset curiosity: is there a reason Golang or rust couldn't perform same or better? I get why as a programmer I would use C, but what benefit does it have for the users of the app?
- jolmg 8y agoThe users of the framework, the programmers of a webapp? I imagine that there's few frameworks for web development in C, so having options is good. It's also probably way more portable than Golang or rust. That's also useful for the users of the webapp if they want to host it. I mean, it probably takes less effort to get it to compile and run on a system like SCO, compared to doing that with Golang or rust. You'd think legacy systems don't matter, but I imagine that there's still many businesses that heavily depend on such legacy systems because the costs to safely migrate are big. Making it in C is probably also going to result in far smaller compiled code, since I imagine C requires a far smaller RTS than Golang or rust. That might make a difference for people that for some reason want to run a webapp on a small device. I may be wrong though, since I don't have any experience with Golang or rust.
- badrabbit 8y agoI meant the users of the webapp.
- loeg 8y agoSure. Go is a garbage-collected language with an immature and unsophisticated compiler toolchain, compared to the big free C compilers like GCC or Clang. The compiler limitations are solvable but GC is a core part of the language. Interoperability with C libraries is possible but not great. Rust is built on LLVM, much like Clang. C integration is relatively easy. I think this is more viable than Go. Unfortunately, Rust is only portable to platforms LLVM supports. While that covers the majority of commonly used hardware today, it is not comprehensive. Also, Rust compile times are pretty bad, especially for optimized builds. At the end of the day the author gets to write code in a language of their choice to scratch their own itch. End users don't care at all what language a web framework is written in.
- denniskane 8y agoI experienced a kind of dyslexia when reading this headline. I couldn't fathom what a C framework could have to do with a "web application" outside of the world of web assembly, so I wondered why the phrases "web assembly" or "wasm" were nowhere to be found. FWIW, I spend almost all of my working hours immersed in the logic of the client side!
- deleted 8y ago[deleted]
- IloveHN84 8y agoWhere's TLS? And http/2?
- doctorpangloss 8y agoPeople who serve SSL out of their Java servlets by installing certificates to random Tomcat and Linux system directories are already a little crazy. You'd have to be a real maniac to serve TLS in someone's random C framework.