Break Observer interface in to async and server sections

Summary: Preparing to move some thrift/lib/cpp/async/ code to folly.  This should remove the thrift-specific observer parts from async/

@override-unit-failures

Test Plan: contbuild

Canary URL: https://our.intern.facebook.com/intern/feedtools/mycanary?id=davejwatson_20140310-133730_D1194848_392e4199b7726b1b60a6db1958cda5f7a26811b8_

Reviewed By: haijunz@fb.com

FB internal diff: D1194848
RelativePtr test fix

Summary: This is weird, I thought local variable ordering was fixed... I guess I was wrong.

Test Plan: Run this test.

Reviewed By: pgriess@fb.com

FB internal diff: D1213027
Add enum class to TSPEC array

Summary: For enums, this adds the enum class so external tools can query and validate enums
@override-unit-failures

Test Plan: build, regenerate thrift files, confirm TSPEC is structured properly

Reviewed By: alandau@fb.com

FB internal diff: D1214173
Cpp generator changes for recursive types

Summary:
Recursive type support for cpp.

For cpp added a cpp.ref annotation.  Users will have to make some recursive types use references to avoid a struct containing itself.  Also had to explicitly check for null references when reading/writing, so we know to set the reference to null.

Test Plan: Added some unittests

Reviewed By: andrewcox@fb.com

FB internal diff: D799611
Codel algorithm in ThreadManager

Summary:
Codel implementation for ThreadManager

Also some minor changes to generated code to send expired execptions back to clients

http://en.wikipedia.org/wiki/CoDel

Test Plan:
fbconfig thirft/perf/cpp
fbmake opt

_bin/thrift/perf/cpp/ThriftServer --num_threads=1
_bin/thrift/perf/cpp/loadgen -weight_burn=1 -async --burn_avg=100 -num_threads=10 -async_ops=10

Shows some tasks expiring from codel.  Increasming burn_avg or async_ops shows it working well up to a point, eventually task timeouts take over - codel can't expire fast enough in some cases.

loadtest.py shows reasonable results, although some tests are now failing since we are getting codel failures - need to work out the issues there.  No perf problems, just tuning the framework to expect expires

Reviewed By: andrewcox@fb.com

FB internal diff: D1053590
Fix readFromJson bug

Summary:
Thrift didn't deserialize a field of type map<X,anything> if X
was a typedef.

Test Plan: added unittest

Reviewed By: davejwatson@fb.com

FB internal diff: D1209311
Create an observer interface for ThreadManager

Summary: Adds a static observer for all thread managers for doing perf recording. By default, perf recording is now *on*, and will send to the observer if one exists. Builds on top of D1194700

Test Plan: new unit test, also perf results looked fine.

Reviewed By: davejwatson@fb.com

FB internal diff: D1196970
More verbose kInit() error message

Summary:
1. Added Krb5Keytab::getName() method that returns keytab name.
2. If kInit() fails, error message will suggest to check keytab location
or run kinit.
@override-unit-failures

Test Plan: 1. Got the modified error mesasge.

Reviewed By: mhorowitz@fb.com

FB internal diff: D1212710
change util uses to std::chrono

Summary: Breaks the dependency between thrift/lib/cpp/async and thrift/lib/cpp/util.  These are all easy enough to do with std::chrono now anyway

Test Plan: contbuild

Reviewed By: andrewcox@fb.com

FB internal diff: D1194887
Fix TAsyncSocketTest.ConnectTimeout

Summary:
- It appears that dns.any is now outright rejecting connection attempts
to port 65535. Instead hit 8.8.8.8, one of the GoogleDNS anycast
addresses. This should be inaccessible from all L3 prod clusters, as
they require use of fwdproxy to get out to the internet. I believe all
devservers are in such clusters these days.

Test Plan: - Ran unit tests

Reviewed By: simpkins@fb.com

FB internal diff: D1209595
Add TAsyncSocketFactory::make(int fd)

Summary:
- Add TAsyncSocketFactory::make(int fd) method to allow for creating
sockets from already-connected sockets
- For TAsyncSSLSocketTransportFactory, add a setServerMode() method to
indicate whether server or client-mode sockets should be created. This
is necessary because handshaking expectations are not symmetric.

Test Plan: - fbconfig -r thrift/lib/cpp && fbmake runtests

Reviewed By: rajat@fb.com

FB internal diff: D1216544
Move thrift/lib/cpp/async to folly.

Summary:
Move the minimum amount of stuff and still have everything compile.  Would like to move TAsyncSocket/ServerSocket/SSL/UDP eventually, but not this round.

thrift async is used very widely now: thrift, proxygen, newer mysql async interface, even trying it out in memcache.  A common complaint is that it doesn't get wide enough notice under thrift/, so let's move it to folly/.  After moving TAsyncSocket, both HHVM and proxygen could avoid a dep on thrift as well.

Changes:
* mv files to folly/io/async
* remove 'T' prefix on classes/filenames
* change namespace to 'folly'
* remove any thrift references.

Tried this before in D470080, this time doesn't attempt to abstract libevent

@override-unit-failures

Test Plan:
fbconfig -r thrift; fbmake dev.
Will iterate on any other contbuild failures

Reviewed By: pgriess@fb.com

FB internal diff: D1195393
Rename /var/security_kill_switch to /var/thrift_security

Summary: We want to put more stuff in this dir, so give it a more generic name

Test Plan: fbconfig, fbmake, twdeploy.lpar validate

Reviewed By: acampi@fb.com

FB internal diff: D1218706
Add HandshakeCallback::handshakeVerify()

Summary:
- Add a handshakeVerify() callback to the TAsyncSSLSocket
HandshakeCallback class. This will not be invoked unless sslConnect()
or sslAccept() are invoked with verify=true; the default is
verify=false, which retains API compatability.
- Discovered that SSL certificates being used in tests are expired.
Generated new certificates and put them in the ssl/ directory along
with instructions for re-generating them.

Test Plan: - Unit tests

Reviewed By: afrind@fb.com

FB internal diff: D1216572
Make more TAsync(SSL)?Socket methods virtual

Summary:
- Make the TAsyncSocket::getFd() and detachFd() virtual
- Make TAsyncSSLSocket::sslConnect() and sslAccept() virtual
- Do all of this so that we can mock out behavior of these classes;
udpate mocks accordingly

Test Plan: - fbconfig -r thrift/lib/cpp && fbmake runtests

Reviewed By: davejwatson@fb.com

FB internal diff: D1216554
Unbreak Frozen

Summary:
since D1163100 was pushed my project using Frozen fails to compile with:

```
from syseng/bind10/hook_lib/Cache.cpp:4:
./thrift/lib/cpp/Frozen.h:893:16: error: 'unordered_map' is not a member of 'std'
./thrift/lib/cpp/Frozen.h:893:16: error: 'unordered_map' is not a member of 'std'
./thrift/lib/cpp/Frozen.h:893:39: error: template argument 1 is invalid
```

This is probably because you forgot to `#include <unordered_map>`

Test Plan: compiled my project and it works

Reviewed By: tjackson@fb.com

FB internal diff: D1218866

Blame Revision: D1163100
Generate mock friendly functions for cpp and cpp2.

Summary:
Most mock frameworks work off the basis that the real object they are mocking has virtual methods. Our generated service client code for async calls add send_* and recv_* functions. These weren't virtual so it was really hard to mock.

Also for cpp2 the recv_* functions were static which are also hard to mock. This adds a 2nd method that is public virtual that can be overridden by mock objects.

Test Plan: fbmake runtests

Reviewed By: davejwatson@fb.com

FB internal diff: D1216619
Fix compilation error on arm

Summary:
We build on 64 bit platforms where 0L is a 64 bit integer, but that
isn't the case on our arm android builds. Thus this was complaining
during compilation that there is not max(int32, int64), only template<T>
max(T& lhs, T& rhs);

Test Plan: compiled

Reviewed By: davejwatson@fb.com

Blame Rev:
www -> fbcode php merge

Summary:
There was a request for php changes in fbthrift :https://github.com/facebook/fbthrift/issues/6

This merges back all our changes from www repo.

* added back include_once lines
* looks like some minor facebook hphp specific feature creap, like sprintf, stubbed out
* TType and TMessageType are missing??? Added back.

Otherwise changes seem reasonable.

Test Plan:
fbconfig -r thrift/test:test_server
_bin/thrift/test/test_server

php thrift/test/php/TestClient.php

Works

Reviewed By: ckwalsh@fb.com

FB internal diff: D1216644
speedup TCompactProtocolT::readVarint64

Summary: Unroll varint decoding (adopted `folly/Varint.h` version, benchmarks show it is ~2x faster)

Test Plan:
fbconfig -r thrift/lib/cpp && fbmake runtests_opt -j32

deployed to test posts unicorn tier, observed
`apache::thrift::protocol::TCompactProtocolT<apache::thrift::transport::TBufferBase>::readVarint64(long&)`
is now ~10% faster

Reviewed By: davejwatson@fb.com

FB internal diff: D1223051