MCPcopy Create free account
hub / github.com/apache/thrift / createConnection

Method createConnection

lib/cpp/src/thrift/server/TNonblockingServer.cpp:912–937  ·  view source on GitHub ↗

* Creates a new connection either by reusing an object off the stack or * by allocating a new one entirely */

Source from the content-addressed store, hash-verified

910 * by allocating a new one entirely
911 */
912TNonblockingServer::TConnection* TNonblockingServer::createConnection(std::shared_ptr<TSocket> socket) {
913 // Check the stack
914 Guard g(connMutex_);
915
916 // pick an IO thread to handle this connection -- currently round robin
917 assert(nextIOThread_ < ioThreads_.size());
918 int selectedThreadIdx = nextIOThread_;
919 nextIOThread_ = static_cast<uint32_t>((nextIOThread_ + 1) % ioThreads_.size());
920
921 TNonblockingIOThread* ioThread = ioThreads_[selectedThreadIdx].get();
922
923 // Check the connection stack to see if we can re-use
924 TConnection* result = nullptr;
925 if (connectionStack_.empty()) {
926 result = new TConnection(socket, ioThread);
927 ++numTConnections_;
928 } else {
929 result = connectionStack_.top();
930 connectionStack_.pop();
931 result->setSocket(socket);
932 result->init(ioThread);
933 }
934
935 activeConnections_.insert(result);
936 return result;
937}
938
939/**
940 * Returns a connection to the stack

Callers 8

NodeClient.jsFile · 0.80
connection.jsFile · 0.80
client.mjsFile · 0.80
client.jsFile · 0.80
client.jsFile · 0.80
client.tsFile · 0.80

Calls 6

emptyMethod · 0.80
setSocketMethod · 0.80
sizeMethod · 0.45
getMethod · 0.45
popMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected