]> git.proxmox.com Git - ceph.git/blame - ceph/src/jaegertracing/jaeger-client-cpp/src/jaegertracing/net/http/SocketReader.h
buildsys: switch source download to quincy
[ceph.git] / ceph / src / jaegertracing / jaeger-client-cpp / src / jaegertracing / net / http / SocketReader.h
CommitLineData
f67539c2
TL
1/*
2 * Copyright (c) 2018, The Jaeger Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef JAEGERTRACING_NET_HTTP_SOCKET_READER_H
18#define JAEGERTRACING_NET_HTTP_SOCKET_READER_H
19
20#include "jaegertracing/net/Socket.h"
21
22namespace jaegertracing {
23namespace net {
24namespace http {
25
26class SocketReader {
27 public:
28 static std::string read(Socket& socket) {
29 constexpr auto kBufferSize = 1024;
30 std::array<char, kBufferSize> buffer{};
31 auto numRead = ::recv(socket.handle(), &buffer[0], buffer.size(), 0);
32 std::string response;
33 while (numRead > 0) {
34 response.append(&buffer[0], numRead);
35 if (numRead < static_cast<int>(buffer.size())) {
36 break;
37 }
38 numRead = ::recv(socket.handle(), &buffer[0], buffer.size(), 0);
39 }
40 return response;
41 }
42};
43
44} // namespace http
45} // namespace net
46} // namespace jaegertracing
47
48#endif // JAEGERTRACING_NET_HTTP_SOCKET_READER_H