onError callbacks

Summary:
We've discussed these a bunch and here they are. I stole a bunch of Hannes' magic from https://www.facebook.com/groups/715931878455430/permalink/772854686096482/ to make this easier

Test Plan: added lots of unit tests

Reviewed By: hans@fb.com

Subscribers: fugalh, folly-diffs@, hannesr

FB internal diff: D1748418

Signature: t1:1748418:1418945606:e14c7d6a31245e222bc6a0d259d0e2b9ddd5a830
Move TAsyncTransport to folly as AsyncTransportWrapper

Summary:
This temporary class will be useful to cut dependencies on thrift
while (roughly) maintaining the old interface.

Fixup various test classes that depend on the interface.  Next diff will be to cut fbthrift dep in proxygen/mcrouter

Test Plan: unit tests, jenkins

Reviewed By: hans@fb.com

Subscribers: fbcode-common-diffs@, andrewcox, alandau, bmatheny, alikhtarov, mshneer, trunkagent, doug, njormrod, folly-diffs@, davejwatson

FB internal diff: D1696094

Signature: t1:1696094:1418762312:6028815cce2845ac5f8e754132a038fabf5fd957
Remove unnecessary constraint from Range subpiece constructor

Summary:
D1746899 enforced the constraint (previously in a comment) on the
constructor `Range(const Range&, size_t, size_t)` that `Iter` is a
`const char*`. There is however no reason for this constraint.

This patch generalizes and simplifies the constructor, and since it
has the same semantics as `subpiece`, the latter is implemented in
terms of the constructor.

Test Plan:
fbconfig -r folly && fbmake runtests_opt

Reviewed By: soren@fb.com

Subscribers: trunkagent, folly-diffs@

FB internal diff: D1747958

Signature: t1:1747958:1418930360:fcd6beeda34e64ec8a34b9491a57674ae2265596
Fixed folly::AtomicHashMap::iterator not advancing past empty submaps

Summary: A potential "real life" scenario that maybe can hit this bug is if we erase almost all elements and then iterate over the whole map.

Test Plan: Added a test for it.

Reviewed By: mwilliams@fb.com

Subscribers: folly-diffs@, lovro

FB internal diff: D1751455

Tasks: 5866368

Signature: t1:1751455:1419016611:b44c41d348f54397844460cb38002ad0d9704972
Add comment explaining that RWTicketSpinLock<..., true> is not reentrant

Test Plan: no, it's a comment

Reviewed By: zanfur@fb.com

Subscribers: folly-diffs@

FB internal diff: D1752850

Tasks: 5823969

Signature: t1:1752850:1419043661:673c68c0daad28b3fde9709e767b528b0dec8ad1
Various Dwarf::Path fixes

Summary:
- Allow both `baseDir` and `subDir` to be empty.  This can happen
if DW_AT_comp_dir is `.` and gets simplified to the empty string.
(The DWARF standard doesn't appear to disallow relative dirs here,
but I couldn't find anthing definitive).
- Fix `./` prefix  stripping to avoid making paths like `.///hello` absolute.
- Fix `/` suffix stripping to avoid making the root dir reference (`/`) empty.
- Do `baseDir` and `subDir` swapping after simplification.

Test Plan: Added unittests.

Reviewed By: njormrod@fb.com

Subscribers: trunkagent, sdwilsh, folly-diffs@

FB internal diff: D1747978

Signature: t1:1747978:1419014942:87f14cb31b8c19b524d7a95b14d63cf5661a8634
Print linux TID while crashing

Summary:
For servers using GLOG, all thread ID are get from gettid system call. So it
is very useful if we print this ID so during debugging I can find the log
of crashing thread.

I'm not sure who should review this diff. Just found you guys from previous
diffs touched this file :)

Test Plan:
See the crash log.
*** Aborted at 1419029404 (Unix time, try 'date -d @1419029404') ***
*** Signal 11 (SIGSEGV) (0x18) received by PID 18852 (pthread TID 0x7f52a1fff700) (linux TID 27908), stack trace: ***

Reviewed By: tudorb@fb.com

Subscribers: seanc, folly-diffs@

FB internal diff: D1752301

Signature: t1:1752301:1419032887:e43c2ace6914e54812149a8b8e84eaffaf42a09c
Allow conversion from StringPiece to StringPiece

Summary: Allow conversion from folly::StringPiece to folly::StringPiece

Test Plan: - fbconfig -r folly && fbmake runtests

Reviewed By: mpawlowski@fb.com

Subscribers: folly-diffs@

FB internal diff: D1752609

Signature: t1:1752609:1419037172:04846f658901306b53fb60c9eafbdf0f4d4d7005
Bring fbstring::operator+ to date with C++11

Summary: Some overloads, particularly with rvalue references, were missing. Also this fixes https://our.intern.facebook.com/intern/tasks/?t=5849579

Test Plan: unittests

Reviewed By: simpkins@fb.com

Subscribers: trunkagent, las, net-systems@, njormrod, folly-diffs@

FB internal diff: D1746319

Tasks: 5849579

Signature: t1:1746319:1418875228:febb965cf52710a5e76b7c1cce5aec601086ad90
folly: AsyncServerSocket::getAddress: prefer IPv6

Summary: Can't connect from ipv6-only cluster to ipv4/ipv6 service which uses different ports.

Test Plan:
```
./fastcopy_server --dir . &

# netstat -atnlp | grep LISTEN | grep fastc
tcp        0      0 0.0.0.0:65478               0.0.0.0:*                   LISTEN      9348/./fastcopy_ser
tcp        0      0 :::52793                    :::*                        LISTEN      9348/./fastcopy_ser
```

Reviewed By: philipp@fb.com, sdoroshenko@fb.com

Subscribers: ps, bmatheny, folly-diffs@

FB internal diff: D1752846

Tasks: 5868818

Signature: t1:1752846:1419043494:7cc0646882249f17258ade5ce7ae5619b13148a0
folly::AtomicHashMap: fixed race between erase() and find()

Summary: advancePastEmpty() was called for all created iterators. It only makes sense for begin(). For find() it's harmful: find() shouldn't return an iterator to the next element if the key was removed. I suspect that the same race condition was possible for insert(), but I haven't tried to reproduce it.

Test Plan: Added a test for it. It fails without these changes.

Reviewed By: delong.j@fb.com

Subscribers: folly-diffs@, lovro

FB internal diff: D1751280

Tasks: 5841499

Signature: t1:1751280:1419107193:71311ff68d92d0a4dcf1941dacdfdc23c25255cc
Fix Dwarf path handling to fix broken test

Summary:
Simplify the logic slightly to better handle joining paths.
This makes DwarfTest.cpp pass.

Test Plan: runtests

Reviewed By: njormrod@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1756036

Tasks: 5871014

Signature: t1:1756036:1419359254:123cc508b8836ea0b1485abe361b1c158538aa08
Fix incorrect 'test' statement in unit test

Summary:
The 'test' command uses one equal sign for string equality, not
two.  bash apparently is okay with two, but zsh isn't, causing this test
to pass if your shell was bash and fail if it was zsh.  The test now
passes with bash, bash in sh mode, zsh, and even dash.

Test Plan:
runtests, also, these pass (zsh failed before):

SHELL=/bin/bash _build/dbg/folly/test/subprocess_test
SHELL=/bin/sh _build/dbg/folly/test/subprocess_test
SHELL=/bin/zsh _build/dbg/folly/test/subprocess_test
SHELL=/bin/dash _build/dbg/folly/test/subprocess_test

Reviewed By: njormrod@fb.com

Subscribers: lins, anca, folly-diffs@

FB internal diff: D1756090

Signature: t1:1756090:1419360674:8576e61a6e0ee102612c5eae0e1fbd79cc397bfa
Allow unregistering connect callback in AsyncSocket

Summary:
Sometimes when the socket is destroyed from a destructor, we wouldn't
want further callbacks on shutdown. We can unregister the readCallback_
by calling setReadCB(nullptr), but if the state is CONNECTING, we can
still get connectErr() callback. I found an ASAN trace (https://phabricator.fb.com/P18837265)
that turned out to be because of this inability to cancel this callback.
This provides a way to unregister the connect callback as well.

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: afrind@fb.com

Subscribers: folly-diffs@

FB internal diff: D1751778

Tasks: 5852935

Signature: t1:1751778:1419363638:26967c2d4fc5819e4d65ae706d217a954dfd784f
Revert "folly: AsyncServerSocket::getAddress: prefer IPv6"

Summary: This reverts commit fc83e983e2376bccc80dc4b21890e3a41dbc211f.

Test Plan: none

Reviewed By: lucian@fb.com, robot9@fb.com

Subscribers: ps, bmatheny, folly-diffs@

FB internal diff: D1756753

Tasks: 5883894, 5886688

Signature: t1:1756753:1419374764:977160379cfa49530babb38022b9d4cc80573a7d
make futexWaitUntil tolerant of invalid time_point-s

Summary:
futexWaitUntil could generate an invalid timespec when presented
with a time_point from before the epoch, which resulted in an EINVAL from
the futex syscall.  Debug builds crashed on this unexpected return value,
while release builds soldiered on.  This path happened to be exercised
by the unit test.  This diff fixes the unintentional deadline overflow
in the test, adds explicit testing of overflow behavior, and makes
futexWaitUntil handle invalid time_points in a sensible manner.

Test Plan:
1. new unit tests
2. fbmake runtests_dbg

Reviewed By: mssarang@fb.com

Subscribers: strager, njormrod, folly-diffs@

FB internal diff: D1747972

Tasks: 5853949

Signature: t1:1747972:1419382193:862c193a13428d96acb33c85f962f59203661f40
HHWheelTimer::cancelAll

Summary: Provide a way to massacre outstanding timers.

Test Plan: new test, and using in wangle (different diff)

Reviewed By: davejwatson@fb.com

Subscribers: jsedgwick, exa, folly-diffs@

FB internal diff: D1753866

Tasks: 4548494

Signature: t1:1753866:1419361846:58ff6ca4d01b0d546495b032b454c8bf0fdb0277
(wangle) Timeouts basic

Summary:
Add basic timeout functionality. This adds `futures::sleep` which makes an async Future that finishes after the given duration, and `Future::get` which blocks on the result and takes an optional timeout.

Introducing the folly::wangle::futures namespace (soon to be just folly::futures) which will hold our wangle utility functions, the things that live in the Future object in Twitter's scala code. We'll probably move when* and wait-ish methods in here too, and perhaps alias makeFuture-ish methods too, though James has me mostly convinced not to deprecate them at the folly::wangle level (because they're basically Future constructors and Future lives at folly::wangle)

`Future::delayed` after Twitter's helper of the same name

Test Plan: new and old unit tests

Reviewed By: davejwatson@fb.com

Subscribers: trunkagent, fugalh, exa, folly-diffs@

FB internal diff: D1748894

Tasks: 4548494

Signature: t1:1748894:1419363496:1f4a62ec8455989c1fcce845695ace1d01c101c8
(wangle) fix Makefile.am

Summary: Add some forgotten header and cpp files to `Makefile.am` for OSS build of folly.

Test Plan: jenkins

Reviewed By: ajitb@fb.com

Subscribers: exa, folly-diffs@

FB internal diff: D1758318

Tasks: 5880251

Signature: t1:1758318:1419639812:47f527fdb2b3d2c49e7557b4176c6ab2478091ae
Fix case of ThreadWheelTimekeeper.cpp in Makefile.am

Test Plan: jenkins

Reviewed By: ajitb@fb.com

Subscribers: exa, folly-diffs@

FB internal diff: D1758358

Tasks: 5880251

Signature: t1:1758358:1419640865:c9e9ea5922a602c44042c358777067e025800e6e