1. 15 Dec, 2015 4 commits
    • Lovro Puzar's avatar
      Support gzip in folly/io:compression · f05cdbc1
      Lovro Puzar authored
      Summary: gzip files can be easier to work with operationally than raw zlib thanks to gzip+gunzip.  zlib supports adding/stripping the gzip header; expose that through a new CodecType.
      
      Reviewed By: chipturner
      
      Differential Revision: D2759554
      
      fb-gh-sync-id: 67e0f5f88e087d363db1c349cabb909fb3f00417
      f05cdbc1
    • Neel Goyal's avatar
      Update SSLContext to use folly::Random and discrete_distribution · fbb8a926
      Neel Goyal authored
      Summary:
      Change next pick logic to use `std::discrete_distribution`.  Use folly::Random::DefaultGenerator as the generator.
      Update the TARGETS to have sslcontext depend on random (which was the build break in D2741855)
      
      Reviewed By: siyengar
      
      Differential Revision: D2749166
      
      fb-gh-sync-id: 7a6b400173b1e8c69a961f9e75e97d4777d5467a
      fbb8a926
    • Yang Chi's avatar
      Add a per-socket buffer callback · 4a46ffa2
      Yang Chi authored
      Summary: this is way simpler than D2623385 + D2709121. There will be a followup diff to clean the existing per-write call BufferCallback. The new one is on per-socket basis, much straightforward. I will only setup this in HTTPUpstreamSession.
      
      Reviewed By: afrind
      
      Differential Revision: D2723493
      
      fb-gh-sync-id: 6b1c21a719281b9693330b6a4074f7149d7c342a
      4a46ffa2
    • Yang Chi's avatar
      Remove per-write buffer callback from AsyncSocket · 76fcf389
      Yang Chi authored
      Summary: Remove per-write buffer callback from AsyncSocket
      
      Reviewed By: afrind
      
      Differential Revision: D2733142
      
      fb-gh-sync-id: 91214a8c833bbd479bf049c2bb72d660e0c30f50
      76fcf389
  2. 11 Dec, 2015 3 commits
    • Louis Brandy's avatar
      folly::dynamic::operator= for std::initializer_list · 34de70e2
      Louis Brandy authored
      Summary:
      If we're going to have a constructor for it, we should have operator=.
      
      Otherwise, gcc-4.9 goes via the copy constructor effectively "ignoring" the attempted nesting for e.g..
      
      ```
      d = { other_dynamic };  // Should be ARRAY containing dynamic
      ```
      
      NOTE: this only fixes gcc-4.9, there's still issues in clang.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2745180
      
      fb-gh-sync-id: 667787c788fc7c131d8a34c608c355f5b875be50
      34de70e2
    • Andrii Grynenko's avatar
      Fix RefCountTest and RCURefCount race · bf8a9074
      Andrii Grynenko authored
      Reviewed By: alikhtarov
      
      Differential Revision: D2741459
      
      fb-gh-sync-id: c4bd068cf735ae25364edba40960096fb35e8c43
      bf8a9074
    • Philip Pronin's avatar
      setup signal handler with SA_ONSTACK · dee3186e
      Philip Pronin authored
      Summary:
      By default signal handlers are run on the signaled thread's stack.
      In case of stack overflow running the `SIGSEGV` signal handler on
      the same stack leads to another `SIGSEGV` and crashes the program
      Use `SA_ONSTACK`, so alternate stack is used (only if configured via
      `sigaltstack`).
      
      Reviewed By: luciang
      
      Differential Revision: D2747021
      
      fb-gh-sync-id: 48388acd6147e2919412ec32acfca1ca76f22a16
      dee3186e
  3. 10 Dec, 2015 6 commits
    • Yedidya Feldblum's avatar
      Use SharedMutex as the default mutex type in Synchronized · d8ebd43d
      Yedidya Feldblum authored
      Summary:
      [Folly] Use `SharedMutex` as the default mutex type in `Synchronized`.
      
      `folly::SharedMutex` is, overall, a faster mutex than `boost::shared_mutex`. Let's upgrade.
      
      Reviewed By: nbronson
      
      Differential Revision: D2743132
      
      fb-gh-sync-id: e36881495e8e1002cd481607e05e555c5da19b9a
      d8ebd43d
    • Neel Goyal's avatar
      D2741855 broke my wangle. Reverting · 17d04308
      Neel Goyal authored
      Summary: Revert D2741855
      
      Reviewed By: mzlee
      
      Differential Revision: D2744015
      
      fb-gh-sync-id: b1e9b0a5ab95cb988d2b5c08c86139452b092465
      17d04308
    • Barney Moss's avatar
      Unit test showing array assignment problem on gcc 4.9 · 97c7b417
      Barney Moss authored
      Summary: Unit test showing array assignment problem on gcc 4.9
      
      Reviewed By: lbrandy
      
      Differential Revision: D2739900
      
      fb-gh-sync-id: 6b0fde956672b8248fbd4e620fd112195c45c646
      97c7b417
    • Andrii Grynenko's avatar
      Add ReadMostlySharedPtr and TLRefCount to Makefile.am · 91499a64
      Andrii Grynenko authored
      Reviewed By: pavlo-fb
      
      Differential Revision: D2743230
      
      fb-gh-sync-id: 4a52d1758a43fd103318bbe0913776340eaa6af7
      91499a64
    • Arjen Roodselaar's avatar
      Fix automake build · acd1f142
      Arjen Roodselaar authored
      Summary: There is slight drift in external deps between the TARGETS and automake files, keeping tests from linking in the 'make check' step when building folly outside of fbcode.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2740482
      
      fb-gh-sync-id: ae6243f9bb112a7d2680017b3d577a1f23ef4f60
      acd1f142
    • Neel Goyal's avatar
      Update SSLContext to use discrete_distribution · 92c9ccb6
      Neel Goyal authored
      Summary: Update the protocol pick logic to use discrete_distribution
      
      Reviewed By: siyengar
      
      Differential Revision: D2741855
      
      fb-gh-sync-id: 244bd087124a7a9584a1108fe8f8150093275878
      92c9ccb6
  4. 09 Dec, 2015 3 commits
    • Andrii Grynenko's avatar
      Switch folly::Singleton to ReadMostlySharedPtr · 71c140ed
      Andrii Grynenko authored
      Summary:
      This also introduces a new try_get_fast() API which returns ReadMostlySharedPtr.
      We should eventually migrate all users onto this API.
      
      Reviewed By: elsteveogrande
      
      Differential Revision: D2706745
      
      fb-gh-sync-id: d558d705f431fc6147334c188fd0c6156644ba5c
      71c140ed
    • Alan Frindell's avatar
      Add support for ALPN · 7e6064c6
      Alan Frindell authored
      Summary: With openssl-1.0.2 and later add support for ALPN.  Clients can request NPN only, but the default is to support either (client will send ALPN list, server will send NPN advertisement if ALPN is not negotiated).
      
      Reviewed By: siyengar
      
      Differential Revision: D2710441
      
      fb-gh-sync-id: a8efe69e1869bbecb4ed9e0a513448fcfdb21ca6
      7e6064c6
    • Shijin Kong's avatar
      notification queue read -> readNoInt · 7137cffd
      Shijin Kong authored
      Summary: EINTR should be retried
      
      Reviewed By: afrind
      
      Differential Revision: D2735879
      
      fb-gh-sync-id: 6f25cd26e29ab8e7e13a3d63f24bf2d104c14809
      7137cffd
  5. 08 Dec, 2015 4 commits
    • Chad Parry's avatar
      Avoid cost of cancelAll · 750d49c8
      Chad Parry authored
      Summary:
      This is an experimental diff that may improve the performance of `HHWheelTimer::cancelAll`. If there are no timers to cancel, then it can bail early.
      
      Since perflab is unlikely to be conclusive, and since this diff looks like a strict improvement, I'll proceed with landing it.
      
      Reviewed By: djwatson
      
      Differential Revision: D2735297
      
      fb-gh-sync-id: 9f5a811ee6d9fa9434576e9abd3ef3443a7579b7
      750d49c8
    • Andrii Grynenko's avatar
      Fix TLRefCount race around thread local destruction and fix RefCount unit test · 5ff51e97
      Andrii Grynenko authored
      Reviewed By: pavlo-fb
      
      Differential Revision: D2708425
      
      fb-gh-sync-id: 665d077210503df4f4e8aa8f88ce5b9b277582f3
      5ff51e97
    • Chip Turner's avatar
      Update zstd to 0.4.2 · 623cc983
      Chip Turner authored
      Summary: New version.
      
      Reviewed By: cyan
      
      Differential Revision: D2730844
      
      fb-gh-sync-id: 4305bdfba2e8d25eba295bbf3f13a140c0d04a1c
      623cc983
    • Neel Goyal's avatar
      Mark some methods virtual on SSL Context. · 7fc28369
      Neel Goyal authored
      Summary:
      Mark some methods as virtual.  This makes writing some
      better unit tests on the associated task possible.
      
      Reviewed By: siyengar
      
      Differential Revision: D2730126
      
      fb-gh-sync-id: f79f7632e873cb218bb49883d9b53beea7bb96e7
      7fc28369
  6. 07 Dec, 2015 2 commits
    • John Sherwood's avatar
      add type info to broken promise what() · 56a2009b
      John Sherwood authored
      Summary: when a promise is broken, add type info to the message. This will allow for some small improvements to debugging errors from broken promises, namely giving developers a slightly more refined target to grep for.
      
      Reviewed By: fugalh
      
      Differential Revision: D2725575
      
      fb-gh-sync-id: b92edbde874e63eaeab97395da7bb52f76968800
      56a2009b
    • Kyle Nekritz's avatar
      Fix segfaults in AsyncSSLSocket when used in unencrypted mode. · df9360f4
      Kyle Nekritz authored
      Reviewed By: djwatson
      
      Differential Revision: D2720027
      
      fb-gh-sync-id: 1d56aabedeaf65a5d48e152eaee5c81695be7620
      df9360f4
  7. 06 Dec, 2015 5 commits
    • Bartek Ryniec's avatar
      json: Add option to parse numbers as strings · 0dbbe856
      Bartek Ryniec authored
      Summary: Adding a flag in `folly::json::serialization_opts` that allows you to request all numbers to be parsed into strings. This saves you from exceptions being thrown by `folly::parseJson` if it encounters numbers that wouldn't fit in int64.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2713039
      
      fb-gh-sync-id: 4f3d0d20f3012efd6229adf895200a3901bb4493
      0dbbe856
    • Kyle Nekritz's avatar
      Make getWrappedTransport/getUnderlyingTransport const. · d662c1b7
      Kyle Nekritz authored
      Reviewed By: mzlee
      
      Differential Revision: D2709222
      
      fb-gh-sync-id: 67a00a49bbcef5572b6092d7bfba1842d985e643
      d662c1b7
    • Kyle Nekritz's avatar
      Remove getBytesRead and getBytesWritten from folly::AsyncSSLSocket. · 37b28711
      Kyle Nekritz authored
      Summary: getRawBytesReceived and getRawBytesWritten should be used instead.
      
      Reviewed By: mzlee
      
      Differential Revision: D2708684
      
      fb-gh-sync-id: 2de87dc2b8c3466f94293a3d7df89fc5fce3a00f
      37b28711
    • Alexey Spiridonov's avatar
      Add an "after fork, before exec" callback · 59030f07
      Alexey Spiridonov authored
      Summary:
      In rare cases, it is required to run code **in the child process**, before it calls `exec()` because you need to change the state of the process **before** the child binary gets to run. This diff adds a callback to permit this. The callback is deliberately harder to use than an `std::function`, because you **REALLY HAVE TO KNOW WHAT YOU ARE DOING** to use this. And you have to check your work three times. Even glog `LOG()` must not be called from inside this callback. Your random library of choice is also probably unsafe.
      
      This diff is primarily applicable to job managers and shells. For example, these tasks benefit from this callback: adding a child to a Linux `cgroup`, twiddling its various POSIX process attributes.
      
      Implementing a correct callback for the post-vfork environment is fraught with peril. Read http://ewontfix.com/7/, and the docstrings in this diff.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2688323
      
      fb-gh-sync-id: aae49e2b3957ca845895acca26e9cb44df1afc07
      59030f07
    • Umair Sadiq's avatar
      fix for negative delay in runAfterDelay · f94bbfeb
      Umair Sadiq authored
      Summary: Currently, the tryRunAfterDelay implicitly converts a negative delay in int to unsigned int. With this change, the api makes it clear than only unsinged int is accepted as valid delay
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2710034
      
      fb-gh-sync-id: cb3c6b91bb86bbe07fa0e590b2ea871242d19745
      f94bbfeb
  8. 03 Dec, 2015 1 commit
    • Steve O'Brien's avatar
      ThreadLocalDetail: OSX fixes · fd4ce7d1
      Steve O'Brien authored
      Summary:
      Change mutex to MicroSpinLock, for constexpr-ctor-ness on OSX.
      
      Fixes this error seen on mac:
      
        ThreadLocalDetail.h:202:38: note: non-literal type 'std::mutex' cannot be used in a constant expression
      
      Reviewed By: ldemailly
      
      Differential Revision: D2713511
      
      fb-gh-sync-id: bc1c34b4a0ee21347278aa368b408f286345e050
      fd4ce7d1
  9. 02 Dec, 2015 5 commits
    • Steve O'Brien's avatar
      ThreadLocalDetail: fix bug just introduced w/ recent change to constexpr-ctor style class · 398f8373
      Steve O'Brien authored
      Summary: Small, silly bug which is triggered when there are no keys to unregister, invalidating the current size of the structure.
      
      Reviewed By: yzhan
      
      Differential Revision: D2712604
      
      fb-gh-sync-id: f6f031936d8e4e458b49c08714f42cb2eec4c4fe
      398f8373
    • Tudor Bosman's avatar
      Add Optional::value_type · d93a7913
      Tudor Bosman authored
      Summary: Comes in handy, and std::experimental::optional has it.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2708324
      
      fb-gh-sync-id: 87cdf2449f356d3baf9fb56a608e9c43d8fe79ae
      d93a7913
    • Steve O'Brien's avatar
      folly: ThreadLocalDetail: make PthreadKeyUnregister constexpr-constructible, avoid SIOF · 4140f483
      Steve O'Brien authored
      Summary:
      Since this is used in so many places during the program's static-initialization (at startup), this class itself could be (has been demonstrated to be) a point of SIOF problems itself.
      
      Made this class constexpr-constructible, so it doesn't need to be part of static initialization, making it SIOF-proof.
      
      Reviewed By: luciang
      
      Differential Revision: D2709231
      
      fb-gh-sync-id: f248c9f2848c09045e000cfdc03636d847e522c9
      4140f483
    • Chad Parry's avatar
      Recommend a different exception_handler idiom · 266ccb57
      Chad Parry authored
      Summary: This is a //tiny// documentation change. I noticed that there are lots of places in the codebase where people follow this recommended usage of `with_exception` in an if–else chain, (e.g., https://fburl.com/181606454). IMHO, a short-circuiting `||` operator is easier to read and write.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2687840
      
      fb-gh-sync-id: 6354555aeba81dcfe7adf17e7e573de0b1206b37
      266ccb57
    • Andrii Grynenko's avatar
      Properly init collectDone_ · 632fb9b5
      Andrii Grynenko authored
      Summary: facepaw
      
      Reviewed By: djwatson
      
      Differential Revision: D2709030
      
      fb-gh-sync-id: 20fe50bc70e97c4fedeae8fd271a4de70fa0e805
      632fb9b5
  10. 01 Dec, 2015 6 commits
    • Yedidya Feldblum's avatar
      Avoid requiring a suppression (unevaluated-expression) · 5f49ee87
      Yedidya Feldblum authored
      Summary: [Folly] Avoid requiring a suppression (`unevaluated-expression`).
      
      I am not a fan of suppressing warnings. This warning comes from the internals of gtest, but anyway.
      
      Replace with something that does not trigger the warning.
      
      Reviewed By: Gownta
      
      Differential Revision: D2706279
      
      fb-gh-sync-id: 2ecac1d230308a8fd21a69565193c52585526448
      5f49ee87
    • Daniel Andersson's avatar
      Enable find/emplace for key types other than KeyT. · 4e5cb0ef
      Daniel Andersson authored
      Summary: Add template parameters to support arbitrary types when looking up a key.
      
      This is useful to avoid the cost of 'materializing' a key which is likely to be present in the array (or, alternatively, switching on a tagged union KeyT).
      
      Use the new capability to greatly simplify the lookup logic in HHVMs static string table.
      
      Reviewed By: nbronson
      
      Differential Revision: D2662451
      
      fb-gh-sync-id: 707fa033f350b80ca8080af17f1a8a74c59f2e88
      4e5cb0ef
    • Jim Meyering's avatar
      folly/Conv.h: suppress -Wfloat-conversion warnings · defa24cf
      Jim Meyering authored
      Summary: Using -Werror and -Wfloat-conversion was causing failure in code that is deliberately
      performing that conversion.  Add explicit casts to avoid the warnings/errors.
      Here are two of the diagnostics:
      
        ./folly/Conv.h: In instantiation of "typename std::enable_if<std::is_floating_point<_Tp>::value, Tgt>::type folly::to(folly::StringPiece) [with Tgt = float; typename std::enable_if<std::is_floating_point<_Tp>::value, Tgt>::type = float; folly::StringPiece = folly::Range<const char*>]":
        ./thrift/lib/cpp2/protocol/SimpleJSONProtocol.tcc:687:28:   required from "T apache::thrift::SimpleJSONProtocolReader::castIntegral(const string&) [with T = float; std::string = std::basic_fbstring<char>]"
        ./thrift/lib/cpp2/protocol/SimpleJSONProtocol.tcc:680:26:   required from "uint32_t apache::thrift::SimpleJSONProtocolReader::readJSONKey(T&) [with T = float; uint32_t = unsigned int]"
        ./thrift/lib/cpp2/protocol/SimpleJSONProtocol.tcc:654:16:   required from "uint32_t apache::thrift::SimpleJSONProtocolReader::readInContext(T&) [with T = float; uint32_t = unsigned int]"
        ./thrift/lib/cpp2/protocol/SimpleJSONProtocol.tcc:1035:34:   required from here
        ./folly/Conv.h:1222:31: error: conversion to "float" from "std::enable_if<true, double>::type {aka double}" may alter its value [-Werror=float-conversion]
      
        ./folly/Conv.h: In instantiation of "typename std::enable_if<((std::is_integral<_Tp2>::value && std::is_floating_point<_Tp>::value) || (std::is_floating_point<_DInputType>::value && std::is_integral<_Tp>::value)), Tgt>::type folly::to(const Src&) [with Tgt = long int; Src = double; typename std::enable_if<((std::is_integral<_Tp2>::value && std::is_floating_point<_Tp>::value) || (std::is_floating_point<_DInputType>::value && std::is_integral<_Tp>::value)), Tgt>::type = long int]":
        ./folly/dynamic-inl.h:636:51:   required from "T folly::dynamic::asImpl() const [with T = long int]"
        ./folly/dynamic-inl.h:384:64:   required from here
        ./folly/Conv.h:1245:16: error: conversion to "long int" from "double" may alter its value [-Werror=float-conversion]
      
      This change deserves a little more explanation:
      
        -  return ceil((double(sizeof(IntegerType) * CHAR_BIT) * M_LN2) / M_LN10);
        +  return (unsigned int)(ceil(sizeof(IntegerType) * CHAR_BIT * M_LN2 / M_LN10));
      
      In addition to adding the cast to destination type, I have also removed the unnecessary cast to double of the first product (there is not risk that it will overflow, and no need to promote to double, there), and I have also removed the grouping parentheses, since the standard left-to-right evaluation works just fine here.
      
      Reviewed By: Gownta, yfeldblum
      
      Differential Revision: D2703928
      
      fb-gh-sync-id: 23b49281d9120d106f1fdbd30921e8f39c01367d
      defa24cf
    • Yedidya Feldblum's avatar
      CodeMod: Use the ExceptionWrapper::with_exception variant that deduces exception types · 15e17fa2
      Yedidya Feldblum authored
      Summary: CodeMod: Use the `ExceptionWrapper::with_exception` variant that deduces exception types.
      
      Since we must specify the exception type in the lambda arg, and there is a variant of `ExceptionWrapper::with_exception` that deduces the type of the exception from the type of the lambda arg, we don't need to specify the exception type again as a template parameter anymore.
      
      Reviewed By: meyering
      
      Differential Revision: D2694895
      
      fb-gh-sync-id: 505469f9008973a315e836f356e5db97df4ec921
      15e17fa2
    • Jim Meyering's avatar
      folly/Conv.h: estimateSpaceNeeded: avoid undefined behavior · 8d56fe68
      Jim Meyering authored
      Summary: Do not negate signed numbers like INT_MIN or INTMAX_MIN, since
      that would evoke undefined behavior.  Otherwise, the test (below)
      would fail with this run-time error:
      
        [ RUN      ] Conv.Integral2String
        folly/Conv.h:521:47: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
      
      Reviewed By: markisaa
      
      Differential Revision: D2704195
      
      fb-gh-sync-id: 4036437fb972109672004163880078127e7df797
      8d56fe68
    • Yedidya Feldblum's avatar
      Avoid deprecated Singleton<T>::get() in folly/futures · d3a08687
      Yedidya Feldblum authored
      Summary: [Folly] Avoid deprecated `Singleton<T>::get()` in `folly/futures`.
      
      Changes `getTimekeeperSingleton()` to return a `shared_ptr<Timekeeper>`, and patches its call-sites.
      
      Additionally, have the call-sites keep the singleton instance alive for the duration that it is being directly used.
      
      Reviewed By: ddrcoder
      
      Differential Revision: D2702361
      
      fb-gh-sync-id: 82b72ee514dc4f2a7f7522af8b2e92b34df063d6
      d3a08687
  11. 26 Nov, 2015 1 commit
    • Andrii Grynenko's avatar
      Deprecate get_weak() · 19fb62bd
      Andrii Grynenko authored
      Summary: get_weak() is always used with .lock(), but try_get() is actually more performant than get_weak().lock().
      Using get_weak() to store a weak_ptr and keep locking is not safe in fork scenarios.
      
      Reviewed By: yfeldblum
      
      Differential Revision: D2694223
      
      fb-gh-sync-id: 908d44293ffd9b3782152d43e28d5de172d1654a
      19fb62bd