1. 23 Aug, 2016 4 commits
    • Heng Hong Lee's avatar
      AsyncSSLSocket getRawBytes fix · 4d37864c
      Heng Hong Lee authored
      Summary:
      While adding logging around our socket and looking into `AsyncSSLSocket` it seems like the data that is actually written into the socket is not correctly attributed.  I
      added logs and printed out what happens on the socket layer, P56563098 in this paste you can see that the `[fishhook]` logs are actually those added in D3698728.
      
      Those are the actual bytes written onto the socket, in the paste, the bytes that are written by the AsyncSocket::bioWrite method are
      the ones that actually get written onto the socket. some of the bytes written into the bio comes from bf_buff.c and bss_mem.c which are not eventually attributed to a
      socket message and will be incorrectly counted when getRawBytesWritten/Read invoked on AsyncSSLSocket.cpp
      
      Unfortunately/Fortunately this issue is not symmetrical and does not manifest in the getRawBytesReceived in AsyncSSLSocket, reading the bio for read bytes
      correctly attributes the actual number of bytes written on the socket. moreover, pulling the asyncsocket data for getRawBytesRead doesnt give the full read bytes on
      wire because SSL_connect and SSL_read dont return the number of bytes they read but return the number of bytes without the TLS bytes used.
      
      siyengar seems like a right person to look at this. so adding him here.
      
      Would love to discuss more about this and am open to iterating more on this solution
      
      Reviewed By: knekritz
      
      Differential Revision: D3698744
      
      fbshipit-source-id: 541aa478778b9607f51db194fcbfe28bd23c737f
      4d37864c
    • Meng Zhang's avatar
      Make it build on Ubuntu 16.04 · 0137d629
      Meng Zhang authored
      Summary:
      include linux/membarrier.h if it is available.
      Closes https://github.com/facebook/folly/pull/455
      
      Reviewed By: lukenels
      
      Differential Revision: D3714952
      
      Pulled By: Orvid
      
      fbshipit-source-id: 8c85756af2cb132152b2182816becfea138f0149
      0137d629
    • Giuseppe Ottaviano's avatar
      Make fbstring::assign() tight, and simplify operator=() and append() · aeef60dd
      Giuseppe Ottaviano authored
      Summary:
      `fbstring::assign()` uses `append()`, which triggers exponential growth, but it's preferable that `assign()` behaves like the `fbstring(const char*, size_t)` constructor, which is tight.
      
      Also rewrite `operator=()` in terms of `assign()`, to avoid duplicating the logic, and refactor the logic of `append()` for the aliasing case so that it uses the same expansion operation as the non-aliasing case.
      
      Reviewed By: luciang
      
      Differential Revision: D3754932
      
      fbshipit-source-id: 5423f2a360b4268b6a05dd0ae9d2fe5bd1eb855d
      aeef60dd
    • Giuseppe Ottaviano's avatar
      Make Malloc.h self-contained again · 89166c82
      Giuseppe Ottaviano authored
      Summary: D3743475 adds to `Malloc.h` a dependency on another folly header, which breaks it when used in stand-alone mode. This diff moves the include to the right `#ifdef` section.
      
      Reviewed By: Gownta
      
      Differential Revision: D3757819
      
      fbshipit-source-id: 71664ca6a3a47b6e4449a4ef603fedf052c5df3b
      89166c82
  2. 22 Aug, 2016 4 commits
    • Christopher Dykes's avatar
      Fixup a reference to detail/FunctionalExcept.cpp · b646787c
      Christopher Dykes authored
      Summary: I missed this reference when I moved it to the portability folder. It is already being compiled at its new location.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3754227
      
      fbshipit-source-id: 357b0c26ddbcefdc7640f6a334150abba90ed711
      b646787c
    • Christopher Dykes's avatar
      Use a constexpr char* under MSVC for the constexpr StringPiece test · 07c7cdee
      Christopher Dykes authored
      Summary: MSVC can't handle the array as a constexpr value, but works fine with the char*.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3705189
      
      fbshipit-source-id: e8208b3f2831a720095641f0e1e72ac63ed845a0
      07c7cdee
    • Christopher Dykes's avatar
      More fixup of the build on Mac for HHVM · 2a0c9d06
      Christopher Dykes authored
      Summary: `std::__throw_bad_alloc()` is defined in `<new>` on OSX, so bring back the `#ifdef` guards that were there previously.
      
      Reviewed By: markw65
      
      Differential Revision: D3749714
      
      fbshipit-source-id: 0338a4cece928fce0b9d33d41c17cfa99a319abe
      2a0c9d06
    • pp__qq's avatar
      fix(FBString): fix bugs · 572543f4
      pp__qq authored
      Summary:
      fix(FBString): compile error on instantiate `basic_fbstring` with a `Storage` that is not `fbstring_core<E>`
      Closes https://github.com/facebook/folly/pull/398
      
      Reviewed By: ot
      
      Differential Revision: D3714957
      
      Pulled By: yfeldblum
      
      fbshipit-source-id: 1c5d2538b674049f7e1872a0b623ec330dc8d7b2
      572543f4
  3. 21 Aug, 2016 3 commits
    • Christopher Dykes's avatar
      Get ObserverManager compiling under MSVC · 7ae5a5e4
      Christopher Dykes authored
      Summary: It only needed a minor tweak, but the change still had to be made :(
      
      Reviewed By: andriigrynenko
      
      Differential Revision: D3745021
      
      fbshipit-source-id: 286c6db706c3571842006537c6b17f506609e51d
      7ae5a5e4
    • Christopher Dykes's avatar
      Fix folly::to<> under MSVC · 1675b895
      Christopher Dykes authored
      Summary: MSVC didn't like the conversion to using `Expected`, and, after `Expected` was fixed to work under MSVC, conv still needs more changes. Specifically MSVC doesn't understand the single-instantiation form of getting the last element, so we have to switch to a tuple-backed version instead, which requires more template instantions, but produces the same performance at runtime.
      
      Reviewed By: ericniebler
      
      Differential Revision: D3744063
      
      fbshipit-source-id: affcab1574c721d8b9529784d7ca2a46233d9935
      1675b895
    • Bi Xue's avatar
      Suggestion of fixing folly::to<std::string>(double/float) performance issue · 10ed79f7
      Bi Xue authored
      Summary:
      When calling folly::to<SomeString>(double), generic implementation will
      firstly reserve 24 (or 25 when negative value) bytes. This will introduce
      a malloc call for most of mainstream string implementation.
      
      But for most cases, a floating point doesn't need 24 (or 25) bytes to
      be converted as a string.
      
      This diff try to introduce a special version which does not do string reserve.
      
      Reviewed By: ericniebler
      
      Differential Revision: D3728171
      
      fbshipit-source-id: d70ead396ad6c8d0df1f542c5516f7534e82cb97
      10ed79f7
  4. 20 Aug, 2016 1 commit
    • Yedidya Feldblum's avatar
      An intro to the upgrade mutex in the Synchronized docs · 3c2fad7c
      Yedidya Feldblum authored
      Summary:
      [Folly] An intro to the upgrade mutex in the `Synchronized` docs.
      
      Describes what the upgrade mutex is. Extends the existing docs which describe `Synchronized` and `LockPtr` interface and behavior in the presence of an upgrade mutex.
      
      Reviewed By: snarkmaster, simpkins
      
      Differential Revision: D3746177
      
      fbshipit-source-id: 68b0570a36cc1f4393d5ccca535efa02752ca11d
      3c2fad7c
  5. 19 Aug, 2016 8 commits
  6. 18 Aug, 2016 4 commits
    • Aravind Anbudurai's avatar
      Support for EPOLLPRI · 2714e5b6
      Aravind Anbudurai authored
      Summary:
      Depends on D3718573 and the other diff to sync tp2 on fbcode after D3718573
      lands.
      
      This adds the PRI flag for using on EPOLLPRI events. The test makes a
      server/client and client a MSG_OOB message to make it appear as a priority
      event.
      
      Masked under a preprocessor directive until libevent upstreams the patch that I
      will send for 2.0
      
      Reviewed By: djwatson
      
      Differential Revision: D3722009
      
      fbshipit-source-id: c15233d4739a38092d11c3026c483c7a9c8e5dac
      2714e5b6
    • Christopher Dykes's avatar
      Fix folly::Expected under MSVC · 96e8ac5b
      Christopher Dykes authored
      Summary:
      There are 3 separate issues that this addresses to get Expected working correctly under MSVC.
      The first is simply that it doesn't like `StrictConjunction`. Switching that to `std::conjunction`, which is part of C++17 and already implemented in MSVC, solves that issue.
      The second is that MSVC was complaining that all members must be initialized in a `constexpr` constructor, but only one of the base classes of `ExpectedStorage` was being initialized, and, as there were no default `constexpr` constructors for the other bases, they couldn't be initialized. This was solved by making the base class's default constructors `constexpr`.
      The last was the most fun, as the simple solutions all resulted in internal compiler errors. MSVC doesn't like SFINAE evaluation in the context of a template type parameter on a static operator defined inline in the class via `friend`. The solution is to simply move the definitions after the class and only include the declarations to be able to mark them as `friend`.
      
      Reviewed By: ericniebler
      
      Differential Revision: D3731833
      
      fbshipit-source-id: ea9244b247b69046866f27cee9fdbd1b2405cafb
      96e8ac5b
    • Dave Watson's avatar
      bitmap search · 060485b6
      Dave Watson authored
      Summary:
      Use a bitmap search to find the next wheel timer tick instead of a linear scan.
      Need to store the current bitmap bit in the individual timeout to support cancellation.
      
      Given the WHEEL_SIZE of 256, this will reduce to 4 ffsl/cmov instructions.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3637116
      
      fbshipit-source-id: 1a37e19a5342604ec81735eaf85b72b6f673ea1e
      060485b6
    • Dave Watson's avatar
      remove constant tick · 9880573b
      Dave Watson authored
      Summary:
      Preciesly calculate the next tick.  Currently only calculates the tick based on the lowest level of wheel timer, so it will still tick at least every WHEEL_SIZE intervals.
      
      Currently the tick calculation is a linear scan over all the buckets, the next diff will optimize this.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3637096
      
      fbshipit-source-id: 53dd596a2085c05c657cccbc7efba267bbd086a6
      9880573b
  7. 17 Aug, 2016 8 commits
    • Christopher Dykes's avatar
      Add a pair of util functions for getting and setting the BIO fd · 7e7a7df7
      Christopher Dykes authored
      Summary: Because we need to translate them between sockets and file descriptors when we're on Windows.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3724802
      
      fbshipit-source-id: 07fff6e1bec7b9b90e0d39fd98441466a746b7f7
      7e7a7df7
    • Phil Willoughby's avatar
      Fix folly contbuild · 79d7f0f5
      Phil Willoughby authored
      Summary: Started failing when we turned on unused-result errors.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3728565
      
      fbshipit-source-id: b12aee8d99f725f1a1cfaf30e9afa66bd05f7989
      79d7f0f5
    • Michael Lee's avatar
      Move the type_traits portability header into its own portability header · 5c7e0242
      Michael Lee authored
      Summary: Split up the big, all-inclusive Portability header a bit
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3723253
      
      fbshipit-source-id: a91c38775825626f3c13853ac8168daa078a169a
      5c7e0242
    • Petr Lapukhov's avatar
      Allow accept callbacks to be short-circuited in primary event-base · 9b8488e8
      Petr Lapukhov authored
      Summary:
      It looks like we were effectively avoiding short-circuiting callbacks submitted for execution in primary event-base (evb == nulptr). The check was there, but it was never effective, since on `addAcceptCallback` we would mask the `nullptr` with our event base pointer.
      
      I see two ways to fix that: either modify the check
      
          if (info->eventBase == nullptr) { ...} on line 834
      
      to compare to the presently attached event base, or store `eventBase = nullptr` into callbacks_ list (CallbackInfo struct). The second approach requires more changes (implemented here) but allows the caller to still submit callbacks for execution via notification queue event in primary event base by supplying eventBase parameter != nullptr in addAcceptCallback. I therefore chose the second approach.
      
      The existing unit-tests needed modification to avoid using the "broken" nullptr semantics (most cases were assuming it would be using notification queue signaling). I quickly looked at fbcode, and it looks like we only have a few cases of addAcceptCallback() with nullptr, the unit-tests for those are passing.
      
      NOTE: The removeAcceptCallback() semantics is different with regards to eventBase; nullptr here means "scan all callbacks regardless of event-base they belong to".
      
      Reviewed By: djwatson
      
      Differential Revision: D3714697
      
      fbshipit-source-id: 2362bcff86a7e0604914b1cb7f1471fe4d03e78e
      9b8488e8
    • Subodh Iyengar's avatar
      Invoking correct callback during TFO fallback · 12ace861
      Subodh Iyengar authored
      Summary:
      If we fallback from SSL to TFO and the connection times
      out, invokeConnectSuccess tries to deliver the connectError,
      however we've already delivered the connect callback to the user.
      
      This is bad because we have no way of reporting an error back.
      This changes it so that when using SSL and we're scheduling a timeout
      when we're falling back, we will schedule a timeout of our own which
      will invoke AsyncSSLSocket's timeoutExpired. This will return a handshakeError
      instead to the client.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3708699
      
      fbshipit-source-id: 41fe668f00972c0875bb0318c6a6de863d3ab8f9
      12ace861
    • Subodh Iyengar's avatar
      Fix ssl timeouts during TFO · 457fa717
      Subodh Iyengar authored
      Summary:
      Handle handshake timestamps and timeouts when TFO
      is used.
      
      If we fallback from TFO to connects, we should unset
      the handshake timeout.
      
      When we restart the handshake, we should reset the handshake
      timeout and also reset the timestamps of the connection.
      
      Reviewed By: yfeldblum, djwatson
      
      Differential Revision: D3708660
      
      fbshipit-source-id: 960030ca14d9f1cc8cb83059491ceffe6ba8f2ed
      457fa717
    • Subodh Iyengar's avatar
      Simplify TFO write path · ff508994
      Subodh Iyengar authored
      Summary:
      We currently call handleInitialReadWrite.
      The reason for this is that if the read callback
      was set before TFO was done with connecting, then
      we need to call handleinitialreadwrite to setup the
      read callback similar to how connect invokes handleInitialReadWrite
      after it's done.
      
      However handleinitalreadwrite may also call handleWrite
      if writeReqHead_ is non null.
      Practically this will not happen since TFO will happen on
      the first write only where writeReqHead_ will be null.
      
      The current code path though is a little bit complicated.
      This simplfies the code so that we dont need to potentially
      call handleWrite within a write call.
      
      We schedule the initial readwrite call asynchrously.
      The reason for this is that handleReadWrite can actually fail if updating
      events fails. This might cause weird state issues once it returns and we
      have no mechanism of processing it.
      
      Reviewed By: djwatson
      
      Differential Revision: D3695925
      
      fbshipit-source-id: 72e19a9e1802caa14e872e05a5cd9bf4e34c5e7d
      ff508994
    • Andrii Grynenko's avatar
      folly::Observer · 2ed41baf
      Andrii Grynenko authored
      Summary:
      This is a basic implementation of a new Observer API. I mostly see this being useful as a replacement for various configuration subscription APIs (Configerator, SMC etc.)
      
      The library provides an Observer primitive. At any time user can take a Snapshot of data in the Observer (which is a view with the most recent version of the data). New Observer can be created by providing a generator functor. Such Observer mays depend on other Observers and its generator functor is re-run automatically every time, when at least one of the dependencies are updated. The implementation may also ignore intermediate updates and will only use the most recent version of other Observers, when re-computing Observer data.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3481231
      
      fbshipit-source-id: 96c165f8081cff0141d5814ec2bc88adeb2e1e74
      2ed41baf
  8. 16 Aug, 2016 8 commits
    • Michael Lee's avatar
      Split up FibersTest into test and Benchmark. · 034d1bd9
      Michael Lee authored
      Summary: And clean up the extra main.cpp
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3717445
      
      fbshipit-source-id: 2a5d554824c454b5339514d0d4ca7ae9474abdb9
      034d1bd9
    • Christopher Dykes's avatar
      Use std::is_nothrow_swappable under MSVC · 30c4c286
      Christopher Dykes authored
      Summary:
      The current implementation didn't work for MSVC, as it tries to evaluate `noexcept` expressions in base class lists before the template is instantiated.
      `std::is_nothrow_swappable` is coming in C++17, and MSVC already has it, so use it instead.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D3724399
      
      fbshipit-source-id: 7927584618a7870824b2e7242fcae562647f4ef4
      30c4c286
    • Eric Niebler's avatar
      Use folly::Expected to implement folly::tryTo, a non-throwing variant of folly::to · 4da4f331
      Eric Niebler authored
      Summary:
      This change adds a non-throwing interface for folly::to<T>: tryTo<T>, which
      returns an Expected<T, ConversionCode>.
      
      Here is how the non-throwing interface compares to the regular interface in
      terms of performance. On the successful path, there's generally not much
      difference between using the throwing and non-throwing interfaces. For the
      error path, tryTo<> is about three orders of magnitude faster than to<>.
      
      Reviewed By: mhx
      
      Differential Revision: D3720512
      
      fbshipit-source-id: dadb8db1b7d7ad8d3e80c1cc69c0480169f9217a
      4da4f331
    • Christopher Dykes's avatar
      Use a base hook rather than a member hook for EventBase callbacks · 5d242d14
      Christopher Dykes authored
      Summary:
      Using boost intrusive member hooks in complex inheritence heirarchies under MSVC is [unsupported](http://www.boost.org/doc/libs/1_61_0/doc/html/intrusive/usage.html#intrusive.usage.usage_member_hook), and, in combination with a [regression in VS 2015 Update 2](https://connect.microsoft.com/VisualStudio/Feedback/Details/2555433) that is not fixed in Update 3, the async socket tests that use this compile under MSVC, but fail at runtime because the hook pointer ends up pointing at the node's vtable rather than the hook.
      This just works around the issue by using a base hook instead.
      
      Reviewed By: djwatson
      
      Differential Revision: D3724521
      
      fbshipit-source-id: a55e36a2e79a15d9943b6090f6194fd480e19074
      5d242d14
    • Christopher Dykes's avatar
      Disable SSL socket cache tests if cache isn't available · cf27a11e
      Christopher Dykes authored
      Summary: These tests will always fail if we're building against a version of OpenSSL that doesn't have the extension.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D3724893
      
      fbshipit-source-id: a093d62b9b5ea8239b5d52a66da2a833911b4f47
      cf27a11e
    • Nathan Bronson's avatar
      explicit return types in Partial to work around gcc bug · ec3d4073
      Nathan Bronson authored
      Summary: Workaround for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70983
      
      Reviewed By: mhx, spacedentist
      
      Differential Revision: D3724410
      
      fbshipit-source-id: 692b1c1f49211a4170900505339794f09cec2369
      ec3d4073
    • Kyle Nekritz's avatar
      Fix extension length counter in client hello parsing. · 930cf162
      Kyle Nekritz authored
      Summary: Orvid noticed this was always throwing on a properly formated client hello, since the sig algs extension length isn't subtracted from the counter. This doesn't actually affect any behavior (except possibly a slight perf hit), but is pretty clowny.
      
      Reviewed By: anirudhvr
      
      Differential Revision: D3722887
      
      fbshipit-source-id: 579993caac96da24fb567ab977b09fca519750a0
      930cf162
    • Sven Over's avatar
      Introducing folly::partial · 6a287baa
      Sven Over authored
      Summary:
      This diff adds folly::partial, a function to partially apply
      a set of zero or more arguments to a callable. It is similar
      to Python's `functools.partial`.
      
      `folly::partial` takes a callable object and additional
      arguments and returns a callable with those additional
      arguments bound to it. When the returned callable is invoked
      with additional arguments, those are appended to the set of
      arguments that were passed to `folly::partial`.
      
      It is similar to `std::bind`, but more simple as it does not
      support reordering of parameters, but also does not
      require you to know how many arguments will be
      eventually passed to the callable. Also, `std::bind`
      does not support move-only types being passed by-value.
      `folly::partial` does:
      
        void someFunc(std::unique_ptr<Foo>, int);
        auto p = folly::partial(&someFunc, std::move(foo_unique_ptr));
        ...
        std::move(p)(42);
      
      Reviewed By: mhx
      
      Differential Revision: D3252539
      
      fbshipit-source-id: ee093771ac732fa70052b9908dcb75e90ba80efe
      6a287baa