MCPcopy Create free account
hub / github.com/Codeya-IDE/deepin-ide / connect

Method connect

3rdparty/cppdap/src/socket.cpp:296–348  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

294}
295
296std::shared_ptr<ReaderWriter> Socket::connect(const char* address,
297 const char* port,
298 uint32_t timeoutMillis) {
299 auto shared = Shared::create(address, port);
300 if (!shared) {
301 return nullptr;
302 }
303
304 std::shared_ptr<ReaderWriter> out;
305 shared->lock([&](SOCKET socket, const addrinfo* info) {
306 if (socket == InvalidSocket) {
307 return;
308 }
309
310 if (timeoutMillis == 0) {
311 if (::connect(socket, info->ai_addr, (int)info->ai_addrlen) == 0) {
312 out = shared;
313 }
314 return;
315 }
316
317 if (!setBlocking(socket, false)) {
318 return;
319 }
320
321 auto res = ::connect(socket, info->ai_addr, (int)info->ai_addrlen);
322 if (res == 0) {
323 if (setBlocking(socket, true)) {
324 out = shared;
325 }
326 } else {
327 const auto microseconds = timeoutMillis * 1000;
328
329 fd_set fdset;
330 FD_ZERO(&fdset);
331 FD_SET(socket, &fdset);
332
333 timeval tv;
334 tv.tv_sec = microseconds / 1000000;
335 tv.tv_usec = microseconds - static_cast<uint32_t>(tv.tv_sec * 1000000);
336 res = select(static_cast<int>(socket + 1), nullptr, &fdset, nullptr, &tv);
337 if (res > 0 && !errored(socket) && setBlocking(socket, true)) {
338 out = shared;
339 }
340 }
341 });
342
343 if (!out) {
344 return nullptr;
345 }
346
347 return out->isOpen() ? out : nullptr;
348}
349
350} // namespace dap

Callers 15

TEST_FFunction · 0.45
registerDBusConnectMethod · 0.45
__init__Method · 0.45
__init__Method · 0.45
executeMethod · 0.45
DAPDebuggerMethod · 0.45
showCheckoutDialogMethod · 0.45
initConnectionMethod · 0.45
initConnectionMethod · 0.45

Calls 6

createFunction · 0.85
connectFunction · 0.85
setBlockingFunction · 0.85
erroredFunction · 0.85
lockMethod · 0.45
isOpenMethod · 0.45

Tested by 1

TEST_FFunction · 0.36