From 19fcec84d8d7d21e796c7624e521b60d28ee21ed Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:45:59 +0200 Subject: Adding upstream version 16.2.11+ds. Signed-off-by: Daniel Baumann --- .../thrift/contrib/transport-sample/Makefile | 25 +++ .../thrift/contrib/transport-sample/README.md | 61 ++++++ .../thrift/contrib/transport-sample/Sample.thrift | 39 ++++ .../contrib/transport-sample/ThriftCommon.cpp | 37 ++++ .../thrift/contrib/transport-sample/ThriftCommon.h | 205 +++++++++++++++++++++ .../contrib/transport-sample/client/ReadMe.txt | 40 ++++ .../contrib/transport-sample/client/client.cpp | 195 ++++++++++++++++++++ .../contrib/transport-sample/client/client.vcxproj | 105 +++++++++++ .../transport-sample/client/client.vcxproj.filters | 66 +++++++ .../contrib/transport-sample/client/stdafx.cpp | 8 + .../contrib/transport-sample/client/stdafx.h | 15 ++ .../contrib/transport-sample/client/targetver.h | 8 + .../thrift/contrib/transport-sample/config.h | 24 +++ .../contrib/transport-sample/server/ReadMe.txt | 40 ++++ .../contrib/transport-sample/server/server.cpp | 168 +++++++++++++++++ .../contrib/transport-sample/server/server.vcxproj | 106 +++++++++++ .../transport-sample/server/server.vcxproj.filters | 66 +++++++ .../contrib/transport-sample/server/stdafx.cpp | 8 + .../contrib/transport-sample/server/stdafx.h | 15 ++ .../contrib/transport-sample/server/targetver.h | 8 + .../thrift/contrib/transport-sample/thriftme.bat | 1 + .../thrift/contrib/transport-sample/thriftme.sh | 24 +++ .../contrib/transport-sample/transport-sample.sln | 26 +++ 23 files changed, 1290 insertions(+) create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/Makefile create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/README.md create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/Sample.thrift create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.cpp create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.h create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/ReadMe.txt create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/client.cpp create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj.filters create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.cpp create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.h create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/client/targetver.h create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/config.h create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/ReadMe.txt create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/server.cpp create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj.filters create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.cpp create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.h create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/server/targetver.h create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/thriftme.bat create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/thriftme.sh create mode 100644 src/jaegertracing/thrift/contrib/transport-sample/transport-sample.sln (limited to 'src/jaegertracing/thrift/contrib/transport-sample') diff --git a/src/jaegertracing/thrift/contrib/transport-sample/Makefile b/src/jaegertracing/thrift/contrib/transport-sample/Makefile new file mode 100644 index 000000000..89e03b8ef --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/Makefile @@ -0,0 +1,25 @@ +THRIFT_DIR =../.. +INCS_DIRS =-I${THRIFT_DIR}/lib/cpp/src -I. +THRIFT_LIB =${THRIFT_DIR}/lib/cpp/.libs/libthrift.a +BOOST_LIB = +CPP_DEFS = +CPP_OPTS =-Wall -O2 + +GEN_SRC = gen-cpp/SampleService.cpp \ + gen-cpp/Sample_types.cpp \ + gen-cpp/SampleCallback.cpp \ + gen-cpp/Sample_constants.cpp +GEN_INC = -Igen-cpp + +default: server client +.PHONY: server client + +server: + g++ ${CPP_OPTS} ${CPP_DEFS} -o server/server ${GEN_INC} ${INCS_DIRS} server/server.cpp ${GEN_SRC} ${THRIFT_LIB} ${BOOST_LIB} + +client: + g++ ${CPP_OPTS} ${CPP_DEFS} -o client/client ${GEN_INC} ${INCS_DIRS} client/client.cpp ${GEN_SRC} ${THRIFT_LIB} ${BOOST_LIB} + +clean: + $(RM) -r client/client server/server + diff --git a/src/jaegertracing/thrift/contrib/transport-sample/README.md b/src/jaegertracing/thrift/contrib/transport-sample/README.md new file mode 100644 index 000000000..a1dfc0a36 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/README.md @@ -0,0 +1,61 @@ +Thrift transport sample project +------------------------------- + +This cross-platform project has been built with Windows Visual Studio 10 and +OSX 10.7.1's g++. The client and server support socket and pipe transports +through command-line switches. + +Windows supports both named & anonymous pipes; *NIX gets only named +'pipes' at this time. + +Windows-only at this time: +The client & server are double-ended. Both sides run a server and client to +enable full duplex bidirectional event signaling. They are simple command +line apps. The server runs until it's aborted (Ctl-C). The client connects to +the server, informs the server of its listening pipe/port, runs some more RPCs +and exits. The server also makes RPC calls to the client to demonstrate +bidirectional operation. + +Prequisites: +Boost -- tested with Boost 1.47, other versions may work. +libthrift library -- build the library under "thrift/lib/cpp/" +thrift IDL compiler -- download from http://thrift.apache.org/download/ + or build from "thrift/compiler/cpp". The IDL compiler version should + match the thrift source distribution's version. For instance, thrift-0.9.0 + has a different directory structure than thrift-0.8.0 and the generated + files are not compatible. + +Note: Bulding the thrift IDL compiler and library are beyond the scope +of this article. Please refer to the Thrift documentation in the respective +directories and online. + + +Microsoft Windows with Visual Studio 10 +---------------------------------------- +Copy the IDL compiler 'thrift.exe' to this project folder or to a location in the path. +Run thriftme.bat to generate the interface source from the thrift files. + +Open transport-sample.sln and... +Adapt the Boost paths for the client and server projects. Right-click on each project, select +Properties, then: +Configuration Properties -> C/C++ -> General -> Additional Include Directories +Configuration Properties -> Linker -> General -> Additional Include Directories + +The stock path assumes that Boost is located at the same level as the thrift repo root. + +Run the following in separate command prompts from the Release or Debug +build folder: + server.exe -np test + client.exe -np test + + +*NIX flavors +------------ +Build the thrift cpp library. +Build the IDL compiler and copy it to this project folder. +Run thriftme.sh to generate the interface source from the thrift files. +Run 'make' + +Run the following in separate shells: + server/server -np /tmp/test + client/client -np /tmp/test diff --git a/src/jaegertracing/thrift/contrib/transport-sample/Sample.thrift b/src/jaegertracing/thrift/contrib/transport-sample/Sample.thrift new file mode 100644 index 000000000..3040e251c --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/Sample.thrift @@ -0,0 +1,39 @@ +/* + transport-sample thrift IDL file . + Execute thriftme.bat under Windows to generate the cpp stubs from this IDL. + */ + +// See thrift/tutorial/tutorial.thrift and shared.thrift for more extensive examples. + + +namespace cpp Sample +namespace java Sample +namespace perl Sample + +//This struct is not used in the sample. Shown here for illustrative purposes only. +// +struct SampleStruct +{ + 1: i32 key + 2: string value +} + + +//A service contains the RPC(s). +// +service SampleService +{ + string HelloThere(1:string HelloString), + void ServerDoSomething(), + + //Client calls this to tell server which port to connect back on. + void ClientSideListenPort(1:i16 Port), + //Named pipe version + void ClientSidePipeName(1:string name), +} + +//Sample RPC on the 'client' side that the master server can call. +service SampleCallback +{ + void pingclient(), +} diff --git a/src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.cpp b/src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.cpp new file mode 100644 index 000000000..60ebf7a00 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.cpp @@ -0,0 +1,37 @@ +// ThriftCommon.cpp : Common functions for sample Thrift client and server +// + +#include "ThriftCommon.h" + +namespace thriftcommon +{ + //---------------------------------------------------------------------------- + //Launch child process and pass R/W anonymous pipe handles on cmd line. + //This is a simple example and does not include elevation or other + //advanced features. + // + bool LaunchAnonPipeChild(std::string app, boost::shared_ptr transport) + { +#ifdef _WIN32 + PROCESS_INFORMATION pi; + STARTUPINFOA si; + GetStartupInfoA(&si); //set startupinfo for the spawned process + char handles[MAX_PATH]; //Stores pipe handles converted to text + + sprintf(handles, "%s %d %d", app.c_str(), + (int)boost::shared_dynamic_cast(transport)->getClientRdPipeHandle(), + (int)boost::shared_dynamic_cast(transport)->getClientWrtPipeHandle()); + + //spawn the child process + if (!CreateProcessA(NULL, handles, NULL,NULL,TRUE,0,NULL,NULL,&si,&pi)) + { + GlobalOutput.perror("TPipeServer CreateProcess failed, GLE=", GetLastError()); + return false; + } + + CloseHandle(pi.hThread); + CloseHandle(pi.hProcess); +#endif + return true; + } +} diff --git a/src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.h b/src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.h new file mode 100644 index 000000000..078ad4474 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/ThriftCommon.h @@ -0,0 +1,205 @@ +// ThriftCommon.h : Common includes, namespaces and templates +// for sample Thrift client and server +// +// Add the following paths to the Project's properties: +// +// Configuration Properties -> C/C++ -> General-> Additional Include Directories -- +// ../;../../../lib/cpp/src;../../../../boost;../../../../boost/boost/tr1; +// +// Configuration Properties -> Linker -> General -> Additional Library Directories -- +// ../../../lib/cpp/$(Configuration);../../../../Boost/lib +// +// Configuration Properties -> Linker -> Input -> Additional Dependencies -- +// libthrift.lib +// +// ... adjust relative paths as necessary. +// + +#ifdef _WIN32 //thrift is crashing when using boost threads on Mac OSX +#else +# include +# include +#endif + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Required Includes +//'server' side #includes +#include +#include +#include +#include +//'client' side #includes +#include +#include +#include +#include +#include + +#include + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +// Required Namespaces +//'server' side namespaces +using namespace apache::thrift::server; +using namespace apache::thrift::concurrency; +//common namespaces +using namespace apache::thrift; +using namespace apache::thrift::protocol; +using namespace apache::thrift::transport; +//using namespace boost; //using ns boost can introduce type conflicts +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +namespace thriftcommon +{ + //---------------------------------------------------------------------------- + // + //Start the thrift 'server' (both server & client side run one for bidir event signaling) + // *** This function template will block *** + // + template + void RunThriftServer (boost::shared_ptr hndlr, + int NumThreads, + boost::shared_ptr transport, + boost::shared_ptr &server) + { +#ifdef _WIN32 + if (!hndlr.get()) + throw std::exception("RunThriftServer() invalid handler"); + if (!transport.get()) + throw std::exception("RunThriftServer() invalid transport"); +#else + if ( !hndlr.get() || !transport.get() ) + throw std::exception(); +#endif + + boost::shared_ptr handler(hndlr); + boost::shared_ptr processor(new MyProcessor(handler)); + boost::shared_ptr tfactory(new TBufferedTransportFactory()); + boost::shared_ptr pfactory(new TBinaryProtocolFactory()); + + if(NumThreads <= 1) + { //Single-threaded server + server.reset(new TSimpleServer(processor, transport, tfactory, pfactory)); + } + else + { //Multi-threaded server + boost::shared_ptr threadManager = ThreadManager::newSimpleThreadManager(NumThreads); + boost::shared_ptr threadFactory = boost::shared_ptr(new ThreadFactory()); + threadManager->threadFactory(threadFactory); + threadManager->start(); + server.reset(new TThreadPoolServer(processor, transport, tfactory, pfactory, threadManager)); + } + + printf("Starting the 'server'...\n"); + server->serve(); + printf("done.\n"); + } + + // Thrift server wrapper function that accepts a pipe name. + // A handler must be passed in to this version. + template + void RunThriftServer (boost::shared_ptr hndlr, int NumThreads, std::string pipename, boost::shared_ptr &svr) + { +#ifndef _WIN32 //Mac, *nix + unlink(pipename.c_str()); +#endif + boost::shared_ptr transport(new TPipeServer(pipename, 1024, NumThreads)); //Named pipe + RunThriftServer(hndlr, NumThreads, transport, svr); + } + + // Thrift server wrapper function that accepts a pipe name. + // This version instantiates its own handler. + template + void RunThriftServer (int NumThreads, std::string pipename) + { + boost::shared_ptr handler(new MyHandler()); + boost::shared_ptr server; + + RunThriftServer(handler, NumThreads, pipename, server); + } + + // Thrift server wrapper function that accepts a socket port number. + // A handler must be passed in to this version. + template + void RunThriftServer (boost::shared_ptr hndlr, int NumThreads, int Port) + { + boost::shared_ptr transport(new TServerSocket(Port)); + boost::shared_ptr server; + RunThriftServer(hndlr, NumThreads, transport, server); + } + + // Thrift server wrapper function that accepts a socket port number. + // This version instantiates its own handler. + template + void RunThriftServer (int NumThreads, int Port) + { + boost::shared_ptr handler(new MyHandler()); + + RunThriftServer(handler, NumThreads, Port); + } + + // + template + void RunThriftServer (boost::shared_ptr hndlr, int NumThreads, boost::shared_ptr transport) + { + boost::shared_ptr server; + RunThriftServer(hndlr, NumThreads, transport, server); + } + + //---------------------------------------------------------------------------- + //Connect to thrift 'server' - Socket version + //(both server & client side run one for bidir event signaling) + // + template + void ConnectToServer (boost::shared_ptr &client, boost::shared_ptr &transport, int Port) + { + //Client side connection using sockets transport. + boost::shared_ptr socket(new TSocket("localhost", Port)); + transport.reset(new TBufferedTransport(socket)); + boost::shared_ptr protocol(new TBinaryProtocol(transport)); + + client.reset(new MyClient(protocol)); + } + + //Connect to thrift 'server' - Named Pipe version + template + void ConnectToServer (boost::shared_ptr &client, boost::shared_ptr &transport, std::string pipename) + { + //Client side connection using Named Pipe transport. + boost::shared_ptr pipe(new TPipe(pipename)); + transport.reset(new TBufferedTransport(pipe)); + boost::shared_ptr protocol(new TBinaryProtocol(transport)); + + client.reset(new MyClient(protocol)); + } + + //Connect to thrift 'server' - Anonymous Pipe version + //Currently only supported under Windows +#ifdef _WIN32 + template + void ConnectToServer (boost::shared_ptr &client, boost::shared_ptr &transport, HANDLE RdPipe, HANDLE WrtPipe) + { + //Client side connection using sockets transport. +#ifdef _WIN32 + boost::shared_ptr pipe(new TPipe((int)RdPipe, (int)WrtPipe)); + transport.reset(new TBufferedTransport(pipe)); +#else + boost::shared_ptr socket(new TSocket("localhost")); + transport.reset(new TBufferedTransport(socket)); +#endif + boost::shared_ptr protocol(new TBinaryProtocol(transport)); + + client.reset(new MyClient(protocol)); + } +#endif + + //---------------------------------------------------------------------------- + //Launch child process and pass R/W anonymous pipe handles on cmd line. + //Currently only supported under Windows +#ifdef _WIN32 + bool LaunchAnonPipeChild(std::string app, boost::shared_ptr transport); +#endif +} diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/ReadMe.txt b/src/jaegertracing/thrift/contrib/transport-sample/client/ReadMe.txt new file mode 100644 index 000000000..6c49a963a --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : client Project Overview +======================================================================== + +AppWizard has created this client application for you. + +This file contains a summary of what you will find in each of the files that +make up your client application. + + +client.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +client.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +client.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named client.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/client.cpp b/src/jaegertracing/thrift/contrib/transport-sample/client/client.cpp new file mode 100644 index 000000000..45fbef1d8 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/client.cpp @@ -0,0 +1,195 @@ +// client->cpp : Defines the entry point for the console application. +// +// sample client command line app using Thrift IPC. +// Quick n Dirty example, may not have very robust error handling +// for the sake of simplicity. + +#ifdef _WIN32 +# include "stdafx.h" +#else +# include "config.h" +#endif + + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//Include this before the generated includes +#include "ThriftCommon.h" +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//Tailor these to your generated files +#include "../gen-cpp/SampleService.h" +#include "../gen-cpp/SampleCallback.h" + +using namespace Sample; //declared in .thrift file +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +void ClientListenerThreadProc(); +bool bSocket = false; +bool bAnonPipe = false; +int srvPort; +std::string pipename; +std::string pipename_client; +#ifdef _WIN32 + HANDLE hConsole; +#endif + +//Customized version of printf that changes the text color +//This depends on hConsole global being initialized +void hlprintf(const char* _Format, ...) +{ +#ifdef _WIN32 + SetConsoleTextAttribute(hConsole, 0xE); +#endif + va_list ap; + int r; + va_start (ap, _Format); + r = vprintf (_Format, ap); + va_end (ap); +#ifdef _WIN32 + SetConsoleTextAttribute(hConsole, 7); +#endif +} + +//----------------------------------------------------------------------------- +// Client-side RPC implementations: Called by the server to the client for +// bidirectional eventing. +// +class SampleCallbackHandler : virtual public SampleCallbackIf { + public: + SampleCallbackHandler() { + // initialization goes here + } + + void pingclient() + { + hlprintf("<< 1) + { + if(_tcscmp(argv[1], TEXT("-sp")) == 0) + { //Socket Port specified + srvPort = _tstoi(argv[2]); + bSocket = true; + } + else if(_tcscmp(argv[1], TEXT("-np")) == 0) + { //Named Pipe specified +#ifdef _WIN32 + std::wstring wpipe(argv[2]); + pipename.resize(wpipe.length()); + std::copy(wpipe.begin(), wpipe.end(), pipename.begin()); +#else + pipename = argv[2]; +#endif + pipename_client = pipename + "_client"; + } + else if(argc == 3) + { //Anonymous Pipe specified +#ifdef _WIN32 + ReadPipe = (HANDLE)_tstoi(argv[1]); + WritePipe = (HANDLE)_tstoi(argv[2]); + bAnonPipe = true; +#else + printf("Anonymous pipes not (yet) supported under *NIX\n"); +#endif + } + else + usage = true; + } + else + usage = true; + + if(usage) + { + hlprintf("Thrift sample client usage:\n\n"); + hlprintf("Socket Port to connect to: -sp \n"); + hlprintf("Named Pipe to connect to: -np (e.g. affpipe)\n"); + hlprintf("Anonymous Pipe (must be launched by anon pipe creator):\n"); + hlprintf(" \n"); + return 0; + } + + //Client side connection to server. + boost::shared_ptr client; //Client class from Thrift-generated code. + boost::shared_ptr transport; + + if(bSocket) + { //Socket transport +#ifdef _WIN32 + TWinsockSingleton::create(); +#endif + hlprintf("Using socket transport port %d\n", srvPort); + thriftcommon::ConnectToServer(client, transport, srvPort); + } + else if(!bAnonPipe) + { + hlprintf("Using Named Pipe %s\n", pipename.c_str()); + thriftcommon::ConnectToServer(client, transport, pipename); + } + else + { +#ifdef _WIN32 + hlprintf("Using Anonymous Pipe transport\n"); + thriftcommon::ConnectToServer(client, transport, ReadPipe, WritePipe); +#endif + } + +#ifdef _WIN32 + //Start a thread to receive inbound connection from server for 2-way event signaling. + boost::thread ClientListenerThread(ClientListenerThreadProc); +#endif + + try { + transport->open(); + + //Notify server what to connect back on. + if(bSocket) + client->ClientSideListenPort(srvPort + 1); //Socket + else if(!bAnonPipe) + client->ClientSidePipeName(pipename_client); //Named Pipe + + //Run some more RPCs + std::string hellostr = "Hello how are you?"; + std::string returnstr; + client->HelloThere(returnstr, hellostr); + hlprintf("\n>>>Sent: %s\n", hellostr.c_str()); + hlprintf("<<>>Calling ServerDoSomething() which delays for 5 seconds.\n"); + client->ServerDoSomething(); + hlprintf(">>>ServerDoSomething() done.\n\n"); + + transport->close(); + } catch (TException &tx) { + hlprintf("ERROR: %s\n", tx.what()); + } + + return 0; +} + + +//Thread Routine +void ClientListenerThreadProc() +{ + if(bSocket) + thriftcommon::RunThriftServer(1, srvPort + 1); + else if(!bAnonPipe) + thriftcommon::RunThriftServer(1, pipename_client); +} diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj b/src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj new file mode 100644 index 000000000..779c339d7 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj @@ -0,0 +1,105 @@ +? + + + + Debug + Win32 + + + Release + Win32 + + + + {85FBFB54-530B-498F-9F38-44BA204FAE6A} + Win32Proj + client + + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../;../../../lib/cpp/src;../../../../boost;../../../../boost/boost/tr1;%(AdditionalIncludeDirectories) + + + Console + true + ../../../lib/cpp/$(Configuration);../../../../Boost/lib;%(AdditionalLibraryDirectories) + libthrift.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../;../../../lib/cpp/src;../../../../boost;../../../../boost/boost/tr1;%(AdditionalIncludeDirectories) + + + Console + true + true + true + ../../../lib/cpp/$(Configuration);../../../../Boost/lib;%(AdditionalLibraryDirectories) + libthrift.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj.filters b/src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj.filters new file mode 100644 index 000000000..3ec7bdefa --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/client.vcxproj.filters @@ -0,0 +1,66 @@ +? + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {1265b3dc-91de-416f-aba6-7b750de4221e} + + + + + + + + Header Files + + + Header Files + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + + + Source Files + + + Source Files + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files + + + diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.cpp b/src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.cpp new file mode 100644 index 000000000..4bd151ef0 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// client.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.h b/src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.h new file mode 100644 index 000000000..b005a839d --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/src/jaegertracing/thrift/contrib/transport-sample/client/targetver.h b/src/jaegertracing/thrift/contrib/transport-sample/client/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/client/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/src/jaegertracing/thrift/contrib/transport-sample/config.h b/src/jaegertracing/thrift/contrib/transport-sample/config.h new file mode 100644 index 000000000..a20d78513 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/config.h @@ -0,0 +1,24 @@ +//Missing definitions for *NIX systems. This sample project +//was initially created on Windows. + +#include +#include +#include + +#define TEXT(str) str + +inline int Sleep(int ms) +{ + return sleep(ms/1000); //sleep() param is in seconds +} + +inline int _tcscmp(const char* str1, const char* str2) +{ + return strcmp(str1, str2); +} + +inline int _tstoi(const char* str) +{ + return atoi(str); +} + diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/ReadMe.txt b/src/jaegertracing/thrift/contrib/transport-sample/server/ReadMe.txt new file mode 100644 index 000000000..53c0ee59b --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/ReadMe.txt @@ -0,0 +1,40 @@ +======================================================================== + CONSOLE APPLICATION : server Project Overview +======================================================================== + +AppWizard has created this server application for you. + +This file contains a summary of what you will find in each of the files that +make up your server application. + + +server.vcxproj + This is the main project file for VC++ projects generated using an Application Wizard. + It contains information about the version of Visual C++ that generated the file, and + information about the platforms, configurations, and project features selected with the + Application Wizard. + +server.vcxproj.filters + This is the filters file for VC++ projects generated using an Application Wizard. + It contains information about the association between the files in your project + and the filters. This association is used in the IDE to show grouping of files with + similar extensions under a specific node (for e.g. ".cpp" files are associated with the + "Source Files" filter). + +server.cpp + This is the main application source file. + +///////////////////////////////////////////////////////////////////////////// +Other standard files: + +StdAfx.h, StdAfx.cpp + These files are used to build a precompiled header (PCH) file + named server.pch and a precompiled types file named StdAfx.obj. + +///////////////////////////////////////////////////////////////////////////// +Other notes: + +AppWizard uses "TODO:" comments to indicate parts of the source code you +should add to or customize. + +///////////////////////////////////////////////////////////////////////////// diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/server.cpp b/src/jaegertracing/thrift/contrib/transport-sample/server/server.cpp new file mode 100644 index 000000000..dba8368b7 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/server.cpp @@ -0,0 +1,168 @@ +// server.cpp : Defines the entry point for the console application. +// +// sample server command line app using Thrift IPC. +// +// This is a simple demonstration of full duplex RPC. That is, each +// side runs both a client and server to enable bidirectional event +// signaling. +// + +#ifdef _WIN32 +# include "stdafx.h" +#else +# include "config.h" +#endif + +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//Include this before the generated includes +#include "ThriftCommon.h" +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +//Tailor these to your generated files +#include "../gen-cpp/SampleService.h" +#include "../gen-cpp/SampleCallback.h" + +using namespace Sample; //declared in .thrift file +//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +int16_t ClientPort_; +std::string ClientPipeName_; +void S2CThreadProc(); + +//----------------------------------------------------------------------------- +// RPC implementations +// +class SampleServiceHandler : virtual public SampleServiceIf { + public: + SampleServiceHandler() { + // Your initialization goes here + } + + void HelloThere(std::string& _return, const std::string& HelloString) { + // Your implementation goes here + printf("<<>>Connecting to client on port %d\n", ClientPort_); + boost::thread Connect2ClientThread(S2CThreadProc); +#endif + } + + void ClientSidePipeName(const std::string& ClientPipeName) + { + ClientPipeName_ = ClientPipeName; + ClientPort_ = 0; +#ifdef _WIN32 + printf(">>>Connecting to client pipe %s\n", ClientPipeName_.c_str()); + boost::thread Connect2ClientThread(S2CThreadProc); +#endif + } +}; +//----------------------------------------------------------------------------- + +#ifdef _WIN32 +int _tmain(int argc, _TCHAR* argv[]) +#else +int main(int argc, char **argv) +#endif +{ + int port; + std::string pipename; //e.g. "affpipe" + + bool usage = false; + + //Process command line params + if(argc > 1) + { + if(_tcscmp(argv[1], TEXT("-sp")) == 0) + { //Socket Port specified + port = _tstoi(argv[2]); +#ifdef _WIN32 + TWinsockSingleton::create(); +#endif + // Start the thrift server which is a blocking call. + thriftcommon::RunThriftServer(10, port); + } + else if(_tcscmp(argv[1], TEXT("-np")) == 0) + { //Named Pipe specified +#ifdef _WIN32 + std::wstring wpipe(argv[2]); + pipename.resize(wpipe.length()); + std::copy(wpipe.begin(), wpipe.end(), pipename.begin()); +#else + pipename = argv[2]; +#endif + printf("Using Named Pipe %s\n", pipename.c_str()); + + //Thrift over Named Pipe. + thriftcommon::RunThriftServer(10, pipename); + } + else if(_tcscmp(argv[1], TEXT("-ap")) == 0) + { //Anonymous Pipe specified + //This is more involved because the child needs to be launched + //after the transport is created but before the blocking server + //call. +#ifdef _WIN32 + boost::shared_ptr transport(new TPipeServer()); //Anonymous pipe + thriftcommon::LaunchAnonPipeChild(".\\client.exe", transport); + boost::shared_ptr handler(new SampleServiceHandler()); + thriftcommon::RunThriftServer(handler, 10, transport); +#else + printf("Anonymous pipes not (yet) supported under *NIX\n"); +#endif + } + else + usage = true; + } + else + usage = true; + + if(usage) + { + printf("Thrift sample server usage:\n\n"); + printf("Socket Port : -sp \n"); + printf("Named Pipe : -np (e.g. affpipe)\n"); + printf("Anonymous Pipe: -ap\n"); + } + return 0; +} + + +//Thread Routine that connects to the 'client'. +void S2CThreadProc() +{ + //Master server's connection to client-side's server. + boost::shared_ptr clientsrv; //Client class from Thrift-generated code. + boost::shared_ptr transport; + if(ClientPort_ != 0) + thriftcommon::ConnectToServer(clientsrv, transport, ClientPort_); + if(!ClientPipeName_.empty()) + thriftcommon::ConnectToServer(clientsrv, transport, ClientPipeName_); + + try { + transport->open(); + + clientsrv->pingclient(); + Sleep(1500); + clientsrv->pingclient(); + Sleep(1500); + clientsrv->pingclient(); + + transport->close(); + } catch (TException &tx) { + printf("ERROR: %s\n", tx.what()); + } +} + diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj b/src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj new file mode 100644 index 000000000..8e39b260e --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj @@ -0,0 +1,106 @@ +? + + + + Debug + Win32 + + + Release + Win32 + + + + {72FCAF29-506D-4164-9FA6-F54C5C28E79D} + Win32Proj + server + + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + true + + + false + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../;../../../lib/cpp/src;../../../../Boost/;../../../../Boost/boost/tr1;%(AdditionalIncludeDirectories) + + + Console + true + ../../../lib/cpp/$(Configuration);../../../../Boost/lib;%(AdditionalLibraryDirectories) + libthrift.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + Level3 + NotUsing + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + ../;../../../lib/cpp/src;../../../../Boost/;../../../../Boost/boost/tr1;%(AdditionalIncludeDirectories) + + + Console + true + true + true + ../../../lib/cpp/$(Configuration);../../../../Boost/lib;%(AdditionalLibraryDirectories) + libthrift.lib;ws2_32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + + Create + Create + + + + + + \ No newline at end of file diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj.filters b/src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj.filters new file mode 100644 index 000000000..8bb6dfb73 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/server.vcxproj.filters @@ -0,0 +1,66 @@ +? + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {dab66db8-bc45-4518-aad2-7a75696226e3} + + + + + + + + Header Files + + + Header Files + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + + + Source Files + + + Source Files + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files\gen-cpp + + + Source Files + + + diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.cpp b/src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.cpp new file mode 100644 index 000000000..c25ff612a --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.cpp @@ -0,0 +1,8 @@ +// stdafx.cpp : source file that includes just the standard includes +// server.pch will be the pre-compiled header +// stdafx.obj will contain the pre-compiled type information + +#include "stdafx.h" + +// TODO: reference any additional headers you need in STDAFX.H +// and not in this file diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.h b/src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.h new file mode 100644 index 000000000..b005a839d --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/stdafx.h @@ -0,0 +1,15 @@ +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently +// + +#pragma once + +#include "targetver.h" + +#include +#include + + + +// TODO: reference additional headers your program requires here diff --git a/src/jaegertracing/thrift/contrib/transport-sample/server/targetver.h b/src/jaegertracing/thrift/contrib/transport-sample/server/targetver.h new file mode 100644 index 000000000..87c0086de --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/server/targetver.h @@ -0,0 +1,8 @@ +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include diff --git a/src/jaegertracing/thrift/contrib/transport-sample/thriftme.bat b/src/jaegertracing/thrift/contrib/transport-sample/thriftme.bat new file mode 100644 index 000000000..4b1ef78c8 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/thriftme.bat @@ -0,0 +1 @@ +thrift.exe --gen cpp Sample.thrift diff --git a/src/jaegertracing/thrift/contrib/transport-sample/thriftme.sh b/src/jaegertracing/thrift/contrib/transport-sample/thriftme.sh new file mode 100644 index 000000000..3b18f909e --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/thriftme.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +THRIFT_COMPILER=./thrift +OUTPUT_FOLDER=$PWD + +if [ ! -e "${THRIFT_COMPILER}" ] +then + THRIFT_COMPILER=thrift + command -v ${THRIFT_COMPILER} >/dev/null 2>&1 + if [ $? -eq 1 ]; then + echo + echo "thrift compiler not found." + echo + exit + fi +fi + +${THRIFT_COMPILER} --gen cpp Sample.thrift + +echo +echo "Files have been generated in gen-cpp." + +exit + diff --git a/src/jaegertracing/thrift/contrib/transport-sample/transport-sample.sln b/src/jaegertracing/thrift/contrib/transport-sample/transport-sample.sln new file mode 100644 index 000000000..a9fa1efa1 --- /dev/null +++ b/src/jaegertracing/thrift/contrib/transport-sample/transport-sample.sln @@ -0,0 +1,26 @@ +? +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "server", "server\server.vcxproj", "{72FCAF29-506D-4164-9FA6-F54C5C28E79D}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client", "client\client.vcxproj", "{85FBFB54-530B-498F-9F38-44BA204FAE6A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {72FCAF29-506D-4164-9FA6-F54C5C28E79D}.Debug|Win32.ActiveCfg = Debug|Win32 + {72FCAF29-506D-4164-9FA6-F54C5C28E79D}.Debug|Win32.Build.0 = Debug|Win32 + {72FCAF29-506D-4164-9FA6-F54C5C28E79D}.Release|Win32.ActiveCfg = Release|Win32 + {72FCAF29-506D-4164-9FA6-F54C5C28E79D}.Release|Win32.Build.0 = Release|Win32 + {85FBFB54-530B-498F-9F38-44BA204FAE6A}.Debug|Win32.ActiveCfg = Debug|Win32 + {85FBFB54-530B-498F-9F38-44BA204FAE6A}.Debug|Win32.Build.0 = Debug|Win32 + {85FBFB54-530B-498F-9F38-44BA204FAE6A}.Release|Win32.ActiveCfg = Release|Win32 + {85FBFB54-530B-498F-9F38-44BA204FAE6A}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal -- cgit v1.2.3