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

Method serve

lib/cpp/src/thrift/server/TServerFramework.cpp:109–189  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109void TServerFramework::serve() {
110 shared_ptr<TTransport> client;
111 shared_ptr<TTransport> inputTransport;
112 shared_ptr<TTransport> outputTransport;
113 shared_ptr<TProtocol> inputProtocol;
114 shared_ptr<TProtocol> outputProtocol;
115
116 // Start the server listening
117 serverTransport_->listen();
118
119 // Run the preServe event to indicate server is now listening
120 // and that it is safe to connect.
121 if (eventHandler_) {
122 eventHandler_->preServe();
123 }
124
125 // Fetch client from server
126 for (;;) {
127 try {
128 // Dereference any resources from any previous client creation
129 // such that a blocking accept does not hold them indefinitely.
130 outputProtocol.reset();
131 inputProtocol.reset();
132 outputTransport.reset();
133 inputTransport.reset();
134 client.reset();
135
136 // If we have reached the limit on the number of concurrent
137 // clients allowed, wait for one or more clients to drain before
138 // accepting another.
139 {
140 Synchronized sync(mon_);
141 while (clients_ >= limit_) {
142 mon_.wait();
143 }
144 }
145
146 client = serverTransport_->accept();
147
148 inputTransport = inputTransportFactory_->getTransport(client);
149 outputTransport = outputTransportFactory_->getTransport(client);
150 if (!outputProtocolFactory_) {
151 inputProtocol = inputProtocolFactory_->getProtocol(inputTransport, outputTransport);
152 outputProtocol = inputProtocol;
153 } else {
154 inputProtocol = inputProtocolFactory_->getProtocol(inputTransport);
155 outputProtocol = outputProtocolFactory_->getProtocol(outputTransport);
156 }
157
158 newlyConnectedClient(shared_ptr<TConnectedClient>(
159 new TConnectedClient(getProcessor(inputProtocol, outputProtocol, client),
160 inputProtocol,
161 outputProtocol,
162 eventHandler_,
163 client),
164 bind(&TServerFramework::disposeConnectedClient, this, std::placeholders::_1)));
165
166 } catch (TTransportException& ttx) {

Callers

nothing calls this directly

Calls 12

releaseOneDescriptorFunction · 0.85
stringFunction · 0.85
preServeMethod · 0.65
acceptMethod · 0.65
getProtocolMethod · 0.65
bindFunction · 0.50
listenMethod · 0.45
resetMethod · 0.45
waitMethod · 0.45
getTransportMethod · 0.45
getTypeMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected