N4626 – Working Draft, C++ Extensions for Networking (2017)

N4626Working Draft, C++ Extensions for Networking, a.k.a. Networking Technical Specification, Networking TS, Jonathan Wakely, 2017-03-17.

Background

  • at cppreference.com
  • Section 4.2 <quote>The design of this specification is based, in part, on the Asio library written by Christopher Kohlhoff.</quote>
  • N4480C++ Extensions for Library Fundamentals, Version 2, 2015-11-25.

Composition

Physical

Everything
#include <experimental/net>

Buys everything.

In Phases && Slices
#include <experimental/netfwd>
#include <experimental/buffer>
#include <experimental/executor>
#include <experimental/internet>
#include <experimental/io_context>
#include <experimental/socket>
#include <experimental/timer>

Incorporates subcomponentry in stages.

Namespaces

std::net
Finally, once standardized, someday; after the year “202a.”
std::experimental::net
(inlined) std::experimental::net::v1
Currently, under draft, during trials, maybe now; prior to the year “202a.”
std::net::ip
a.k.a. std::experimental::net::v1::ip.
The Internet Protocol Subsystem

Components

As elaborated in <net>, a.k.a. <experimental/net>.
Using the "post-standardized" naming conventions:

std::net::associated_allocator
std::net::associated_executor
std::net::async_completion
std::net::async_result
std::net::bad_executor
std::net::basic_datagram_socket
std::net::basic_socket
std::net::basic_socket_acceptor
std::net::basic_socket_iostream
std::net::basic_socket_streambuf
std::net::basic_stream_socket
std::net::basic_waitable_timer
std::net::bind_executor
std::net::buffer_copy
std::net::buffer_size
std::net::const_buffer
std::net::defer
std::net::dispatch
std::net::dynamic_string_buffer
std::net::dynamic_vector_buffer
std::net::execution_context
std::net::execution_context;
std::net::execution_context::service
std::net::executor
std::net::executor_binder
std::net::executor_work_guard
std::net::get_associated_allocator
std::net::get_associated_executor
std::net::high_resolution_timer
std::net::io_context
std::net::io_context::executor_type
std::net::ip::address
std::net::ip::address_v4
std::net::ip::address_v4_iterator
std::net::ip::address_v4_range
std::net::ip::address_v6
std::net::ip::address_v6_iterator
std::net::ip::address_v6_range
std::net::ip::bad_address_cast
std::net::ip::basic_address_iterator
std::net::ip::basic_address_range
std::net::ip::basic_endpoint
std::net::ip::basic_resolver
std::net::ip::basic_resolver_entry
std::net::ip::basic_resolver_results
std::net::ip::network_v4
std::net::ip::network_v6
std::net::ip::resolver_base
std::net::ip::tcp
std::net::ip::udp
std::net::is_executor
std::net::make_work_guard
std::net::mutable_buffer
std::net::packaged_task
std::net::post
std::net::socket_base
std::net::steady_timer
std::net::strand
std::net::system_context
std::net::system_executor
std::net::system_timer
std::net::transfer_all
std::net::transfer_at_least
std::net::transfer_exactly
std::net::use_future_t
std::net::uses_executor
std::net::wait_traits

Referenced

Contents

  • Contents (this list)
  • List of Tables
  1. Scope
  2. Normative references
  3. Terms and definitions
  4. General Principles
    1. Conformance
    2. Acknowledgments
  5. Namespaces and headers
  6. Future plans (Informative)
  7. Feature test macros (Informative)
  8. Method of description (Informative)
    1. Structure of each clause
    2. Other conventions
  9. Error reporting
    1. Synchronous operations
    2. Asynchronous operations
    3. Error conditions
    4. Suppression of signals
  10. Library summary
  11. Convenience header
    • Header <experimental/net> synopsis
  12. Forward declarations
    • Header <experimental/netfwd> synopsis
  13. Asynchronous model
    • Header <experimental/executor> synopsis
    • Requirements
    • Class template async_result
    • Class template async_completion
    • Class template associated_allocator
    • Function get_associated_allocator
    • Class execution_context
    • Class execution_context::service
    • Class template is_executor
    • Executor argument tag
    • uses_executor
    • Class template associated_executor
    • Function get_associated_executor
    • Class template executor_binder
    • Function bind_executor
    • Class template executor_work_guard
    • Function make_work_guard
    • Class system_executor
    • Class system_context
    • Class bad_executor
    • Class executor
    • Function dispatch
    • Function post
    • Function defer
    • Class template strand
    • Class template use_future_t
    • Partial specialization of async_result for packaged_task
  14. I/O services
    • Header <experimental/io_context> synopsis
    • Class io_context
    • Class io_context::executor_type
  15. Timers
    • Header <experimental/timer> synopsis
    • Requirements
    • Class template wait_traits
    • Class template basic_waitable_timer
  16. Buffers
    • Header <experimental/buffer> synopsis
    • Requirements
    • Error codes
    • Class mutable_buffer
    • Class const_buffer
    • Buffer type traits
    • Buffer sequence access
    • Function buffer_size
    • Function buffer_copy
    • Buffer arithmetic
    • Buffer creation functions
    • Class template dynamic_vector_buffer
    • Class template dynamic_string_buffer
    • Dynamic buffer creation functions
  17. Buffer-oriented streams
    • Requirements
    • Class transfer_all
    • Class transfer_at_least
    • Class transfer_exactly
    • Synchronous read operations
    • Asynchronous read operations
    • Synchronous write operations
    • Asynchronous write operations
    • Synchronous delimited read operations
    • Asynchronous delimited read operations
  18. Sockets
    • Header <experimental/socket> synopsis
    • Requirements
    • Error codes
    • Class socket_base
    • Socket options
    • Class template basic_socket
    • Class template basic_datagram_socket
    • Class template basic_stream_socket
    • Class template basic_socket_acceptor
  19. Socket iostreams
    • Class template basic_socket_streambuf
    • Class template basic_socket_iostream
  20. Socket algorithms
    • Synchronous connect operations
    • Asynchronous connect operations
  21. Internet protocol
    • Header <experimental/internet> synopsis
    • Requirements
    • Error codes
    • Class ip::address
    • Class ip::address_v4
    • Class ip::address_v6
    • Class ip::bad_address_cast
    • Hash support
    • Class template ip::basic_address_iterator specializations
    • Class template ip::basic_address_range specializations
    • Class template ip::network_v4
    • Class template ip::network_v6
    • Class template ip::basic_endpoint
    • Class template ip::basic_resolver_entry
    • Class template ip::basic_resolver_results
    • Class ip::resolver_base
    • Class template ip::basic_resolver
    • Host name functions
    • Class ip::tcp
    • Class ip::udp
    • Internet socket options
  • Index
  • Index of library names
  • Index of implementation-defined behavior

Previously filled.

C++17 in details: Parallel Algorithms | Bartłomiej Filipek

Bartłomiej Filipek <noreply@blogger.com>; C++17 in details: Parallel Algorithms; In His Blog; 2017-08-17.

Contents

Mentioned

  • C++11
  • C++14
  • C++17
  • “map reduce” is “transform reduce” in C++17.
  • execution policy.

Scheme

std::algorithm_name(policy, arguments...);

Components

#include <execution>
namespace std::execution
std::execution::ExecutionPolicy

Configuration
Sequential
The algorithm may not be parallelized.

  • (type) std::execution::sequenced_policy
  • (constant) std::execution::seq
Parallel
The algorithm may be parallelized; each individual ith can be scheduled concurrently, but within a stripe, serialization occurs.

  • (type) std::execution::parallel_policy
  • (constant) std::execution::par
Unsequenced (Vectorizable)
The algorithm can be vectorized; the workload as a whole is to be considered.

  • (type) std::execution::parallel_unsequenced_policy
  • (constant) std::execution::par_unseq

Catalog

Via Experimental Parallel Algorithms, at cppreference.com.

Generally…

  • adjacent difference
  • adjacent find.
  • all_of
  • any_of
  • none_of
  • copy
  • count
  • equal
  • fill
  • find
  • generate
  • includes
  • inner product
  • in place merge
  • merge
  • is heap
  • is partitioned
  • is sorted
  • lexicographical_compare
  • min element
  • minmax element
  • mismatch
  • move
  • n-th element
  • partial sort
  • sort copy
  • partition
  • remove & variations
  • replace & variations
  • reverse
  • rotate
  • search
  • set difference
  • intersection
  • union
  • symmetric difference
  • sort
  • stable partition
  • swap ranges
  • transform
  • unique
More New…
  • for_each
  • for_each_n
  • reduce
  • exclusive_scan
  • inclusive_scan
  • std::partial_sum
The Map/Reduce Idom
  • transform_reduce – applies a functor, then reduces out of order
  • transform_exclusive_scan – applies a functor, then calculates exclusive scan
  • transform_inclusive_scan – applies a functor, then calculates inclusive scan

Filler

  • GPU
  • Vectorization (SIMD)
  • Packages
    • CUDA
    • OpenCL
    • OpenGL
    • SYCL
    • Intel TBB
    • “other” vectorized libraries
  • Amdahl’s law; In Jimi Wales’ Wiki

Referenced

There are many resources referenced

Papers

isocpp.org
  • N4659Draft, Standard for Programming Language C++, 2017-03-21.
  • P0024R2Parallelism
    a.k.a. “the original paper for the spec”
  • P0636r0Changes between C++14 and C++17 DIS
  • N3554PDF: A Parallel Algorithms Library, 2013.
    a.k.a. “the initial Parallelism TS”

Popularization

In Modern C++ (Magazine)‖

Books

  • Jacek Galowicz; C++17 STL Cookbook; amzn.to
  • Marius Bancila; Modern C++ Programming Cookbook; amzn.to

YouTube

  • Bryce Adelstein; A Talk; On YouTube; WHEN?
    tl;dr → something about the distinction between std::execution::par, and std::execution::par_unseq.
  • Bryce Lelbach: C++Now 2017: C++17 Features; On YouTube; 2017.
  • Sean Parent; A Talk; At code::dive (Conference), hosted on YouTube; 2016; same material(?) was the subject of a keynote address at CppNow 2012 <rly?>
  • Jason Turner: C++ Weekly channel; On YouTube.
    tl;dr → covers C++17 features in a linear read-the-news-at-you-over-visual-media type format.

Implementations

Previously

In His Blog

Series

  1. Fixes and deprecation
  2. Language clarification
  3. Templates
  4. Attributes
  5. Simplification
  6. Library changes – Filesystem
  7. Library changes – Parallel STL
  8. Library changes – Utils
  9. Wrap up, Bonus

Previously filled.

Trip report: Summer ISO C++ standards meeting (Toronto) | Sutter’s Mill

Herb Sutter; Trip report: Summer ISO C++ standards meeting (Toronto); In His Blog entitled Sutter’s Mill; 2017-07-15.

Mentions

  • Concepts TS
    • “introducer syntax”
    • “terse/natural syntax”
  • Draft C++20
  • C++17
  • Modules TS
  • Coroutines TS
  • Networking TS
  • atomic_shared_ptr<T>
  • Latches
  • Barriers
  • Reflection
  • Library Evolution [Working Group]
  • SG1
  • CppCon

Something About…

  • several new containers
  • compile-time programming
  • metaclass programming

and…

  • modules
  • contracts

Definitions

“IS”
The “international standard” is core [of the] C++ standard.
a.k.a. “trunk.”
“TS”
The “technical specification” is a document separate from the main standard. Experimental features can start here before being put into the IS.
a.k.a. “beta branches.”
Current Status
See the actualities, below.

Who

  • Bjarne Stroustrup
  • Gabriel Dos Reis
  • Andrew Sutton

Referenced

Proposals
  • P0194compile-time reflection
  • P0244Unicode support
  • P0355date library
  • P0329Add designated initializers.
    e.g. struct A { int x; int y; int z; }; A b{.x = 1, .z = 2};
  • P0409Allow lambda capture [=, this].
  • P0428Allow template parameter lists on lambdas.
    e.g. auto f = []<typename T>(std::vector<T> vector) { /*…*/ };
Issues
  • BUG 311remove deprecated features

Previously

In His Blog

Actualities

Previously filled

Roundup of miscellaneous notes, captured and organized

Blockchain Culture

The Seven(Hundred) Dwarves

  • Blockstack(.org)- The New Decentralized Internet
    • blockstack, at GitHub
    • Union Square Ventures (USV)
    • Promotion
      • Staff (USV); The Blockchain App Stack; In Their Blog; 2016-08-08.
      • Blockstack Unveils A Browser For The Decentralized Web; Laura Shin; In Forbes; 2017-05-15.
        tl;dr → <quote>Tuesday, at the main blockchain industry conference, Consensus, one of the companies working on this new decentralized web, Blockstack, which has $5.5 million in funding from Union Square Ventures and AngelList cofounder Naval Ravikant, released a browser add-on that enables that and more.<snip/>The add-on enables a browser to store the user’s identity information by a local key on the consumer’s device.</quote>; Ryan Shea, cofounder.
  • Everyone has something here.

Bluetooth Culture

Bluetooth LE (BLE)

  • and?

Bluetooth 5

  • Something about mesh networking
  • Something about the standard being released “summer 2017.”

C++ Culture

C++20

  • The roadmap onto the twenties.

Application

  • MapReduce, from ETL or EU somewhere.
  • Kyoto Cabinet, Typhoon, Tycoon
  • Virtual Reality packages
  • Ctemplate, Olafud Spek (?)
  • Robot Operating System (ROS)
  • libgraphqlparser – A GraphQL query parser in C++ with C and C++ APIs

Computing Culture

Ubicomp, <ahem>Pervicomp</ahem>

  • Rich Gold
  • Mark Weiser

Dev(Ops) Culture

Futures Cult(ure)

Advocacy

  • Cory Doctorow, the coming war against general purpose computing, an article; WHERE?
  • Cory Doctorow, dystopia contra utopia, an article; WHERE?

Fiction

  • Cory Doctorow, various works

Imagine a World In Which…

  • Stocks vs Flows
  • Chaos vs Stability
  • Permission vs Permissionless
  • Civil Society ↔ Crony Society
    • Transparency
    • Deals
    • Priorities
  • Predictive Technology “just works”
    • is trusted
    • is eventual
    • is law
    • “is” equates with “ought”

Fedora Culture

  • Flatpak

Fedora 26 Notes

  • nmcli reload con down $i
  • nm cli reload con up $i
  • eui64 must be manually configured

Internet of (unpatchable) Thingies (IoT)

  • MQTT
  • mosquito

Language Lifestyles

Go Lang

  • Go for it.
  • A package manager

LangSec

  • theory
  • implementation?

Rust Lang

  • Was there a NoStarch book?

SCOLD Lang

  • C++20?
    hey, surely someone has modules working by now, eh?

Projects

Generally

  • Repig, in C++, with threads, in an NVMe

mod_profile

  • sure, what?

mod_proliphix

  • Interface to the (discontinued) Proliphix thermostats

mod_resting

  • CDN Store
  • Picture Store
  • Document Cache (store & forward)

mod_files

  • Firefox Tiles

SCOLD Experiences

SCOLD near-syntax, common errors

  • #import <hpp>
  • missing #divert
  • #using, a declaration
  • #origin
  • #namespace
  • $@

Suggestions

Build System
  • –with-std-scold or maybe –with-scold
module-c-string
  • vecdup, like strdup
  • vectree, like strfree→free
module-json
  • json::check::Failure or json::Cast.
  • namespace json::is
    • is_array
    • is_null
    • is_object
  • json::as<…>(…)
module-path
  • pathify(…)
module-sqlite
  • column result
  • concept guarding the template parameter, from C++17
module-string
  • typed strings
    • location
    • path
    • etc.
  • and

Surveillance Culture

Concepts

  • Eigenpeople
  • Eigenpersonas
  • Personality modeling

Literature

Yves-Alexandre de Montjoye, Jordi Quoidbach, Florent Robic, Alex (Sandy) Pentland; Predicting Personality Using Novel Mobile Phone-Based Metrics; In: A.M. Greenberg, W.G. Kennedy, N.D. Bos (editors) Social Computing, Behavioral-Cultural Modeling and Prediction as Proceedings of Social Computing, Behavioral (SBP 2013), Lecture Notes in Computer Science, vol 7812; 2013; paywalls: Springer, ACM. Previously filled.

Theory

  • POSS (Post Open Source Software)
    defined as: if everything is on GitHub, then who needs licenses?
    Was this ever amplified?
    Certainly it is facially incorrect and facile.

Psychology

  • Rob Horning; Sock of Myself, an essay; In Real Life Magazine; 2017-05-17
    tl;dr → riffing on happiness, Facebook. Is. Bad. Q.E.D. R.D. Laing , The Divided Self,; John Cheney-Lippold’s We Are Data; Donald Mackenzie.
  • Michael Nelson; University of California, Riverside.

Purposive directionality

  • increase
    • predictability
  • reduce
    • uncertainty
    • variability

Various

Uncomprehensible, Unknown, Unpossible

  • Sunlight, a package? FOSS?

Roundup of unnoted & unfilled items for C++ & SCOLD

Within “Major” C++ Components

  • Kyoto Cabinet
  • Kyoto Tycoon
  • lstio (of Google)
  • ros (Robot Operating System)
  • GraphQL, for C++
  • and

Within Demonstration Projects

  • Wall of Sheep
  • iptables emulator (simulator, exhibition)
  • Reboot the Sun Microsystems Network Architecture
    but with json, avro, etc.

    • portmapper
    • xdr
    • the yp thingy?
      feels like LDAP
  • Conversational Request-Response Daemon
    • NNTP
    • SMTP
  • Pig in C++
    • with threading
      • std::future
      • std::promise
    • with UDFs
  • and

Within C++ SCOLD

  • for module-sqlite
    • connect & open
      • sqlite::open::Result
      • the exception contains the filename
    • errors use the std::error_code std::error_category system
      • status::Code
      • std::error:code
    • insert_last_rowid
    • step(…) as an ADL function
    • row(…) and done(…) are not errors
      they are legitimate flavors of success.
    • function as<…>(…)
    • use concepts to guard the return types
      • as<std::string>(…)
      • as<std::string_view>(…)
      • as<c::stringz>(…) and consty
      • as<c::stringn>(…) and consty
  • ideas for top-level namespaces
    • rest
    • more
    • want
    • have
  • exception taxonomization
    • std::length_error
      • for resizing
      • for sizing
      • because it really is a “programmer’s error”
      • because it isn’t a resource exhaustion error (that is something else)
    • std::out_of_range
      • for indexing-type access violations
      • not std::invalid_argument
  • something about an object iterator
    • a:b, c:d
  • rename module-file-slurp → module-slurp
  • slurp::Failure
    • descends from std::ios::failure
    • rethrow ios::failure
  • promote 1-arg copy
    • std::copy(…3-arguments…)
    • want::copy(1-argument)
      • is like std::move(…)
      • can be elided, or must not be elided?
  • for module-sys-time, namespace sys::time
    • from when milliseconds were good enough
    • ftime and timeb
      but is labeled as “deprecated” nowadays
  • for module-sys-posix
    • sleep
    • usleep
    • returns the time remaining
  • The variants of the syscalls with timeouts.
    • run the syscall in a separate thread
  • module-ish
  • the grab bag, the collection
  • recollect module-mvr in there
  • and

Within Cloud

  • C++ MapReduce & Pig thingy, out of some EU Uni.
  • Apache Beam
    • Uses a dataflow-like language specification
    • Runtimes (“Runners”)
      • Java
      • Python
    • beam.apache.org
    • nifi.apache.org
Posted in C++

Whither the mysterious rpmbuild warning ‘Could not canonicalize hostname devbox.example.com’?

tl;dr → The host in question is an IPv6-only host; rpm uses IPv4-only APIs.


Context

You are using rpmbuild.

Question

Whither the mysterious Could not canonicalize hostname: devbox.example.com?

Specimen

warning: Could not canonicalize hostname: devbox.example.com

Explanation

The code in question is at least a score years old. It uses the IPv4-only API. It does not take into account IPv6. If you are on an IPv6-only host, then you will get this message.

Exhibition

$ rpmbuild -ba example-package-1.1.0.spec
<snip/>
install -D --mode 444 LICENSE /local/fedora/build/workspace/BUILDROOT/example-package-1.2.0-1.fc19.x86_64/usr/local/share/doc/example-package-1.2.0/LICENSE
make[1]: Leaving directory `/local/fedora/build/workspace/BUILD/example-package-1.2.0'
+ /usr/lib/rpm/find-debuginfo.sh --strict-build-id -m --run-dwz --dwz-low-mem-die-limit 10000000 --dwz-max-die-limit 110000000 /local/fedora/build/workspace/BUILD/example-package-1.2.0
/usr/lib/rpm/sepdebugcrcfix: Updated 0 CRC32s, 0 CRC32s did match.
+ /usr/lib/rpm/check-buildroot
+ /usr/lib/rpm/redhat/brp-compress
+ /usr/lib/rpm/redhat/brp-strip-static-archive /usr/bin/strip
+ /usr/lib/rpm/brp-python-bytecompile /usr/bin/python 1
+ /usr/lib/rpm/redhat/brp-python-hardlink
+ /usr/lib/rpm/redhat/brp-java-repack-jars
Processing files: example-package-1.2.0-1.fc19.noarch
Provides: config(example-package) = 1.2.0-1.fc19 example-package = 1.2.0-1.fc19
Requires(interp): /bin/sh /bin/sh /bin/sh /bin/sh
Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
Requires(pre): /bin/sh
Requires(post): /bin/sh
Requires(preun): /bin/sh
Requires(postun): /bin/sh
Requires: /bin/bash /bin/sh
Checking for unpackaged file(s): /usr/lib/rpm/check-files /local/fedora/build/workspace/BUILDROOT/example-package-1.2.0-1.fc19.x86_64
warning: Could not canonicalize hostname: devbox.example.com
Wrote: /local/fedora/build/workspace/SRPMS/example-package-1.2.0-1.fc19.src.rpm
Wrote: /local/fedora/build/workspace/RPMS/noarch/example-package-1.2.0-1.fc19.noarch.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.Vzsxv5
+ umask 022
+ cd /local/fedora/build/workspace/BUILD
+ cd example-package-1.2.0
+ exit 0

Background

Via: An Email Thread
Date: 2002-04-26
Jeff Johnson ARS N3NPQ
jbj@redhat.com (jbj@jbj.org)
Chapel Hill, NC

<quote>Here’s the code that returns the build host (build/names.c):</quote>

const char *const buildHost(void)
{
  static char hostname[1024];
  static int gotit = 0;
  struct hostent *hbn;

  if (! gotit) {
      (void) gethostname(hostname, sizeof(hostname));
      hbn = gethostbyname(hostname);
      if (hbn)
	  strcpy(hostname, hbn->h_name);
      else
	  rpmMessage(RPMMESS_WARNING,
		      _("Could not canonicalize hostname: %s\n"), hostname);
      gotit = 1;
  }
  return(hostname);
}

Also

The opposite of trenchant, misdirecting, even wrong: Setting up RPM Building for SME Server (undated).
<quote><snip/>If you get “warning: Could not canonicalize hostname:” it can be ignored. This is a DNS resolution error and the easy solution is to add your hostname to /etc/hosts</quote>

Complete

Nowadays we so things: use C++11, type safe, exception safe, thread safe. We can get three of the four easily. Thread safety has to wait for another day.

  auto get_canonical_build_hostname(void) -> std::string {
    static std::string hostname;
    static bool cached(false);
    if (cached) {
      return hostname;
    }
    auto gethostname = sys::gethostname();
    if ( ! std::get<0>(gethostname)) {
      throw std::get<2>(gethostname);
    }
    std::string const &best_hostname_estimate = std::get<3>(gethostname);
    std::array<sys::AF,2> const families{sys::AF::INET6, sys::AF::INET4};
    for (auto family : families) {
      auto gethostbyname2 = sys::gethostbyname2(best_hostname_estimate, family);
      if (std::get<0>(gethostbyname2)) {
	hostname.assign(std::get<3>(gethostbyname2).name);
	return hostname;
      }
    }
    throw std::get<2>(gethostbyname);
  }

Demonstration

g++ -o canonical -ggdb -std=c++11 main.cpp
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstdarg>
#include <cstdint>
#include <cstring>
#include <exception>
#include <functional>
#include <iostream>
#include <string>
#include <system_error>
#include <tuple>
#include <typeinfo>
#include <vector>

#include <unistd.h>
#include <netdb.h>
#include <sys/param.h>
#include <sys/socket.h>

// no language translations
#define _(message) message

namespace rpm {

  std::size_t message_count;

  enum class Message { INFO, WARNING, ERROR };
  constexpr Message const MESS_WARNING = Message::WARNING;

  auto log(Message severity, char const *format, ...) -> void __attribute__ ((format (printf, 2, 3))) {
    message_count++;
    FILE *stream = severity == Message::INFO ? stdout : stderr;
    fputs("warning: ", stream);
    va_list ap;
    va_start(ap, format);
    vfprintf(stream, format, ap);
    va_end(ap);
  }

}

extern "C" {
  static const char *const buildHost(void) {
    static char hostname[1024];
    static int gotit = 0;
    if (! gotit) {
      // (sic) was in the original code
      (void) ::gethostname(hostname, sizeof(hostname));
      ::hostent *hbn = ::gethostbyname(hostname);
      if (hbn) {
	strcpy(hostname, hbn->h_name);
      } else {
	rpm::log(rpm::MESS_WARNING, _("Could not canonicalize hostname: %s\n"), hostname);
      }
      gotit = 1;
    }
    return hostname;
  }
}

namespace sys {
  enum class AF { INET4 = AF_INET, INET6 = AF_INET6 };
  struct hostent;
  enum class herrc {
    host_not_found = HOST_NOT_FOUND,
      try_again = TRY_AGAIN,
      no_recovery = NO_RECOVERY,
      no_address = NO_ADDRESS, // same as no_data
      no_data = NO_DATA
  };
  namespace detail {
    std::size_t const PRUDENT_MAXIMUM_HOSTNAME_LENGTH = (2*MAXHOSTNAMELEN); // haters wanna
    union addr;
    class netdb_category;
    using getcall = std::function<::hostent *(char const *)>;
  }
}

namespace std {
  template<> struct is_error_condition_enum<sys::herrc>;
}

namespace sys {
  template<typename CHAR, typename TRAITS> inline auto operator<<(std::basic_ostream<CHAR, TRAITS> &, AF) -> std::basic_ostream<CHAR, TRAITS> &;
  auto netdb_category() noexcept -> std::error_category const &;
  inline auto gethostname() -> std::tuple<bool, int, std::system_error, std::string>;
  inline auto gethostbyname(std::string const &) -> std::tuple<bool, ::hostent *, std::system_error, hostent>; 
  inline auto gethostbyname2(std::string const &, AF) -> std::tuple<bool, ::hostent *, std::system_error, hostent>; 
  namespace detail {
    // count the length of a nullptr-terminated argv
    inline auto count(char const *const *argv) -> std::size_t;
    // gethostname(...) and gethostname2(...) are basically the same thing
    template<typename FUNCTION> auto gethostbyname(FUNCTION const &, std::string const &query_name) -> std::tuple<bool, ::hostent *, std::system_error, hostent>;
  }    
}

template<> struct std::is_error_condition_enum<sys::herrc> : public std::true_type { };

// per the memory shenanigains of ::hostent::h_addr_list
union sys::detail::addr {
  using addr4_type = ::in_addr;
  addr4_type addr4;
  using addr6_type = ::in6_addr;
  addr6_type addr6;
};

struct sys::hostent {
  // like ::hostent, but has appropriate deep copy semantics
  std::string name;                         // was h_name (Official name of host)
  std::vector<std::string> aliases;         // was h_aliases (Alias list)
  AF type;                                  // was h_addrtype (Host address type)
  std::size_t size;                         // was h_length (The address size, in bytes)
  std::vector<detail::addr> addresses;      // was h_addr_list (List of addresses from name server)
};

struct sys::detail::netdb_category : public std::error_category {
  using ancestor = std::error_category;
  // returns "netdb"
  auto name() const noexcept -> char const * override final;
  // returns hstrerror(code)
  auto message(int code) const -> std::string override final;
  // converts h_errno into 
  auto default_error_condition(int code) const noexcept -> std::error_condition override final;
};

auto sys::detail::count(char const *const *argv) -> std::size_t {
  std::size_t count = 0;
  if (nullptr != argv) {
    while (nullptr != *argv++) {
      count++;
    }
  }
  return count;
}

template<typename CHAR, typename TRAITS> auto sys::operator<<(std::basic_ostream<CHAR, TRAITS> &o, AF family) -> std::basic_ostream<CHAR, TRAITS> & {
  char const *begin, *end;
  switch (family) {
  case AF::INET4:
    {
      static char const WORD[]{"inet4"};
      begin = &WORD[0];
      end = &WORD[sizeof (WORD)-1];
    }
    break;
  case AF::INET6:
    {
      static char const WORD[]{"inet6"};
      begin = &WORD[0];
      end = &WORD[sizeof (WORD)-1];
    }
    break;
  default:
    throw std::system_error(std::make_error_code(std::errc::address_family_not_supported), "sys::AF=" + std::to_string(int(family)));
  }
  std::for_each(begin, end, [&o](char c) {
      o << o.widen(c);
    });
  return o;
}

auto sys::detail::netdb_category::name() const noexcept -> char const * {
  return "netdb";
}

// returns hstrerror(code)
auto sys::detail::netdb_category::message(int code) const -> std::string {
  return hstrerror(code);
}

auto sys::detail::netdb_category::default_error_condition(int code) const noexcept -> std::error_condition {
  return std::error_condition(code, *this);
}

auto sys::netdb_category() noexcept -> std::error_category const & {
  static detail::netdb_category const singleton;
  return singleton;
}

auto sys::gethostname() -> std::tuple<bool, int, std::system_error, std::string> {
  using result_type = std::tuple<bool, int, std::system_error, std::string>;
  std::vector<char> buf; // because you can't use a std::string as a fill-buffer
  buf.resize(detail::PRUDENT_MAXIMUM_HOSTNAME_LENGTH);
  int r = ::gethostname(buf.data(), buf.size());
  bool b = 0 == r;
  auto n2 = std::tuple_element<2, result_type>::type();
  auto n3 = std::tuple_element<3, result_type>::type();
  result_type result(b, r, n2, n3);
  if ( ! b ) {
    std::get<2>(result) = std::system_error(h_errno, sys::netdb_category(), "gethostname");
  } else {
    std::get<3>(result).assign(buf.data());
  }
  return result;
}

auto sys::gethostbyname(std::string const &query_name) -> std::tuple<bool, ::hostent *, std::system_error, hostent> {
  detail::getcall syscall = ::gethostbyname;
  return detail::gethostbyname(syscall, query_name);
}

auto sys::gethostbyname2(std::string const &query_name, AF family) -> std::tuple<bool, ::hostent *, std::system_error, hostent> {
  using namespace std::placeholders;
  detail::getcall syscall = std::bind(::gethostbyname2, _1, int(family));
  return detail::gethostbyname(syscall, query_name);
}

template<typename FUNCTION> auto sys::detail::gethostbyname(FUNCTION const &funcall, std::string const &query_name) -> std::tuple<bool, ::hostent *, std::system_error, hostent> {
  using result_type = std::tuple<bool, ::hostent *, std::system_error, hostent>;
  std::vector<char> buf; // because you can't use a std::string as a fill-buffer
  // not threadsafe, returns a pointer to static data
  ::hostent *r = funcall(query_name.c_str());
  bool b = nullptr != r;
  auto n2 = std::tuple_element<2, result_type>::type();
  auto n3 = std::tuple_element<3, result_type>::type();
  result_type result(b, r, n2, n3);
  if ( ! b ) {
    std::get<2>(result) = std::system_error(h_errno, sys::netdb_category(), "gethostbyname " + query_name);
  } else {
    hostent &href = std::get<3>(result);
    href.name = r->h_name;
    href.aliases.assign(&r->h_aliases[0], &r->h_aliases[detail::count(r->h_aliases)]);
    href.type = AF(r->h_addrtype);
    href.size = r->h_length;
    auto push_back = [&href, query_name](char const *rhs) {
      detail::addr lhs;
      switch (href.type) {
      case AF::INET4:
	lhs.addr4 = *(detail::addr::addr4_type *)(rhs);
	break;
      case AF::INET6:
	lhs.addr6 = *(detail::addr::addr6_type *)(rhs);
	break;
      default:
	// unclear this is a good idea.  If the address family isn't known, then the whole hostname
	// is poisoned to us until this gets cleared up.  Maybe we should ignore it and move along?
	throw std::system_error(std::make_error_code(std::errc::address_family_not_supported), "gethostbyname " + query_name);
      }
      href.addresses.push_back(lhs);
    };
    std::for_each(&r->h_addr_list[0], &r->h_addr_list[detail::count(r->h_addr_list)], push_back);
  }
  return result;
}

namespace {

  auto get_canonical_build_hostname(void) -> std::string {
    static std::string hostname;
    static bool cached(false);
    if (cached) {
      return hostname;
    }
    static_assert(std::is_same<std::tuple<bool, int, std::system_error, std::string>, decltype(sys::gethostname())>::value,
		  "sys::gethostname() return type is surprising");
    auto gethostname = sys::gethostname();
    if ( ! std::get<0>(gethostname)) {
      throw std::get<2>(gethostname);
    }
    std::string const &best_hostname_estimate = std::get<3>(gethostname);
    static_assert(std::is_same<std::tuple<bool, ::hostent *, std::system_error, sys::hostent>, decltype(sys::gethostbyname(std::string()))>::value,
		  "sys::gethostbyname(...) return type is surprising");
    auto gethostbyname = sys::gethostbyname(best_hostname_estimate);
    if (std::get<0>(gethostbyname)) {
      hostname.assign(std::get<3>(gethostbyname).name);
      return hostname;
    }
    // recall: that gethostbyname(...) only checks IPv4 ... and we could have an IPv6-only host on our hands [this is the modern age buddy!]
    std::array<sys::AF,2> const families{sys::AF::INET6, sys::AF::INET4};
    static_assert(std::is_same<std::tuple<bool, ::hostent *, std::system_error, sys::hostent>, decltype(sys::gethostbyname2(std::string(), sys::AF()))>::value,
		  "sys::gethostbyname2(...) return type is surprising");
    for (auto family : families) {
      auto gethostbyname2 = sys::gethostbyname2(best_hostname_estimate, family);
      if (std::get<0>(gethostbyname2)) {
	hostname.assign(std::get<3>(gethostbyname2).name);
	return hostname;
      }
    }
    // Characterizing that first failure
    throw std::get<2>(gethostbyname);
  } 

}

auto main() -> int {
  try {
    {
      std::cout << "Trial #1. (Straight C, like you learned in the '80s)\n";
      std::string hostname = ::buildHost();
      std::cout << "canonical hostname: " << hostname;
      char const *const was = 1 == rpm::message_count ? "was" : "where";
      char const *const problem = 1 == rpm::message_count ? "problem": "problems";
      std::cout << ", there " << was << ' ' << rpm::message_count << ' ' << problem << " observed\n";
    } {
      std::cout << "Trial #2. (SCOLD C++ Techniques)\n";
      std::string hostname, problem; 
      try {
	hostname = get_canonical_build_hostname();
      } catch (std::exception const &e) {
	problem = e.what();
      }
      std::cout << "canonical hostname: " << hostname;
      if (hostname.empty()) {
	std::cout << "(empty)";
      }
      if (!problem.empty()) {
	std::cout << ", problems found as " << problem;
      } else {
	std::cout << ", no problems observed, the answer is unambiguous";
      }
      std::cout << '\n';
    }
    return 0;
  } catch (std::exception const &e) {
    std::clog << "FAIL: unexpected exception " << e.what() << '\n';
    return 1;
  }
}

Referenced

Forthcoming

Scalable C++ Original Location Disaggregation (SCOLD)

gcc’s ‘#pragma once’ accounts for file timestamp and contents but not name

Nota Bene: gcc’s #pragma once takes into account the file timestamp and the file contents but does not take into account the file name or position in the tree. This is unfortunate.

Folklore

This can occur…

  • On very fast systems & filesystems such that file timestamps become “the same” (having the same per-second granularity).
  • [unusual] When files are copied OR
  • When files have substantially the same contents but because of their location in the build tree or searchpath, make visible different ancillary files.

Evidence

  • 52566#include with #pragma once and files’ contents is the same

Modules in C++, Roundup

More or less archaeological order; newer works on top, older works down below.

Proposals

References

  • Bjarne Stoustrup; C++ FAQ; current, last update 2014-10?.
  • Stefanus Du Toit; Workiing Draft, Standard for Programming Language C++; Document N3797; ISO/IEC JTC1/SC22/WG21; 2013-10-13; 1366 pages.
    Also: draft source.
  • International Standard ISO/IEC 14882 Programming Languages — C++; International Organization for Standards; 3rd edition; 2011; paywalled.
  • Margaret E. Ellis, Bjarne Stroustrup; The Annotated C++ Reference Manual; Addison-Wesley; 1990.

Scalable C++ Original Location Disaggregation (SCOLD) from 2004

Wendell Baker; Scalable C++ Original Location Disaggregation (SCOLD); 2004-04-12.

  • language definition
  • prototype code.

Overview

  • Version v0.1, circa 2004-Q2.
  • Five phases of the C++ declarations
    • forward declarations; e.g. class name declarations with incomplete types.
    • complete declarations; e.g. with class definitions.
    • inline definitions; e.g. inline functions, inline function templates
    • outline definition declarations; e.g. outline templates
    • outline definitions; e.g. are strong definitions subject the One Definition Rule (ODR)
  • Codifies existing reasonable-to-best practice in library physical design.
  • Blends in with the existing cut & paste methodology of C Pre–Processor language capability of C++98, C++03 [and now C++11].

Grammar

translation_unit ::= stanza-list

stanza ::= declaration-list code-body

declaration ::= provide | require | include

code-body ::= forward declarations { ...arbitrary C++ Code... }
code-body ::= complete declarations { ...arbitrary C++ Code... }
code-body ::= inline definitions { ...arbitrary C++ Code... }
code-body ::= outline definition declarations { ...arbitrary C++ Code... }
code-body ::= outline definitions { ...arbitrary C++ Code... }

Semantics

  • Semantics defined in terms of the existing #include model of a C++ translation unit.
  • The stanzas necessarily have a partial order defined by the C++ Standard; i.e.the stanzas within a translation unit must be ordered as:
    • forward declarations precede complete declarations
    • which precede inline definitions
    • which precede outline definition declarations
    • which precede outline definitions
  • Reminder: consider a multiple translation unit application.
  • The declarations establish a partial order among the code bodies from other translation units.
  • The stanzas forward declaration through outline definition declarations must be presented for the outline definitions section of any translation uint.
  • There is a natural “zipper-like” reassembly of the interfaces via idempotent recursive #include-type operations (think #pragma once).

Implementation

For module mymodule.scpp as a translation unit:

  • the forward declarations stanza becomes mymodule.fpp
  • the complete declarations stanza becomes mymodule.hpp
    • which includes mymodule.fpp
    • and #includes hpp phases from other translation units mentioned as  requires
  • the inline definitions stanza becomes mymodule.ipp
    • which includes mymodule.hpp
    • and #includes ipp phases from other translation units mentioned as  requires
  • the outline definition declarations stanza becomes mymodule.tpp
    • which includes mymodule.ipp
    • and #includes tpp phases from other translation units mentioned as  requires
  • the complete declarations stanza becomes mymodule.cpp
    • which includes mymodule.tpp
    • and #includes the tpp phases from any other translation units’ interfaces that it requires.

Example

provide <iostream>;
provide "myclass.h";
provide myclass;
provide mynamespace::myclass;
forward declarations {
  class myclass;
  namespace mynamespace {
    class myclass;
  }
}

require std::auto_ptr;
require std::string;
complete declarations {
#include <iostream>
#include "myclass.h"
  class myclass {
    int save;
  public:
    myclass();
    inline int value() const;
  };
  namespace mynamespace {
    class myclass {
    public:
      myclass(std::string const &);
      template<typename TYPE> void set(TYPE);
    };
  }
}

inline declarations {
   inline int myclass::value() const {
     return save;
  }
}

outline definition declarations {
  template<typename TYPE> void myclass::set(TYPE x) {
    ...etc...
  }
}

outline definitions {
  mynamespace::myclass::myclass(std::string const &value) {
    ...etc...
  }
}

Proxygen by Facebook, a C++ HTTP Framework

Daniel Sommermann, Alan Frindell (Facebook); Introducing Proxygen, Facebook’s C++ HTTP Framework; In Their Blog; 2014-11-09.

Mentions

Assessment

Summary
Language LOC App LOC Test LOC
am 695 572 123
c++ 47,712 35,075 12,637
py 163 163 0
sh 84 84 0
total 48,654 35,894 12,760

Language (C++)

  • C++11
  • In-class initializers
  • Uniform Initialization
    • brace-enclosed initializers
    • in-class initializers
  • move semantics
  • namespaces
  • const
  • return value optimization (functions returning containers)
  • seems formatted for 80 character teletype screens.
  • std::unique_ptr
  • bool as single bitfield
  • range for loop
  • auto
  • std::string in lieu of char * (sometimes)
  • std::vector in lieu of arrays (sometimes)
  • attributes
    • final
    • ifunc (indirect function, per ELF)
    • noexcept
    • override
    • __attribute__((constructor))
  • static_assert
  • std::function
  • std::thread
  • std::chrono (seconds, milliseconds)

Dependencies

Runtime
Buildtime
  • Python
  • Ruby
  • gperf

Physical Design

  • (outline) function definitions separated from the function declaration (mostly)
  • roughly one class per file
  • Suffixes
    • *.hpp
    • *.cpp

Build System

  • autotools (automake, autoconf)
  • doxygen

Portability

  • Ubuntu

Promotion

Via: backfill

Actualities

CoreProxygenArchitecture.png

Inventory

LOC File
264 ./proxygen/proxygen/configure.ac
27 ./proxygen/proxygen/httpserver/Makefile.am
10 ./proxygen/proxygen/httpserver/samples/echo/Makefile.am
1 ./proxygen/proxygen/httpserver/samples/Makefile.am
1 ./proxygen/proxygen/lib/http/codec/Makefile.am
135 ./proxygen/proxygen/lib/http/Makefile.am
1 ./proxygen/proxygen/lib/http/session/Makefile.am
13 ./proxygen/proxygen/lib/Makefile.am
29 ./proxygen/proxygen/lib/services/Makefile.am
28 ./proxygen/proxygen/lib/ssl/Makefile.am
62 ./proxygen/proxygen/lib/utils/Makefile.am
1 ./proxygen/proxygen/Makefile.am
2381 ./proxygen/proxygen/external/http_parser/http_parser_cpp.cpp
319 ./proxygen/proxygen/external/http_parser/http_parser.h
3142 ./proxygen/proxygen/external/http_parser/test.c
59 ./proxygen/proxygen/httpserver/filters/DirectResponseHandler.h
125 ./proxygen/proxygen/httpserver/Filters.h
106 ./proxygen/proxygen/httpserver/filters/RejectConnectFilter.h
92 ./proxygen/proxygen/httpserver/HTTPServerAcceptor.cpp
48 ./proxygen/proxygen/httpserver/HTTPServerAcceptor.h
205 ./proxygen/proxygen/httpserver/HTTPServer.cpp
142 ./proxygen/proxygen/httpserver/HTTPServer.h
86 ./proxygen/proxygen/httpserver/HTTPServerOptions.h
78 ./proxygen/proxygen/httpserver/Mocks.h
186 ./proxygen/proxygen/httpserver/RequestHandlerAdaptor.cpp
74 ./proxygen/proxygen/httpserver/RequestHandlerAdaptor.h
76 ./proxygen/proxygen/httpserver/RequestHandlerFactory.h
99 ./proxygen/proxygen/httpserver/RequestHandler.h
198 ./proxygen/proxygen/httpserver/ResponseBuilder.h
84 ./proxygen/proxygen/httpserver/ResponseHandler.h
56 ./proxygen/proxygen/httpserver/samples/echo/EchoHandler.cpp
47 ./proxygen/proxygen/httpserver/samples/echo/EchoHandler.h
87 ./proxygen/proxygen/httpserver/samples/echo/EchoServer.cpp
41 ./proxygen/proxygen/httpserver/samples/echo/EchoStats.h
192 ./proxygen/proxygen/httpserver/ScopedHTTPServer.h
36 ./proxygen/proxygen/httpserver/SignalHandler.cpp
37 ./proxygen/proxygen/httpserver/SignalHandler.h
218 ./proxygen/proxygen/lib/http/codec/CodecDictionaries.h
92 ./proxygen/proxygen/lib/http/codec/CodecProtocol.cpp
51 ./proxygen/proxygen/lib/http/codec/CodecProtocol.h
409 ./proxygen/proxygen/lib/http/codec/compress/GzipHeaderCodec.cpp
96 ./proxygen/proxygen/lib/http/codec/compress/GzipHeaderCodec.h
128 ./proxygen/proxygen/lib/http/codec/compress/HeaderCodec.h
46 ./proxygen/proxygen/lib/http/codec/compress/Header.h
61 ./proxygen/proxygen/lib/http/codec/compress/HeaderPiece.h
210 ./proxygen/proxygen/lib/http/codec/compress/HeaderTable.cpp
221 ./proxygen/proxygen/lib/http/codec/compress/HeaderTable.h
105 ./proxygen/proxygen/lib/http/codec/compress/HPACKCodec.cpp
56 ./proxygen/proxygen/lib/http/codec/compress/HPACKCodec.h
50 ./proxygen/proxygen/lib/http/codec/compress/HPACKConstants.h
59 ./proxygen/proxygen/lib/http/codec/compress/HPACKContext.cpp
58 ./proxygen/proxygen/lib/http/codec/compress/HPACKContext.h
105 ./proxygen/proxygen/lib/http/codec/compress/HPACKDecodeBuffer.cpp
84 ./proxygen/proxygen/lib/http/codec/compress/HPACKDecodeBuffer.h
167 ./proxygen/proxygen/lib/http/codec/compress/HPACKDecoder.cpp
78 ./proxygen/proxygen/lib/http/codec/compress/HPACKDecoder.h
112 ./proxygen/proxygen/lib/http/codec/compress/HPACKEncodeBuffer.cpp
94 ./proxygen/proxygen/lib/http/codec/compress/HPACKEncodeBuffer.h
155 ./proxygen/proxygen/lib/http/codec/compress/HPACKEncoder.cpp
75 ./proxygen/proxygen/lib/http/codec/compress/HPACKEncoder.h
36 ./proxygen/proxygen/lib/http/codec/compress/HPACKHeader.cpp
81 ./proxygen/proxygen/lib/http/codec/compress/HPACKHeader.h
345 ./proxygen/proxygen/lib/http/codec/compress/Huffman.cpp
138 ./proxygen/proxygen/lib/http/codec/compress/Huffman.h
158 ./proxygen/proxygen/lib/http/codec/compress/Logging.cpp
39 ./proxygen/proxygen/lib/http/codec/compress/Logging.h
111 ./proxygen/proxygen/lib/http/codec/compress/StaticHeaderTable.cpp
24 ./proxygen/proxygen/lib/http/codec/compress/StaticHeaderTable.h
39 ./proxygen/proxygen/lib/http/codec/ErrorCode.cpp
52 ./proxygen/proxygen/lib/http/codec/ErrorCode.h
124 ./proxygen/proxygen/lib/http/codec/FlowControlFilter.cpp
97 ./proxygen/proxygen/lib/http/codec/FlowControlFilter.h
1071 ./proxygen/proxygen/lib/http/codec/HTTP1xCodec.cpp
196 ./proxygen/proxygen/lib/http/codec/HTTP1xCodec.h
49 ./proxygen/proxygen/lib/http/codec/HTTPChecks.cpp
38 ./proxygen/proxygen/lib/http/codec/HTTPChecks.h
263 ./proxygen/proxygen/lib/http/codec/HTTPCodecFilter.cpp
175 ./proxygen/proxygen/lib/http/codec/HTTPCodecFilter.h
468 ./proxygen/proxygen/lib/http/codec/HTTPCodec.h
74 ./proxygen/proxygen/lib/http/codec/HTTPSettings.cpp
71 ./proxygen/proxygen/lib/http/codec/HTTPSettings.h
16 ./proxygen/proxygen/lib/http/codec/SettingsId.cpp
44 ./proxygen/proxygen/lib/http/codec/SettingsId.h
1584 ./proxygen/proxygen/lib/http/codec/SPDYCodec.cpp
378 ./proxygen/proxygen/lib/http/codec/SPDYCodec.h
163 ./proxygen/proxygen/lib/http/codec/SPDYConstants.cpp
130 ./proxygen/proxygen/lib/http/codec/SPDYConstants.h
81 ./proxygen/proxygen/lib/http/codec/SPDYUtil.cpp
144 ./proxygen/proxygen/lib/http/codec/SPDYUtil.h
16 ./proxygen/proxygen/lib/http/codec/SPDYVersion.h
47 ./proxygen/proxygen/lib/http/codec/SPDYVersionSettings.h
33 ./proxygen/proxygen/lib/http/codec/TransportDirection.cpp
28 ./proxygen/proxygen/lib/http/codec/TransportDirection.h
61 ./proxygen/proxygen/lib/http/HTTPCommonHeaders.template.h
167 ./proxygen/proxygen/lib/http/HTTPConnector.cpp
152 ./proxygen/proxygen/lib/http/HTTPConnector.h
32 ./proxygen/proxygen/lib/http/HTTPConstants.cpp
67 ./proxygen/proxygen/lib/http/HTTPConstants.h
31 ./proxygen/proxygen/lib/http/HTTPException.cpp
169 ./proxygen/proxygen/lib/http/HTTPException.h
308 ./proxygen/proxygen/lib/http/HTTPHeaders.cpp
423 ./proxygen/proxygen/lib/http/HTTPHeaders.h
34 ./proxygen/proxygen/lib/http/HTTPHeaderSize.h
831 ./proxygen/proxygen/lib/http/HTTPMessage.cpp
98 ./proxygen/proxygen/lib/http/HTTPMessageFilters.h
724 ./proxygen/proxygen/lib/http/HTTPMessage.h
45 ./proxygen/proxygen/lib/http/HTTPMethod.cpp
59 ./proxygen/proxygen/lib/http/HTTPMethod.h
34 ./proxygen/proxygen/lib/http/ProxygenErrorEnum.cpp
73 ./proxygen/proxygen/lib/http/ProxygenErrorEnum.h
81 ./proxygen/proxygen/lib/http/RFC2616.cpp
73 ./proxygen/proxygen/lib/http/RFC2616.h
23 ./proxygen/proxygen/lib/http/session/AckLatencyEvent.h
33 ./proxygen/proxygen/lib/http/session/ByteEvents.cpp
105 ./proxygen/proxygen/lib/http/session/ByteEvents.h
171 ./proxygen/proxygen/lib/http/session/ByteEventTracker.cpp
85 ./proxygen/proxygen/lib/http/session/ByteEventTracker.h
67 ./proxygen/proxygen/lib/http/session/CodecErrorResponseHandler.cpp
42 ./proxygen/proxygen/lib/http/session/CodecErrorResponseHandler.h
122 ./proxygen/proxygen/lib/http/session/HTTPDirectResponseHandler.cpp
52 ./proxygen/proxygen/lib/http/session/HTTPDirectResponseHandler.h
89 ./proxygen/proxygen/lib/http/session/HTTPDownstreamSession.cpp
73 ./proxygen/proxygen/lib/http/session/HTTPDownstreamSession.h
34 ./proxygen/proxygen/lib/http/session/HTTPErrorPage.cpp
70 ./proxygen/proxygen/lib/http/session/HTTPErrorPage.h
47 ./proxygen/proxygen/lib/http/session/HTTPEvent.cpp
126 ./proxygen/proxygen/lib/http/session/HTTPEvent.h
102 ./proxygen/proxygen/lib/http/session/HTTPSessionAcceptor.cpp
141 ./proxygen/proxygen/lib/http/session/HTTPSessionAcceptor.h
71 ./proxygen/proxygen/lib/http/session/HTTPSessionController.h
2002 ./proxygen/proxygen/lib/http/session/HTTPSession.cpp
832 ./proxygen/proxygen/lib/http/session/HTTPSession.h
25 ./proxygen/proxygen/lib/http/session/HTTPSessionStats.h
933 ./proxygen/proxygen/lib/http/session/HTTPTransaction.cpp
118 ./proxygen/proxygen/lib/http/session/HTTPTransactionEgressSM.cpp
71 ./proxygen/proxygen/lib/http/session/HTTPTransactionEgressSM.h
1155 ./proxygen/proxygen/lib/http/session/HTTPTransaction.h
134 ./proxygen/proxygen/lib/http/session/HTTPTransactionIngressSM.cpp
73 ./proxygen/proxygen/lib/http/session/HTTPTransactionIngressSM.h
116 ./proxygen/proxygen/lib/http/session/HTTPUpstreamSession.cpp
95 ./proxygen/proxygen/lib/http/session/HTTPUpstreamSession.h
66 ./proxygen/proxygen/lib/http/session/SimpleController.cpp
66 ./proxygen/proxygen/lib/http/session/SimpleController.h
162 ./proxygen/proxygen/lib/http/session/TransportFilter.cpp
124 ./proxygen/proxygen/lib/http/session/TransportFilter.h
27 ./proxygen/proxygen/lib/http/session/TTLBAStats.h
96 ./proxygen/proxygen/lib/http/Window.cpp
84 ./proxygen/proxygen/lib/http/Window.h
59 ./proxygen/proxygen/lib/services/AcceptorConfiguration.h
444 ./proxygen/proxygen/lib/services/Acceptor.cpp
342 ./proxygen/proxygen/lib/services/Acceptor.h
56 ./proxygen/proxygen/lib/services/ConnectionCounter.h
54 ./proxygen/proxygen/lib/services/HTTPAcceptor.h
45 ./proxygen/proxygen/lib/services/LoadShedConfiguration.cpp
109 ./proxygen/proxygen/lib/services/LoadShedConfiguration.h
60 ./proxygen/proxygen/lib/services/NetworkAddress.h
40 ./proxygen/proxygen/lib/services/RequestWorker.cpp
89 ./proxygen/proxygen/lib/services/RequestWorker.h
126 ./proxygen/proxygen/lib/services/ServerSocketConfig.h
58 ./proxygen/proxygen/lib/services/ServiceConfiguration.h
33 ./proxygen/proxygen/lib/services/Service.cpp
137 ./proxygen/proxygen/lib/services/Service.h
102 ./proxygen/proxygen/lib/services/ServiceWorker.h
66 ./proxygen/proxygen/lib/services/TransportInfo.cpp
279 ./proxygen/proxygen/lib/services/TransportInfo.h
160 ./proxygen/proxygen/lib/services/WorkerThread.cpp
129 ./proxygen/proxygen/lib/services/WorkerThread.h
24 ./proxygen/proxygen/lib/ssl/ClientHelloExtStats.h
53 ./proxygen/proxygen/lib/ssl/DHParam.h
31 ./proxygen/proxygen/lib/ssl/PasswordInFile.cpp
38 ./proxygen/proxygen/lib/ssl/PasswordInFile.h
23 ./proxygen/proxygen/lib/ssl/SSLCacheOptions.h
69 ./proxygen/proxygen/lib/ssl/SSLCacheProvider.h
95 ./proxygen/proxygen/lib/ssl/SSLContextConfig.h
654 ./proxygen/proxygen/lib/ssl/SSLContextManager.cpp
186 ./proxygen/proxygen/lib/ssl/SSLContextManager.h
354 ./proxygen/proxygen/lib/ssl/SSLSessionCacheManager.cpp
293 ./proxygen/proxygen/lib/ssl/SSLSessionCacheManager.h
42 ./proxygen/proxygen/lib/ssl/SSLStats.h
76 ./proxygen/proxygen/lib/ssl/SSLUtil.cpp
102 ./proxygen/proxygen/lib/ssl/SSLUtil.h
308 ./proxygen/proxygen/lib/ssl/TLSTicketKeyManager.cpp
198 ./proxygen/proxygen/lib/ssl/TLSTicketKeyManager.h
20 ./proxygen/proxygen/lib/ssl/TLSTicketKeySeeds.h
60 ./proxygen/proxygen/lib/utils/CobHelper.h
76 ./proxygen/proxygen/lib/utils/CryptUtil.cpp
22 ./proxygen/proxygen/lib/utils/CryptUtil.h
84 ./proxygen/proxygen/lib/utils/DestructorCheck.h
71 ./proxygen/proxygen/lib/utils/DomainNameMisc.h
34 ./proxygen/proxygen/lib/utils/Exception.cpp
46 ./proxygen/proxygen/lib/utils/Exception.h
358 ./proxygen/proxygen/lib/utils/FilterChain.h
43 ./proxygen/proxygen/lib/utils/HTTPTime.cpp
20 ./proxygen/proxygen/lib/utils/HTTPTime.h
16 ./proxygen/proxygen/lib/utils/NullTraceEventObserver.cpp
23 ./proxygen/proxygen/lib/utils/NullTraceEventObserver.h
159 ./proxygen/proxygen/lib/utils/ParseURL.cpp
112 ./proxygen/proxygen/lib/utils/ParseURL.h
242 ./proxygen/proxygen/lib/utils/Result.h
38 ./proxygen/proxygen/lib/utils/SocketOptions.cpp
24 ./proxygen/proxygen/lib/utils/SocketOptions.h
46 ./proxygen/proxygen/lib/utils/StateMachine.h
37 ./proxygen/proxygen/lib/utils/TestUtils.h
128 ./proxygen/proxygen/lib/utils/Time.h
32 ./proxygen/proxygen/lib/utils/TraceEventContext.h
130 ./proxygen/proxygen/lib/utils/TraceEvent.cpp
139 ./proxygen/proxygen/lib/utils/TraceEvent.h
24 ./proxygen/proxygen/lib/utils/TraceEventObserver.h
24 ./proxygen/proxygen/lib/utils/UtilInl.h
163 ./proxygen/proxygen/lib/utils/gen_trace_event_constants.py
54 ./proxygen/proxygen/deps.sh
30 ./proxygen/proxygen/reinstall.sh
11 ./proxygen/proxygen/httpserver/tests/Makefile.am
21 ./proxygen/proxygen/lib/http/codec/test/Makefile.am
21 ./proxygen/proxygen/lib/http/session/test/Makefile.am
14 ./proxygen/proxygen/lib/http/test/Makefile.am
16 ./proxygen/proxygen/lib/ssl/test/Makefile.am
27 ./proxygen/proxygen/lib/test/Makefile.am
13 ./proxygen/proxygen/lib/utils/test/Makefile.am
97 ./proxygen/proxygen/httpserver/samples/echo/test/EchoHandlerTest.cpp
154 ./proxygen/proxygen/httpserver/tests/HTTPServerTest.cpp
35 ./proxygen/proxygen/lib/http/codec/compress/test/HeaderPieceTests.cpp
134 ./proxygen/proxygen/lib/http/codec/compress/test/HeaderTableTests.cpp
345 ./proxygen/proxygen/lib/http/codec/compress/test/HPACKBufferTests.cpp
283 ./proxygen/proxygen/lib/http/codec/compress/test/HPACKCodecTests.cpp
202 ./proxygen/proxygen/lib/http/codec/compress/test/HPACKContextTests.cpp
65 ./proxygen/proxygen/lib/http/codec/compress/test/HPACKHeaderTests.cpp
96 ./proxygen/proxygen/lib/http/codec/compress/test/HTTPArchive.cpp
37 ./proxygen/proxygen/lib/http/codec/compress/test/HTTPArchive.h
312 ./proxygen/proxygen/lib/http/codec/compress/test/HuffmanTests.cpp
146 ./proxygen/proxygen/lib/http/codec/compress/test/LoggingTests.cpp
212 ./proxygen/proxygen/lib/http/codec/compress/test/RFCExamplesTests.cpp
61 ./proxygen/proxygen/lib/http/codec/compress/test/TestUtil.cpp
28 ./proxygen/proxygen/lib/http/codec/compress/test/TestUtil.h
222 ./proxygen/proxygen/lib/http/codec/test/FilterTests.cpp
130 ./proxygen/proxygen/lib/http/codec/test/HTTP1xCodecTest.cpp
130 ./proxygen/proxygen/lib/http/codec/test/MockHTTPCodec.h
1228 ./proxygen/proxygen/lib/http/codec/test/SPDYCodecTest.cpp
207 ./proxygen/proxygen/lib/http/codec/test/TestUtils.cpp
237 ./proxygen/proxygen/lib/http/codec/test/TestUtils.h
226 ./proxygen/proxygen/lib/http/session/test/DownstreamTransactionTest.cpp
1367 ./proxygen/proxygen/lib/http/session/test/HTTPDownstreamSessionTest.cpp
154 ./proxygen/proxygen/lib/http/session/test/HTTPSessionAcceptorTest.cpp
226 ./proxygen/proxygen/lib/http/session/test/HTTPSessionMocks.h
71 ./proxygen/proxygen/lib/http/session/test/HTTPSessionTest.h
153 ./proxygen/proxygen/lib/http/session/test/HTTPTransactionMocks.h
169 ./proxygen/proxygen/lib/http/session/test/HTTPTransactionSMTest.cpp
1411 ./proxygen/proxygen/lib/http/session/test/HTTPUpstreamSessionTest.cpp
1368 ./proxygen/proxygen/lib/http/session/test/MockCodecDownstreamTest.cpp
41 ./proxygen/proxygen/lib/http/session/test/TestUtils.cpp
34 ./proxygen/proxygen/lib/http/session/test/TestUtils.h
463 ./proxygen/proxygen/lib/http/test/HTTPMessageTest.cpp
49 ./proxygen/proxygen/lib/http/test/MockHTTPMessageFilter.h
128 ./proxygen/proxygen/lib/http/test/RFC2616Test.cpp
124 ./proxygen/proxygen/lib/http/test/WindowTest.cpp
83 ./proxygen/proxygen/lib/services/test/AcceptorTest.cpp
278 ./proxygen/proxygen/lib/ssl/test/SSLCacheTest.cpp
88 ./proxygen/proxygen/lib/ssl/test/SSLContextManagerTest.cpp
635 ./proxygen/proxygen/lib/test/TestAsyncTransport.cpp
158 ./proxygen/proxygen/lib/test/TestAsyncTransport.h
23 ./proxygen/proxygen/lib/test/TestMain.cpp
49 ./proxygen/proxygen/lib/utils/test/CryptUtilTest.cpp
538 ./proxygen/proxygen/lib/utils/test/GenericFilterTest.cpp
54 ./proxygen/proxygen/lib/utils/test/HTTPTimeTest.cpp
42 ./proxygen/proxygen/lib/utils/test/MockTime.h
137 ./proxygen/proxygen/lib/utils/test/ParseURLTest.cpp
73 ./proxygen/proxygen/lib/utils/test/ResultBenchmark.cpp
112 ./proxygen/proxygen/lib/utils/test/ResultTest.cpp
22 ./proxygen/proxygen/lib/utils/test/UtilTest.cpp

Effective Modern C++ | Scott Meyers

Scott Meyers; Effective Modern C++: 42 Specific Ways to Improve Your Use of C++11 and C++14; O’Reilly Media; 1st edition; 2014-12-04; 320 pages; kindle: no, paper: $41.


Related

Scott Meyers; Effective Modern C++; At NDC on Vimeo; 2014; 1:00:??.

Mentions

  • Prefer auto, for a variety of reasons
  • Whereas
    • int (int unsigned) is 32 bits
    • std::size_t is always 64 bits
  • Closures might or might not use heap storage depending upon how many objects are captured.  The auto variant will be inlined & on the stack.

    • std::function<int (int)> = fla = [=](int x) { ... }
    • auto = fla = [=](int x) { ... }
  • A braced initializer does not have a t ype, but deduces to std::initializer_list<TYPE> mostly.
  • Proxy types, hidden proxy types (so you want to use auto)
    • ! std::is_same<std::vector<bool>::reference *, type *>::value
  • Uniform Initialization (mostly) can be done with brace initialization
    • disallows narrowing conversions
    • different rules for constructor overloading matches in the presence of std::initializer_list<TYPE>.
  • Atomic Data versus Transactions (mutexes)
    • bitwise const or internal synchronization
    • standard discipline for multithreaded design applies

Actualities

ol>

N3570: Quoted Strings Library Proposal

N3570; Quoted Strings Library Proposal; (Revision 1); Beman Dawes; 2013-03-14

Sample

std::stringstream ss;
std::string original = "fooled you";
std::string round_trip;

ss << quoted(original);
ss >> quoted(round_trip);

std::cout << quoted(original); // outputs: "fooled you"
std::cout << round_trip; // outputs: fooled you

assert(original == round_trip); // assert will not fire

Related

Via: backfill

C++ Formatting Libraries

 Libraries

Application: integer-to-string conversion

  1. sprintf
  2. std::stringstream
  3. std::to_string from C++11
  4. boost::format from the Boost Format library
  5. boost::lexical_cast
  6. karma::generate from the Boost Spirit Parser framework
  7. fmt::Writer from the format library
  8. fmt::Format from the format library
  9. Public-domain ltoa implementation
  10. decimal_from function suggested by Alf P. Steinbach
  11. fmt::FormatInt from the format library

Via: Victor Zverovich; Fast integer to string conversion in C++; In His Blog; 2013-09-07.

Examples

C Stdio:
printf("%s, %s %d\n", weekday, month, day);

IOStreams:
std::cout << weekday << ", " << month << " " << day << "\n";

Boost Format:
std::string s = str(boost::format("%1%, %2% %3%\n") % weekday % month % day);

SafeFormat:
Loki::SPrintf(s, "%s, %d %d\n")(weekday)(month)(day);

Format
std::string s = str(fmt::Format("{0}, {1} {2}\n") << weekday << month << day);
ReportError("File not found: {0}") << path;

Referenced

Via: backfill

 

N3580: Concepts Lite | Sutton, Stoustrup, Dos Reis

Concepts Lite

Via: backfill

C++0x, C++11, C++14

Overview

C++11

Boost

  • boost::shared_mutex
    RAII

    • shared_lock takes a shared read lock
    • lock_guard
      • std::lock_guard<std::mutex>
    • unique_lock take an exclusive lock
  • boost::unique_future
  • boost::thread
    • Has cancellation, called interruption (rly?)
    • Uses boost::bind, which requires copyable arguments
  • boost::bind
  • boost::format
    • is like printf, but (um) better
  • Boost.Exception
  • Beyond C++11
    • join with timeout
    • thread interruption
    • thread groups
    • extra lock types

Future

  • Concepts
    • N3701 Concepts Lite; 2013-06-28
    • N3351 Concept Design for the STL; 2012-01-13.
    • N2081 Concepts (Revision 1); 2006-09-10.
    • Concept Maps (maybe, maybe not)
    • Concept GCC; In Jimi Wales’ Wiki.
  • Modules

Historical

  • #include <pthread.h>
  • pthread_create(pthread_t *, pthread_attr_t const *, void *(*routine)(void *), void *routine_arg)

Standards Working Documents

  • N2179 Language Support for Transporting Exceptions between Threads; 2007-03-03.
  • N2184 Thread Launching for C++; 2007-03-09
  • N2320 Multi-threading Library for Standard C++; 2007-06-24.
  • N2431 A name for the null pointer: nullptr; 2007-10-02.
  • N2880 C++ object lifetime interactions with the threads API; 2009-05-01.
  • N3070 Handling Detached Threads and thread_local Variables; 2010-03-11.
  • N3242 Working Draft, Standard for Programming Language C++; 2011-02-28.

Referenced

General

Detailed, Dated

Modules in C++ | N3347=12-0037

Daveed Vandevoorde; Modules in C++; n3347; Revision 6; 2012-01-11; 23 pages.

Syntax

import modulename; (semicolon)
import modulename.partitionname; (semicolon)
import {
    ... declarations ...
}
export modulename: (colon)
export modulename.partitionname: (colon)
public:
private:
(not protected:)

Properties

  • New name class:
    • module name
    • similar to namespace name, class name, enum name, etc.
  • Module names may look like nested namespace qualifiers
    • but are not nested namespace qualifiers
    • e.g. module Boost::MPL might contain
      namespace Boost {
        namespace MPL {
          ...declarations...
        }
      }
  • Module declarations must precede all other declarations.
  • Module names are not namespace names; they cannot be used as qualifiers in a qualified name
  • Inline imports are not members of any module and are thus not exportable.
  • A module may span multiple translation units.
  • The module import dependency order is necessarily a partial order.
  • The module dependency order provides for accurate initialization guarantees.

Implied Invariants & Requirements

  • The dependencies among partitions within a module must form a directed acyclic graph.
  • Within a module partition the module variables are initialized in the order currently specified for a translation unit (see [basic.start.init] §3.6.2). The module variables and local static variables of a program are destroyed in reverse order of initialization (see [basic.start.term] §3.6.3)
  • Every import directive implicitly defines anonymous namespace scope variables associated with each module partition being imported. These variables require dynamic initialization. The first of such variables associated with a partition to be initialized triggers by its initialization the initialization of the associated partition; the initialization of the other variables associated with the same partition is without effect.
  • In modules, public entities cannot have internal linkage.
  • An imported class type is incomplete unless its definition was public or a public declaration requires the type to be complete.
  • Outside the module containing a derived class, its private base classes are not considered for derived-to-base or base-to-derived conversions.

Considerations

  • Build-time considerations.
  • How will make work?

Options

-M /path/location
The location of modules for use, like a -I searchpath?
-X /path/location
Where the module is to be created for later use.

Mentions

  • Precompiled Interface File (PIF)
  • <quote>An internal project at Intel has been tracking the ratio of C++ code in “.cpp” files to the amount of code in header files: In the early nineties, header files only contained about 10% of all that project’s code; a decade later, well over half the code resided in header files.</quote>
  • common template instantiation strategies
    • greedy
    • queried
    • iterated

Cited

  • N1400 Toward standardization of dynamic libraries; Matt Austern; 2002.
  • N1602 Class Scope Using Declarations & private Members; Francis Glassborow; 2004.
  • N1614 #scope: A simple scoping mechanism for the C/C++ preprocessor; Bjarne Stroustrup; 2004.
  • N1664 Toward Improved Optimization Opportunities in C++0X; Walter E. Brown, Marc F. Paterno; 2004.

C++ Reading List

List

Via: Andrew Binstock; The C++ Reading List; In Dr. Dobb’s; 2013-05-28.

C++ Reading List C++ Reading List C++ Reading List C++ Reading List C++ Reading List C++ Reading List