Github user jpeach commented on a diff in the pull request:

    https://github.com/apache/trafficserver/pull/1294#discussion_r94529615
  
    --- Diff: iocore/net/BIO_fastopen.cc ---
    @@ -160,9 +174,24 @@ static const BIO_METHOD fastopen_methods = {
       .destroy       = fastopen_destroy,
       .callback_ctrl = nullptr,
     };
    +#else
    +static BIO_METHOD *fastopen_methods = nullptr;
    +#endif
     
     const BIO_METHOD *
     BIO_s_fastopen()
     {
    +#if OPENSSL_VERSION_NUMBER < 0x10100000L
       return &fastopen_methods;
    +#else
    +  if (!fastopen_methods) {
    +    fastopen_methods = BIO_meth_new(BIO_TYPE_SOCKET, "fastopen");
    +    BIO_meth_set_write(fastopen_methods, fastopen_bwrite);
    +    BIO_meth_set_read(fastopen_methods, fastopen_bread);
    +    BIO_meth_set_ctrl(fastopen_methods, fastopen_ctrl);
    +    BIO_meth_set_create(fastopen_methods, fastopen_create);
    +    BIO_meth_set_destroy(fastopen_methods, fastopen_destroy);
    --- End diff --
    
    I think this would be a little cleaner (and avoid the race condition) if 
you used a static initializer:
    
    ```C
    struct fastopen_bio
    {
        fastopen_bio() {
    #if OPENSSL_VERSION_NUMBER < 0x10100000L
          static const BIO_METHOD m = {
          ...
          };
    
          method = &m;
    #else
          method = BIO_meth_new(BIO_TYPE_SOCKET, "fastopen");
          BIO_meth_set_write(method, fastopen_bwrite);
          ...
    #endif
        }
    
        const BIO_METHOD *method; 
    };
    
    static fastopen_bio fastopen;
    
    const BIO_METHOD *
    BIO_s_fastopen()
    {
        return fastopen.methods;
    }
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to