Skip to content

Commit

Permalink
Merge pull request #7 from sumwale/snappy/0.14.1
Browse files Browse the repository at this point in the history
Porting changes from snappy/0.12.0, based off bf867bc skipping the following changes since they are already in thrift 0.14.1:

    - Changing to C++11 noexcept from empty throw()
    - Allow for localhost-only bind for client sockets (C++)
    - Fixing maven repo URLs to use https

Full set of changes applied:

- Add "skip_async" property to java generator
  - This skips generation of asynchronous interfaces for those who are not using them.

- Add "struct_separate_files" property to C++ generator
  - This generates classes in separate files, one class per file, instead of everything in a single file
    (similar to what other generators like java do by default).
  - This allows for clean separation of classes and allows override of specific classes by hand-written code if required.
  - This patch also changes the constants generation to use static consts for primitive types
    (int, bool, long, short, byte, double).

- Add couple of options to skip C++ generator features
  - "no-recursion-limit" option to skip checks for maximum recursion limit while writing objects
  - "no-concurrent-client" option to skip concurrent client code generation

- Adding public getters for TSocket timeout settings
- Removing unnecessary TBase with virtual TBase
- Fixing build on older compilers (gcc < 4.5).
- Fix java plugin's gradle install task
- Add TSSLSocketFactory::setInExit() to allow skipping calls to SSL_shutdown
  (e.g. useful during global destructor cleanup where SSL_shutdown can lead to unexpected crashes)
  • Loading branch information
Sumedh Wale authored and sumwale committed May 2, 2021
1 parent f6fa179 commit 13b00bf
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 115 deletions.
412 changes: 348 additions & 64 deletions compiler/cpp/src/thrift/generate/t_cpp_generator.cc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion compiler/cpp/src/thrift/generate/t_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class t_generator {
virtual std::string autogen_comment() {
return std::string("/**\n") + " * " + autogen_summary() + "\n" + " *\n"
+ " * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING\n"
+ " * @generated\n" + " */\n";
+ " * @generated\n" + " */\n\n";
}

virtual std::string autogen_summary() {
Expand Down
21 changes: 17 additions & 4 deletions compiler/cpp/src/thrift/generate/t_java_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class t_java_generator : public t_oop_generator {
suppress_generated_annotations_ = false;
rethrow_unhandled_exceptions_ = false;
unsafe_binaries_ = false;
skip_async_ = false;
for( iter = parsed_options.begin(); iter != parsed_options.end(); ++iter) {
if( iter->first.compare("beans") == 0) {
bean_style_ = true;
Expand Down Expand Up @@ -106,6 +107,8 @@ class t_java_generator : public t_oop_generator {
}
} else if( iter->first.compare("unsafe_binaries") == 0) {
unsafe_binaries_ = true;
} else if( iter->first.compare("skip_async") == 0) {
skip_async_ = true;
} else {
throw "unknown option java:" + iter->first;
}
Expand Down Expand Up @@ -415,6 +418,7 @@ class t_java_generator : public t_oop_generator {
bool suppress_generated_annotations_;
bool rethrow_unhandled_exceptions_;
bool unsafe_binaries_;
bool skip_async_;

};

Expand Down Expand Up @@ -2862,11 +2866,17 @@ void t_java_generator::generate_service(t_service* tservice) {

// Generate the three main parts of the service
generate_service_interface(tservice);
generate_service_async_interface(tservice);
if (!skip_async_) {
generate_service_async_interface(tservice);
}
generate_service_client(tservice);
generate_service_async_client(tservice);
if (!skip_async_) {
generate_service_async_client(tservice);
}
generate_service_server(tservice);
generate_service_async_server(tservice);
if (!skip_async_) {
generate_service_async_server(tservice);
}
generate_service_helpers(tservice);

indent_down();
Expand Down Expand Up @@ -5455,4 +5465,7 @@ THRIFT_REGISTER_GENERATOR(
" generated_annotations=[undated|suppress]:\n"
" undated: suppress the date at @Generated annotations\n"
" suppress: suppress @Generated annotations entirely\n"
" unsafe_binaries: Do not copy ByteBuffers in constructors, getters, and setters.\n")
" unsafe_binaries: Do not copy ByteBuffers in constructors, getters, and setters.\n"
" skip_async:\n"
" Skip generating the Asynchronous interfaces, client and server.\n"
)
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ AS_IF([test "x$PY_PREFIX" = x], [PY_PREFIX="/usr"])

AC_ARG_VAR([JAVA_PREFIX], [Prefix for installing the Java lib jar.
Default = "/usr/local/lib"])
AS_IF([test "x$JAVA_PREFIX" != x], [JAVA_PREFIX="$JAVA_PREFIX/usr/local/lib"],
AS_IF([test "x$JAVA_PREFIX" != x], [JAVA_PREFIX="$JAVA_PREFIX"],
[test "x$PREFIX" != x], [JAVA_PREFIX="$PREFIX/usr/local/lib"],
[JAVA_PREFIX="/usr/local/lib"])

Expand Down
1 change: 0 additions & 1 deletion lib/cpp/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ include_thrift_HEADERS = \
src/thrift/TApplicationException.h \
src/thrift/TLogging.h \
src/thrift/TToString.h \
src/thrift/TBase.h \
src/thrift/TConfiguration.h

include_concurrencydir = $(include_thriftdir)/concurrency
Expand Down
38 changes: 0 additions & 38 deletions lib/cpp/src/thrift/TBase.h

This file was deleted.

4 changes: 2 additions & 2 deletions lib/cpp/src/thrift/transport/THeaderTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class THeaderTransport : public TVirtualTransport<THeaderTransport, TFramedTrans
/// Use default buffer sizes.
explicit THeaderTransport(const std::shared_ptr<TTransport>& transport,
std::shared_ptr<TConfiguration> config = nullptr)
: TVirtualTransport(transport, config),
: TVirtualTransport<THeaderTransport, TFramedTransport>(transport, config),
outTransport_(transport),
protoId(T_COMPACT_PROTOCOL),
clientType(THRIFT_HEADER_CLIENT_TYPE),
Expand All @@ -91,7 +91,7 @@ class THeaderTransport : public TVirtualTransport<THeaderTransport, TFramedTrans
THeaderTransport(const std::shared_ptr<TTransport> inTransport,
const std::shared_ptr<TTransport> outTransport,
std::shared_ptr<TConfiguration> config = nullptr)
: TVirtualTransport(inTransport, config),
: TVirtualTransport<THeaderTransport, TFramedTransport>(inTransport, config),
outTransport_(outTransport),
protoId(T_COMPACT_PROTOCOL),
clientType(THRIFT_HEADER_CLIENT_TYPE),
Expand Down
7 changes: 4 additions & 3 deletions lib/cpp/src/thrift/transport/TSSLSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void TSSLSocket::open() {
*/
void TSSLSocket::close() {
if (ssl_ != nullptr) {
try {
if (!TSSLSocketFactory::inExit()) try {
int rc;
int errno_copy = 0;
int error = 0;
Expand Down Expand Up @@ -854,6 +854,7 @@ unsigned int TSSLSocket::waitForEvent(bool wantRead) {
uint64_t TSSLSocketFactory::count_ = 0;
Mutex TSSLSocketFactory::mutex_;
bool TSSLSocketFactory::manualOpenSSLInitialization_ = false;
bool TSSLSocketFactory::inExit_ = false;

TSSLSocketFactory::TSSLSocketFactory(SSLProtocol protocol) : server_(false) {
Guard guard(mutex_);
Expand Down Expand Up @@ -1022,9 +1023,9 @@ void TSSLSocketFactory::loadPrivateKeyFromBuffer(const char* aPrivateKey, const
}

void TSSLSocketFactory::loadTrustedCertificates(const char* path, const char* capath) {
if (path == nullptr) {
if (path == nullptr && capath == nullptr) {
throw TTransportException(TTransportException::BAD_ARGS,
"loadTrustedCertificates: <path> is nullptr");
"loadTrustedCertificates: <path> and <capath> are both nullptr");
}
if (SSL_CTX_load_verify_locations(ctx_->get(), path, capath) == 0) {
int errno_copy = THRIFT_GET_SOCKET_ERROR;
Expand Down
15 changes: 15 additions & 0 deletions lib/cpp/src/thrift/transport/TSSLSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,20 @@ class TSSLSocketFactory {
static void setManualOpenSSLInitialization(bool manualOpenSSLInitialization) {
manualOpenSSLInitialization_ = manualOpenSSLInitialization;
}
/**
* Set the "inExit_" flag that will avoid SSL_shutdown() for any subsequent
* TSSLSocket::close() calls. Typically useful during global destructor/exit
* that can otherwise cause unexpected trouble in SSL_shutdown().
*/
static void setInExit(bool inExit) {
inExit_ = inExit;
}
/**
* Return the global flag as set by setInExit().
*/
static bool inExit() {
return inExit_;
}

protected:
std::shared_ptr<SSLContext> ctx_;
Expand All @@ -328,6 +342,7 @@ class TSSLSocketFactory {
static concurrency::Mutex mutex_;
static uint64_t count_;
THRIFT_EXPORT static bool manualOpenSSLInitialization_;
THRIFT_EXPORT static bool inExit_;
void setup(std::shared_ptr<TSSLSocket> ssl);
static int passwordCallback(char* password, int size, int, void* data);
};
Expand Down
21 changes: 21 additions & 0 deletions lib/cpp/src/thrift/transport/TSocket.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,16 +199,37 @@ class TSocket : public TVirtualTransport<TSocket> {
*/
void setConnTimeout(int ms);

/**
* Get the connect timeout in milliseconds.
*/
int getConnTimeout() {
return connTimeout_;
}

/**
* Set the receive timeout
*/
void setRecvTimeout(int ms);

/**
* Get the receive timeout in milliseconds.
*/
int getRecvTimeout() {
return recvTimeout_;
}

/**
* Set the send timeout
*/
void setSendTimeout(int ms);

/**
* Get the send timeout in milliseconds.
*/
int getSendTimeout() {
return sendTimeout_;
}

/**
* Set the max number of recv retries in case of an THRIFT_EAGAIN
* error
Expand Down
2 changes: 1 addition & 1 deletion lib/java/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ all-local:
--console=plain

install-exec-hook:
./gradlew $(GRADLE_OPTS) install \
./gradlew $(GRADLE_OPTS) installDist installJavadoc \
-Prelease=true \
-Pinstall.path=$(DESTDIR)$(JAVA_PREFIX) \
-Pinstall.javadoc.path=$(DESTDIR)$(docdir)/java \
Expand Down

0 comments on commit 13b00bf

Please sign in to comment.