home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,281 of 33,346   
   Jorgen Grahn to alapaa   
   Re: Thin, fast C++11 wrapper for BSD soc   
   16 Feb 14 22:11:21   
   
   From: grahn+nntp@snipabacken.se   
      
   On Tue, 2014-02-11, alapaa wrote:   
   >   
   > Hi,   
   >   
   > I am looking for a good, thin, modern (preferably C++11) C++ wrapper   
   > over socket calls and other Unix-style sys/library calls (strerror   
   > (thread-safe variants), read(), you name it). The wrapper would   
   > ideally use templates where necessary and be very thin, non-obscure   
   > and small so you get all the power of the C API without the hassles   
   > of e.g C char buffer handling for e.g strerror. Also, it must be fast   
   > and lightweight enough for use in embedded systems and many real-time   
   > systems.   
   >   
   > The wrapper must be open source, e.g. something like BSD license. LGPL   
   > also works.   
   >   
   > Basically, a library you could show C guys and say: Look, here you get   
   > the speed, abstraction and power of C++, and it is extremely easy to   
   > grok if you know C++ and normal Unix systems/network programming C API   
   > calls.   
   >   
   > My main target is "portable Unix" (maybe Posix plus more) with (GNU)   
   > Linux first in line, so  the library should preferably be usable on   
   > *BSD (possibly including Mac), Solaris and Linux.   
   >   
   > /Erik Alapää   
      
   I used to plan to write such a thin library (going through Stevens'   
   network programming books page by page and implementing C++ wrappers   
   for what he taught) but I gave up for several reasons:   
      
   - The better Unix socket APIs are quite usable from C++.  E.g.   
     getaddrinfo(3) and epoll(7) (yes, I know the latter is   
     Linux-specific, but it's so much more convenient than select(2)).   
      
     The things that look ugly when you look at the BSD socket API (e.g.   
     the weak typing, the functions which work on a connected UDP socket   
     but not on an unbound TCP socket, etc ...) don't seem very   
     problematic in practice.   
      
   - And the hard parts (e.g. creating a TCP server with nonblocking I/O)   
     are nothing a simple library can fix for you anyway.   
      
   - The things which could use some C++ elegance are IME mostly   
     application-specific.  The most generally useful thing I have is a   
     class which buffers line-oriented TCP protocols: perform one read(),   
     and zero or more lines of text pop out at the other end.   
      
   - People who want something radical have things like Boost.Asio   
     already (and I assume that's not what you're after).   
      
   - People who don't, don't want to learn a new interface anyway. They   
     want their books and man pages to be relevant, without having to   
     mentally translate between the socket API and this new one.   
      
   So that's why I never wrote such a library, or searched very hard for   
   one.  It's possible that one exists, of course ...   
      
   If I wanted to impress C people I'd do it by showing them how it makes   
   their own designs better, not how it hides the APIs they are used to   
   using.  (I would also show them getaddrinfo(3) and epoll(7), because   
   it seems a lot of them write networking code based on examples from   
   the 1980s ...)   
      
   /Jorgen   
      
   --   
     // Jorgen Grahn    O  o   .   
      
      
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca