From b09f58838f78e8c8ef411a6db052da8db1f9dc05 Mon Sep 17 00:00:00 2001 From: Marc Slemko Date: Wed, 23 Aug 2006 22:03:34 +0000 Subject: [PATCH] Uber configure.ac/Makefile.am and configure.ac/Makefile.am for lib/php and compiler Modified TProtocol.h et al to take collection size as unsigned int. This removes need to cast STL's default size_t to signed int and is more correct, since collection sizes cannot be < 0 by definition Moved compiler/Makefile to compiler/cpp.mk so it doesn't get trashed by automake git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664766 13f79535-47bb-0310-9956-ffa450edef68 --- bootstrap.sh | 51 ++++++ compiler/Makefile.am | 2 + compiler/bootstrap.sh | 36 ++++ compiler/configure.ac | 13 ++ compiler/{Makefile => cpp.mk} | 0 compiler/src/cpp_generator.py | 55 +++++- compiler/src/php_generator.py | 11 +- compiler/src/thrift | 11 +- configure.ac | 13 ++ lib/cpp/configure.ac | 2 +- lib/cpp/src/protocol/TBinaryProtocol.cc | 28 ++-- lib/cpp/src/protocol/TBinaryProtocol.h | 12 +- lib/cpp/src/protocol/TProtocol.h | 18 +- lib/cpp/src/test/Makefile | 2 +- lib/cpp/src/test/StressTest.thrift | 4 + lib/cpp/src/test/main.cc | 211 +++++++++++++----------- lib/php/Makefile.am | 17 ++ lib/php/bootstrap.sh | 36 ++++ lib/php/configure.ac | 11 ++ test/cpp/Makefile | 5 +- 20 files changed, 399 insertions(+), 139 deletions(-) create mode 100755 bootstrap.sh create mode 100644 compiler/Makefile.am create mode 100755 compiler/bootstrap.sh create mode 100644 compiler/configure.ac rename compiler/{Makefile => cpp.mk} (100%) create mode 100644 configure.ac create mode 100644 lib/php/Makefile.am create mode 100755 lib/php/bootstrap.sh create mode 100644 lib/php/configure.ac diff --git a/bootstrap.sh b/bootstrap.sh new file mode 100755 index 00000000..fe07addf --- /dev/null +++ b/bootstrap.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +subdirs="compiler lib/cpp lib/php" + +rm -rf \ +AUTHORS \ +COPYING \ +ChangeLog \ +INSTALL \ +Makefile.am \ +Makefile \ +Makefile.in \ +Makefile.orig \ +NEWS \ +README \ +aclocal.m4 \ +autom4te.cache \ +autoscan.log \ +config.guess \ +config.h \ +config.hin \ +config.log \ +config.status \ +config.sub \ +configure \ +configure.scan \ +depcomp \ +.deps \ +install-sh \ +.libs \ +libtool \ +ltmain.sh \ +Makefile.in \ +missing + +echo "SUBDIRS = ${subdirs}" > Makefile.am + +aclocal +touch NEWS README AUTHORS ChangeLog +autoconf +automake -ac + +for subdir in ${subdirs}; do + if [ -x "${subdir}/bootstrap.sh" ]; then + cwd="`pwd`" + cd ${subdir} + ./bootstrap.sh + cd ${cwd} + fi +done + diff --git a/compiler/Makefile.am b/compiler/Makefile.am new file mode 100644 index 00000000..8b84d0a3 --- /dev/null +++ b/compiler/Makefile.am @@ -0,0 +1,2 @@ +install-exec-hook: + $(PYTHON) setup.py install install_scripts --install-dir=$(bindir) diff --git a/compiler/bootstrap.sh b/compiler/bootstrap.sh new file mode 100755 index 00000000..11f41a9a --- /dev/null +++ b/compiler/bootstrap.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +rm -rf \ +AUTHORS \ +COPYING \ +ChangeLog \ +INSTALL \ +Makefile \ +Makefile.in \ +Makefile.orig \ +NEWS \ +README \ +aclocal.m4 \ +autom4te.cache \ +autoscan.log \ +config.guess \ +config.h \ +config.hin \ +config.log \ +config.status \ +config.sub \ +configure \ +configure.scan \ +depcomp \ +.deps \ +install-sh \ +.libs \ +libtool \ +ltmain.sh \ +Makefile.in \ +missing + +aclocal +touch NEWS README AUTHORS ChangeLog +autoconf +automake -ac diff --git a/compiler/configure.ac b/compiler/configure.ac new file mode 100644 index 00000000..dcc7bf2f --- /dev/null +++ b/compiler/configure.ac @@ -0,0 +1,13 @@ +AC_PREREQ(2.59) + +AC_INIT([compiler], [1.0]) + +AC_CONFIG_AUX_DIR([.]) + +AM_INIT_AUTOMAKE + +AM_PATH_PYTHON(2.4,, :) + +AC_CONFIG_FILES([Makefile]) + +AC_OUTPUT diff --git a/compiler/Makefile b/compiler/cpp.mk similarity index 100% rename from compiler/Makefile rename to compiler/cpp.mk diff --git a/compiler/src/cpp_generator.py b/compiler/src/cpp_generator.py index ba3380e8..97a5f360 100644 --- a/compiler/src/cpp_generator.py +++ b/compiler/src/cpp_generator.py @@ -871,15 +871,22 @@ uint32_t read_${suffix}("""+CPP_PROTOCOLP+""" iprot, """+CPP_TRANSPORTP+""" itra ${keyType} key; ${valueType} elem; uint32_t xfer = 0; + """+CPP_PROTOCOL_TTYPE+""" keyType; + """+CPP_PROTOCOL_TTYPE+""" valueType; - xfer += iprot->readU32(itrans, count); + xfer += iprot->readMapBegin(itrans, keyType, valueType, count); + /* XXX + Should we assert that read key and value type are correct? */ + for(uint32_t ix = 0; ix < count; ix++) { ${keyReaderCall}; ${valueReaderCall}; value.insert(std::make_pair(key, elem)); } + xfer += iprot->readMapEnd(itrans); + return xfer; } """) @@ -889,12 +896,14 @@ uint32_t write_${suffix}("""+CPP_PROTOCOLP+""" oprot, """+CPP_TRANSPORTP+""" otr uint32_t xfer = 0; - xfer += oprot->writeU32(otrans, value.size()); + xfer += oprot->writeMapBegin(otrans, ${keyWireType}, ${valueWireType}, value.size()); for(${declaration}::const_iterator ix = value.begin(); ix != value.end(); ++ix) { ${keyWriterCall}; ${valueWriterCall}; } + + xfer += oprot->writeMapEnd(otrans); return xfer; } """) @@ -905,6 +914,12 @@ uint32_t read_${suffix}("""+CPP_PROTOCOLP+""" iprot, """+CPP_TRANSPORTP+""" itra uint32_t count; ${valueType} elem; uint32_t xfer = 0; + """+CPP_PROTOCOL_TTYPE+""" valueType; + + xfer += iprot->read${protocolSuffix}Begin(itrans, valueType, count); + + /* XXX + Should we assert that read value type is correct? */ xfer+= iprot->readU32(itrans, count); @@ -912,6 +927,8 @@ uint32_t read_${suffix}("""+CPP_PROTOCOLP+""" iprot, """+CPP_TRANSPORTP+""" itra ${valueReaderCall}; value.${insert}(elem); } + + xfer += iprot->read${protocolSuffix}End(itrans); return xfer; } """) @@ -921,11 +938,14 @@ uint32_t write_${suffix}("""+CPP_PROTOCOLP+""" oprot, """+CPP_TRANSPORTP+""" otr uint32_t xfer = 0; - xfer+= oprot->writeU32(otrans, value.size()); + xfer+= oprot->write${protocolSuffix}Begin(otrans, ${valueWireType}, value.size()); for(${declaration}::const_iterator ix = value.begin(); ix != value.end(); ++ix) { ${valueWriterCall}; } + + xfer+= oprot->write${protocolSuffix}End(otrans); + return xfer; } """) @@ -949,11 +969,14 @@ def toCollectionReaderDefinition(collection): else: if isinstance(collection, ListType): + protocolSuffix="List" insert="push_back" else: + protocolSuffix="Set" insert="insert" return CPP_READ_LIST_DEFINITION.substitute(suffix=suffix, declaration=toCTypeDeclaration(collection), + protocolSuffix=protocolSuffix, valueReaderCall=valueReaderCall, valueType=toCTypeDeclaration(collection.valueType), insert=insert) @@ -966,22 +989,36 @@ def toCollectionWriterDefinition(collection): if isinstance(collection, MapType): keyWriterCall = toWriterCall("ix->first", collection.keyType) + keyWireType = toWireType(collection.keyType) valueWriterCall = toWriterCall("ix->second", collection.valueType) else: valueWriterCall= toWriterCall("*ix", collection.valueType) + valueWireType = toWireType(collection.valueType) + if isinstance(collection, MapType): return CPP_WRITE_MAP_DEFINITION.substitute(suffix=suffix, declaration=toCTypeDeclaration(collection), - keyType=toCTypeDeclaration(collection.keyType), - keyWriterCall=keyWriterCall, - valueType=toCTypeDeclaration(collection.valueType), - valueWriterCall=valueWriterCall) + keyType=toCTypeDeclaration(collection.keyType), + keyWireType=keyWireType, + keyWriterCall=keyWriterCall, + valueType=toCTypeDeclaration(collection.valueType), + valueWireType=valueWireType, + valueWriterCall=valueWriterCall) else: + if isinstance(collection, ListType): + protocolSuffix = "List" + elif isinstance(collection, SetType): + protocolSuffix = "Set" + else: + raise Exception, "Unknown collection type "+str(type(collection))+":"+str(collection) + return CPP_WRITE_LIST_DEFINITION.substitute(suffix=suffix, declaration=toCTypeDeclaration(collection), - valueWriterCall=valueWriterCall, - valueType=toCTypeDeclaration(collection.valueType)) + protocolSuffix=protocolSuffix, + valueWireType=valueWireType, + valueWriterCall=valueWriterCall, + valueType=toCTypeDeclaration(collection.valueType)) CPP_READ_STRUCT_DEFINITION = Template(""" diff --git a/compiler/src/php_generator.py b/compiler/src/php_generator.py index e68a4f73..71b1fd38 100644 --- a/compiler/src/php_generator.py +++ b/compiler/src/php_generator.py @@ -329,8 +329,6 @@ class Reader(CodeGenerator): result+= self.toReadStructEnd() - result+= self.indent()+"return "+value+";\n" - return result def toReadCollection(self, value, collection): @@ -631,12 +629,17 @@ class ClientFunctionGenerator(CodeGenerator): result+= self.indent()+"}\n" + result+= self.reader.toReadMessageEnd() + + if not isVoidType(function.returnType()): + result+= self.indent()+"return "+resultVar.name+"->success;\n" + else: + result+= self.indent()+"return;\n" + self.indent-= 1 self.oldScope() - result+= self.reader.toReadMessageEnd() - result+= self.indent()+"}\n" return result diff --git a/compiler/src/thrift b/compiler/src/thrift index 39bdb162..6c252d9a 100644 --- a/compiler/src/thrift +++ b/compiler/src/thrift @@ -1,16 +1,20 @@ #!python import sys -from thrift import cpp_generator from thrift import generator +from thrift import cpp_generator +from thrift import php_generator from thrift import parser -def thrift(source, cpp=False, perl=False, php=False, python=False, java=False, ruby=False, debug=False): +def thrift(source, cpp=False, java=False, perl=False, php=False, python=False, ruby=False, debug=False): generators = [] if cpp: generators.append(cpp_generator.CPPGenerator()) + if php: + generators.append(php_generator.PHPGenerator()) + p = parser.Parser(debug=debug) p.parse(source, False) @@ -37,6 +41,9 @@ def main(args): if "--cpp" in args: cpp = True args.remove("--cpp") + if "--php" in args: + php = True + args.remove("--php") if "--debug" in args: debug = True args.remove("--debug") diff --git a/configure.ac b/configure.ac new file mode 100644 index 00000000..54f19603 --- /dev/null +++ b/configure.ac @@ -0,0 +1,13 @@ +AC_PREREQ(2.59) + +AC_INIT([thrift], [1.0]) + +AC_CONFIG_AUX_DIR([.]) + +AM_INIT_AUTOMAKE + +AC_CONFIG_FILES([Makefile]) + +AC_CONFIG_SUBDIRS([compiler lib/cpp lib/php]) + +AC_OUTPUT diff --git a/lib/cpp/configure.ac b/lib/cpp/configure.ac index b854ebd9..d571ba02 100644 --- a/lib/cpp/configure.ac +++ b/lib/cpp/configure.ac @@ -1,6 +1,6 @@ AC_PREREQ(2.59) -AC_INIT(thrift, 1.0) +AC_INIT(thriftcpp, 1.0) AC_CONFIG_SRCDIR(src/Thrift.h) diff --git a/lib/cpp/src/protocol/TBinaryProtocol.cc b/lib/cpp/src/protocol/TBinaryProtocol.cc index 3cd11ba0..f2fbe873 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.cc +++ b/lib/cpp/src/protocol/TBinaryProtocol.cc @@ -48,11 +48,11 @@ uint32_t TBinaryProtocol::writeFieldStop(shared_ptr out) const { uint32_t TBinaryProtocol::writeMapBegin(shared_ptr out, const TType keyType, const TType valType, - const int32_t size) const { + const uint32_t size) const { return writeByte(out, (uint8_t)keyType) + writeByte(out, (uint8_t)valType) + - writeI32(out, (int32_t)size); + writeU32(out, (uint32_t)size); } uint32_t TBinaryProtocol::writeMapEnd(shared_ptr out) const { @@ -61,10 +61,10 @@ uint32_t TBinaryProtocol::writeMapEnd(shared_ptr out) const { uint32_t TBinaryProtocol::writeListBegin(shared_ptr out, const TType elemType, - const int32_t size) const { + const uint32_t size) const { return writeByte(out, (uint8_t) elemType) + - writeI32(out, (int32_t)size); + writeU32(out, (int32_t)size); } uint32_t TBinaryProtocol::writeListEnd(shared_ptr out) const { @@ -73,10 +73,10 @@ uint32_t TBinaryProtocol::writeListEnd(shared_ptr out) const { uint32_t TBinaryProtocol::writeSetBegin(shared_ptr out, const TType elemType, - const int32_t size) const { + const uint32_t size) const { return writeByte(out, (uint8_t)elemType) + - writeI32(out, (int32_t)size); + writeU32(out, (int32_t)size); } uint32_t TBinaryProtocol::writeSetEnd(shared_ptr out) const { @@ -200,14 +200,14 @@ uint32_t TBinaryProtocol::readFieldEnd(shared_ptr in) const { uint32_t TBinaryProtocol::readMapBegin(shared_ptr in, TType& keyType, TType& valType, - int32_t& size) const { + uint32_t& size) const { uint8_t k, v; uint32_t result = 0; result += readByte(in, k); keyType = (TType)k; result += readByte(in, v); valType = (TType)v; - result += readI32(in, size); + result += readU32(in, size); return result; } @@ -217,12 +217,12 @@ uint32_t TBinaryProtocol::readMapEnd(shared_ptr in) const { uint32_t TBinaryProtocol::readListBegin(shared_ptr in, TType& elemType, - int32_t& size) const { + uint32_t& size) const { uint8_t e; uint32_t result = 0; result += readByte(in, e); elemType = (TType)e; - result += readI32(in, size); + result += readU32(in, size); return result; } @@ -232,12 +232,12 @@ uint32_t TBinaryProtocol::readListEnd(shared_ptr in) const { uint32_t TBinaryProtocol::readSetBegin(shared_ptr in, TType& elemType, - int32_t& size) const { + uint32_t& size) const { uint8_t e; uint32_t result = 0; result += readByte(in, e); elemType = (TType)e; - result += readI32(in, size); + result += readU32(in, size); return result; } @@ -318,8 +318,8 @@ uint32_t TBinaryProtocol::readI64(shared_ptr in, uint32_t TBinaryProtocol::readString(shared_ptr in, string& str) const { uint32_t result; - int32_t size; - result = readI32(in, size); + uint32_t size; + result = readU32(in, size); // Use the heap here to prevent stack overflow for v. large strings uint8_t *b = new uint8_t[size]; diff --git a/lib/cpp/src/protocol/TBinaryProtocol.h b/lib/cpp/src/protocol/TBinaryProtocol.h index 480182d5..7780f168 100644 --- a/lib/cpp/src/protocol/TBinaryProtocol.h +++ b/lib/cpp/src/protocol/TBinaryProtocol.h @@ -49,19 +49,19 @@ using namespace boost; uint32_t writeMapBegin(shared_ptr out, const TType keyType, const TType valType, - const int32_t size) const; + const uint32_t size) const; uint32_t writeMapEnd(shared_ptr out) const; uint32_t writeListBegin(shared_ptr out, const TType elemType, - const int32_t size) const; + const uint32_t size) const; uint32_t writeListEnd(shared_ptr out) const; uint32_t writeSetBegin(shared_ptr out, const TType elemType, - const int32_t size) const; + const uint32_t size) const; uint32_t writeSetEnd(shared_ptr out) const; @@ -119,19 +119,19 @@ using namespace boost; uint32_t readMapBegin(shared_ptr in, TType& keyType, TType& valType, - int32_t& size) const; + uint32_t& size) const; uint32_t readMapEnd(shared_ptr in) const; uint32_t readListBegin(shared_ptr in, TType& elemType, - int32_t& size) const; + uint32_t& size) const; uint32_t readListEnd(shared_ptr in) const; uint32_t readSetBegin(shared_ptr in, TType& elemType, - int32_t& size) const; + uint32_t& size) const; uint32_t readSetEnd(shared_ptr in) const; diff --git a/lib/cpp/src/protocol/TProtocol.h b/lib/cpp/src/protocol/TProtocol.h index 7dbb4a09..38c53479 100644 --- a/lib/cpp/src/protocol/TProtocol.h +++ b/lib/cpp/src/protocol/TProtocol.h @@ -103,19 +103,19 @@ class TProtocol { virtual uint32_t writeMapBegin(shared_ptr out, const TType keyType, const TType valType, - const int32_t size) const = 0; + const uint32_t size) const = 0; virtual uint32_t writeMapEnd(shared_ptr out) const = 0; virtual uint32_t writeListBegin(shared_ptr out, const TType elemType, - const int32_t size) const = 0; + const uint32_t size) const = 0; virtual uint32_t writeListEnd(shared_ptr out) const = 0; virtual uint32_t writeSetBegin(shared_ptr out, const TType elemType, - const int32_t size) const = 0; + const uint32_t size) const = 0; virtual uint32_t writeSetEnd(shared_ptr out) const = 0; @@ -172,19 +172,19 @@ class TProtocol { virtual uint32_t readMapBegin(shared_ptr in, TType& keyType, TType& valType, - int32_t& size) const = 0; + uint32_t& size) const = 0; virtual uint32_t readMapEnd(shared_ptr in) const = 0; virtual uint32_t readListBegin(shared_ptr in, TType& elemType, - int32_t& size) const = 0; + uint32_t& size) const = 0; virtual uint32_t readListEnd(shared_ptr in) const = 0; virtual uint32_t readSetBegin(shared_ptr in, TType& elemType, - int32_t& size) const = 0; + uint32_t& size) const = 0; virtual uint32_t readSetEnd(shared_ptr in) const = 0; @@ -273,7 +273,7 @@ class TProtocol { uint32_t result = 0; TType keyType; TType valType; - int32_t i, size; + uint32_t i, size; result += readMapBegin(in, keyType, valType, size); for (i = 0; i < size; i++) { result += skip(in, keyType); @@ -286,7 +286,7 @@ class TProtocol { { uint32_t result = 0; TType elemType; - int32_t i, size; + uint32_t i, size; result += readSetBegin(in, elemType, size); for (i = 0; i < size; i++) { result += skip(in, elemType); @@ -298,7 +298,7 @@ class TProtocol { { uint32_t result = 0; TType elemType; - int32_t i, size; + uint32_t i, size; result += readListBegin(in, elemType, size); for (i = 0; i < size; i++) { result += skip(in, elemType); diff --git a/lib/cpp/src/test/Makefile b/lib/cpp/src/test/Makefile index 73206cd7..9b150953 100644 --- a/lib/cpp/src/test/Makefile +++ b/lib/cpp/src/test/Makefile @@ -38,7 +38,7 @@ all: stress-test debug: stress-test-debug stubs: StressTest.thrift - $(THRIFT) --cpp StressTest.thrift + $(THRIFT) --cpp --php StressTest.thrift stress-test-debug: stubs g++ -o stress-test $(DCFL) main.cc cpp-gen/StressTest.cc diff --git a/lib/cpp/src/test/StressTest.thrift b/lib/cpp/src/test/StressTest.thrift index 89e2f9b2..3d2f9d82 100644 --- a/lib/cpp/src/test/StressTest.thrift +++ b/lib/cpp/src/test/StressTest.thrift @@ -7,5 +7,9 @@ service Service { u16 echoU16(u16 arg), u32 echoU32(u32 arg), u64 echoU64(u64 arg), + string echoString(string arg), + list echoList(list arg), + set echoSet(set arg), + map echoMap(map arg), } diff --git a/lib/cpp/src/test/main.cc b/lib/cpp/src/test/main.cc index 51ac38a9..69a6eb05 100644 --- a/lib/cpp/src/test/main.cc +++ b/lib/cpp/src/test/main.cc @@ -34,6 +34,10 @@ class Server : public ServiceServerIf { uint16_t echoU16(uint16_t arg) {return arg;} uint32_t echoU32(uint32_t arg) {return arg;} uint64_t echoU64(uint64_t arg) {return arg;} + string echoString(string arg) {return arg;} + list echoList(list arg) {return arg;} + set echoSet(set arg) {return arg;} + map echoMap(map arg) {return arg;} }; class ClientThread: public Runnable { @@ -107,17 +111,20 @@ int main(int argc, char **argv) { size_t workerCount = 4; size_t clientCount = 10; size_t loopCount = 10000; + bool runServer = true; - ostringstream usage; + ostringstream usage; usage << - argv[0] << " [--port=] [--server-type=] [--protocol-type=] [--workers=]" << endl << - - "\t\tserver-type\t\ttype of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl << - - "\t\tprotocol-type\t\ttype of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl << - - "\t\tworkers\t\tNumber of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl; + argv[0] << " [--port=] [--server] [--server-type=] [--protocol-type=] [--workers=] [--clients=] [--loop=]" << endl << + "\tclients Number of client threads to create - 0 implies no clients, i.e. server only. Default is " << clientCount << endl << + "\thelp Prints this help text." << endl << + "\tloop The number of remote thrift calls each client makes. Default is " << loopCount << endl << + "\tport The port the server and clients should bind to for thrift network connections. Default is " << port << endl << + "\tserver Run the Thrift server in this process. Default is " << runServer << endl << + "\tserver-type Type of server, \"simple\" or \"thread-pool\". Default is " << serverType << endl << + "\tprotocol-type Type of protocol, \"binary\", \"ascii\", or \"xml\". Default is " << protocolType << endl << + "\tworkers Number of thread pools workers. Only valid for thread-pool server type. Default is " << workerCount << endl; map args; @@ -143,10 +150,27 @@ int main(int argc, char **argv) { try { + if(!args["clients"].empty()) { + clientCount = atoi(args["clients"].c_str()); + } + + if(!args["help"].empty()) { + cerr << usage.str(); + return 0; + } + + if(!args["loop"].empty()) { + loopCount = atoi(args["loop"].c_str()); + } + if(!args["port"].empty()) { port = atoi(args["port"].c_str()); } + if(!args["server"].empty()) { + runServer = args["server"] == "true"; + } + if(!args["server-type"].empty()) { serverType = args["server-type"]; @@ -164,138 +188,141 @@ int main(int argc, char **argv) { workerCount = atoi(args["workers"].c_str()); } - if(!args["clients"].empty()) { - clientCount = atoi(args["clients"].c_str()); - } - - if(!args["loop"].empty()) { - loopCount = atoi(args["loop"].c_str()); - } } catch(exception& e) { cerr << e.what() << endl; cerr << usage; } - // Dispatcher - shared_ptr binaryProtocol(new TBinaryProtocol); + shared_ptr threadFactory = shared_ptr(new PosixThreadFactory()); - shared_ptr server(new Server(binaryProtocol)); + if(runServer) { - // Options - shared_ptr serverOptions(new TServerOptions()); + // Dispatcher + shared_ptr binaryProtocol(new TBinaryProtocol); - // Transport - shared_ptr serverSocket(new TServerSocket(port)); + shared_ptr server(new Server(binaryProtocol)); - // ThreadFactory + // Options + shared_ptr serverOptions(new TServerOptions()); - shared_ptr threadFactory = shared_ptr(new PosixThreadFactory()); + // Transport + shared_ptr serverSocket(new TServerSocket(port)); - shared_ptr serverThread; + // ThreadFactory + + shared_ptr serverThread; + + if(serverType == "simple") { + + serverThread = threadFactory->newThread(shared_ptr(new TSimpleServer(server, serverOptions, serverSocket))); + + } else if(serverType == "thread-pool") { - if(serverType == "simple") { + shared_ptr threadManager = ThreadManager::newSimpleThreadManager(workerCount); - serverThread = threadFactory->newThread(shared_ptr(new TSimpleServer(server, serverOptions, serverSocket))); + threadManager->threadFactory(threadFactory); - } else if(serverType == "thread-pool") { + threadManager->start(); - shared_ptr threadManager = ThreadManager::newSimpleThreadManager(workerCount); + serverThread = threadFactory->newThread(shared_ptr(new TThreadPoolServer(server, + serverOptions, + serverSocket, + threadManager))); + } - threadManager->threadFactory(threadFactory); + cerr << "Starting the server on port " << port << endl; - threadManager->start(); + serverThread->start(); + + // If we aren't running clients, just wait forever for external clients - serverThread = threadFactory->newThread(shared_ptr(new TThreadPoolServer(server, - serverOptions, - serverSocket, - threadManager))); + if(clientCount == 0) { + serverThread->join(); + } } - cerr << "Starting the server on port " << port << endl; + if(clientCount > 0) { - serverThread->start(); + Monitor monitor; - Monitor monitor; + size_t threadCount = 0; - size_t threadCount = 0; + set > clientThreads; - set > clientThreads; - - for(size_t ix = 0; ix < clientCount; ix++) { + for(size_t ix = 0; ix < clientCount; ix++) { - shared_ptr socket(new TSocket("127.0.01", port)); - shared_ptr bufferedSocket(new TBufferedTransport(socket, 2048)); - shared_ptr binaryProtocol(new TBinaryProtocol()); - shared_ptr serviceClient(new ServiceClient(bufferedSocket, binaryProtocol)); + shared_ptr socket(new TSocket("127.0.01", port)); + shared_ptr bufferedSocket(new TBufferedTransport(socket, 2048)); + shared_ptr binaryProtocol(new TBinaryProtocol()); + shared_ptr serviceClient(new ServiceClient(bufferedSocket, binaryProtocol)); - clientThreads.insert(threadFactory->newThread(shared_ptr(new ClientThread(bufferedSocket, serviceClient, monitor, threadCount, loopCount)))); - } + clientThreads.insert(threadFactory->newThread(shared_ptr(new ClientThread(bufferedSocket, serviceClient, monitor, threadCount, loopCount)))); + } - for(std::set >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) { - (*thread)->start(); - } - - cerr << endl; + for(std::set >::const_iterator thread = clientThreads.begin(); thread != clientThreads.end(); thread++) { + (*thread)->start(); + } - long long time00; - long long time01; + long long time00; + long long time01; - {Synchronized s(monitor); - threadCount = clientCount; + {Synchronized s(monitor); + threadCount = clientCount; - cerr << "Launch "<< clientCount << " client threads" << endl; + cerr << "Launch "<< clientCount << " client threads" << endl; - time00 = Util::currentTime(); + time00 = Util::currentTime(); - monitor.notifyAll(); + monitor.notifyAll(); + + while(threadCount > 0) { + monitor.wait(); + } - while(threadCount > 0) { - monitor.wait(); + time01 = Util::currentTime(); } - - time01 = Util::currentTime(); - } - long long firstTime = 9223372036854775807LL; - long long lastTime = 0; + long long firstTime = 9223372036854775807LL; + long long lastTime = 0; - double averageTime = 0; - long long minTime = 9223372036854775807LL; - long long maxTime = 0; + double averageTime = 0; + long long minTime = 9223372036854775807LL; + long long maxTime = 0; - for(set >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) { + for(set >::iterator ix = clientThreads.begin(); ix != clientThreads.end(); ix++) { - shared_ptr client = dynamic_pointer_cast((*ix)->runnable()); + shared_ptr client = dynamic_pointer_cast((*ix)->runnable()); - long long delta = client->_endTime - client->_startTime; + long long delta = client->_endTime - client->_startTime; - assert(delta > 0); + assert(delta > 0); - if(client->_startTime < firstTime) { - firstTime = client->_startTime; - } + if(client->_startTime < firstTime) { + firstTime = client->_startTime; + } - if(client->_endTime > lastTime) { - lastTime = client->_endTime; - } + if(client->_endTime > lastTime) { + lastTime = client->_endTime; + } - if(delta < minTime) { - minTime = delta; - } + if(delta < minTime) { + minTime = delta; + } - if(delta > maxTime) { - maxTime = delta; - } + if(delta > maxTime) { + maxTime = delta; + } - averageTime+= delta; - } + averageTime+= delta; + } - averageTime /= clientCount; + averageTime /= clientCount; - - cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl; - cerr << "done." << endl; + cout << "workers :" << workerCount << ", client : " << clientCount << ", loops : " << loopCount << ", rate : " << (clientCount * loopCount * 1000) / ((double)(time01 - time00)) << endl; + + cerr << "done." << endl; + } return 0; } diff --git a/lib/php/Makefile.am b/lib/php/Makefile.am new file mode 100644 index 00000000..23208d9f --- /dev/null +++ b/lib/php/Makefile.am @@ -0,0 +1,17 @@ +thrift_SCRIPTS = src/Thrift.php + +protocol_SCRIPTS = src/protocol/TProtocol.php \ + src/protocol/TBinaryProtocol.php \ + src/protocol/TType.php + +transport_SCRIPTS = src/transport/TTransport.php \ + src/transport/TBufferedTransport.php \ + src/transport/TChunkedTransport.php \ + src/transport/TSocket.php + +thriftdir = $(prefix)/php/thrift + +protocoldir = $(thriftdir)/protocol + +transportdir = $(thriftdir)/transport + diff --git a/lib/php/bootstrap.sh b/lib/php/bootstrap.sh new file mode 100755 index 00000000..11f41a9a --- /dev/null +++ b/lib/php/bootstrap.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +rm -rf \ +AUTHORS \ +COPYING \ +ChangeLog \ +INSTALL \ +Makefile \ +Makefile.in \ +Makefile.orig \ +NEWS \ +README \ +aclocal.m4 \ +autom4te.cache \ +autoscan.log \ +config.guess \ +config.h \ +config.hin \ +config.log \ +config.status \ +config.sub \ +configure \ +configure.scan \ +depcomp \ +.deps \ +install-sh \ +.libs \ +libtool \ +ltmain.sh \ +Makefile.in \ +missing + +aclocal +touch NEWS README AUTHORS ChangeLog +autoconf +automake -ac diff --git a/lib/php/configure.ac b/lib/php/configure.ac new file mode 100644 index 00000000..d32321e6 --- /dev/null +++ b/lib/php/configure.ac @@ -0,0 +1,11 @@ +AC_PREREQ(2.59) + +AC_INIT([thriftphp], [1.0]) + +AC_CONFIG_AUX_DIR([.]) + +AM_INIT_AUTOMAKE + +AC_CONFIG_FILES([Makefile]) + +AC_OUTPUT diff --git a/test/cpp/Makefile b/test/cpp/Makefile index cec9699b..f95401cf 100644 --- a/test/cpp/Makefile +++ b/test/cpp/Makefile @@ -22,7 +22,10 @@ include_paths = $(thrift_home)/include/thrift \ include_flags = $(patsubst %,-I%, $(include_paths)) # Tools -THRIFT = python ../../compiler/src/thrift.py ~/ws/thrift/dev/test/ThriftTest.thrift +ifndef THRIFT +THRIFT = thrift +endif # THRIFT + CC = g++ LD = g++ -- 2.17.1