MCPcopy Create free account
hub / github.com/apache/impala / Start

Method Start

be/src/kudu/security/tls_socket-test.cc:134–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132 }
133
134 void Start() {
135 ASSERT_OK(server_tls_.Init());
136 ASSERT_OK(server_tls_.GenerateSelfSignedCertAndKey());
137 ASSERT_OK(listen_addr_.ParseString("127.0.0.1", 0));
138 ASSERT_OK(listener_.Init(listen_addr_.family(), 0));
139 ASSERT_OK(listener_.BindAndListen(listen_addr_, /*listen_queue_size=*/10));
140 ASSERT_OK(listener_.GetSocketAddress(&listen_addr_));
141
142 thread_ = thread([&] {
143 pthread_ = pthread_self();
144 pthread_sync_.CountDown();
145 unique_ptr<Socket> sock(new Socket());
146 Sockaddr remote;
147 CHECK_OK(listener_.Accept(sock.get(), &remote, /*flags=*/0));
148
149 TlsHandshake server(TlsHandshakeType::SERVER);
150 CHECK_OK(server_tls_.InitiateHandshake(&server));
151 CHECK_OK(DoNegotiationSide(sock.get(), &server, "server"));
152 CHECK_OK(server.Finish(&sock));
153
154 CHECK_OK(sock->SetRecvTimeout(kTimeout));
155 unique_ptr<uint8_t[]> buf(new uint8_t[kEchoChunkSize]);
156 // An "echo" loop for kEchoChunkSize byte buffers.
157 while (!is_stopped_) {
158 size_t n;
159 Status s = sock->BlockingRecv(buf.get(), kEchoChunkSize, &n, MonoTime::Now() + kTimeout);
160 if (!s.ok()) {
161 CHECK(is_stopped_) << "unexpected error reading: " << s.ToString();
162 }
163
164 LOG(INFO) << "server echoing " << n << " bytes";
165 size_t written;
166 s = sock->BlockingWrite(buf.get(), n, &written, MonoTime::Now() + kTimeout);
167 if (!s.ok()) {
168 CHECK(is_stopped_) << "unexpected error writing: " << s.ToString();
169 }
170 if (slow_read_) {
171 SleepFor(MonoDelta::FromMilliseconds(10));
172 }
173 }
174
175 CHECK_OK(listener_.Close());
176 });
177 }
178
179 void EnableSlowRead() {
180 slow_read_ = true;

Callers 1

TEST_FFunction · 0.45

Calls 15

SleepForFunction · 0.85
GetSocketAddressMethod · 0.80
CountDownMethod · 0.80
AcceptMethod · 0.80
InitiateHandshakeMethod · 0.80
SetRecvTimeoutMethod · 0.80
BlockingRecvMethod · 0.80
BlockingWriteMethod · 0.80
DoNegotiationSideFunction · 0.70
getMethod · 0.65
InitMethod · 0.45

Tested by

no test coverage detected