LLDB mainline
ConnectionFileDescriptorPosix.cpp
Go to the documentation of this file.
1//===-- ConnectionFileDescriptorPosix.cpp ---------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#if defined(__APPLE__)
10// Enable this special support for Apple builds where we can have unlimited
11// select bounds. We tried switching to poll() and kqueue and we were panicing
12// the kernel, so we have to stick with select for now.
13#define _DARWIN_UNLIMITED_SELECT
14#endif
15
17#include "lldb/Host/Config.h"
19#include "lldb/Host/Socket.h"
24
25#include <cerrno>
26#include <cstdlib>
27#include <cstring>
28#include <fcntl.h>
29#include <sys/types.h>
30
31#if LLDB_ENABLE_POSIX
32#include <termios.h>
33#include <unistd.h>
34#endif
35
36#include <memory>
37#include <sstream>
38
39#include "llvm/Support/Errno.h"
40#include "llvm/Support/ErrorHandling.h"
41#if defined(__APPLE__)
42#include "llvm/ADT/SmallVector.h"
43#endif
44#include "lldb/Host/Host.h"
45#include "lldb/Host/Socket.h"
48#include "lldb/Utility/Log.h"
50#include "lldb/Utility/Timer.h"
51
52using namespace lldb;
53using namespace lldb_private;
54
56 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
58 LLDB_LOGF(log, "%p ConnectionFileDescriptor::ConnectionFileDescriptor ()",
59 static_cast<void *>(this));
60}
61
63 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
64 m_io_sp =
65 std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, owns_fd);
66
68 LLDB_LOGF(log,
69 "%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = "
70 "%i, owns_fd = %i)",
71 static_cast<void *>(this), fd, owns_fd);
73}
74
76 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false) {
77 InitializeSocket(socket);
78}
79
82 LLDB_LOGF(log, "%p ConnectionFileDescriptor::~ConnectionFileDescriptor ()",
83 static_cast<void *>(this));
84 Disconnect(nullptr);
86}
87
90
92 // Make the command file descriptor here:
93 Status result = m_pipe.CreateNew(/*child_processes_inherit=*/false);
94 if (!result.Success()) {
95 LLDB_LOGF(log,
96 "%p ConnectionFileDescriptor::OpenCommandPipe () - could not "
97 "make pipe: %s",
98 static_cast<void *>(this), result.AsCString());
99 } else {
100 LLDB_LOGF(log,
101 "%p ConnectionFileDescriptor::OpenCommandPipe() - success "
102 "readfd=%d writefd=%d",
103 static_cast<void *>(this), m_pipe.GetReadFileDescriptor(),
105 }
106}
107
110 LLDB_LOGF(log, "%p ConnectionFileDescriptor::CloseCommandPipe()",
111 static_cast<void *>(this));
112
113 m_pipe.Close();
114}
115
117 return m_io_sp && m_io_sp->IsValid();
118}
119
121 Status *error_ptr) {
122 return Connect(
123 path, [](llvm::StringRef) {}, error_ptr);
124}
125
128 socket_id_callback_type socket_id_callback,
129 Status *error_ptr) {
130 std::lock_guard<std::recursive_mutex> guard(m_mutex);
132 LLDB_LOGF(log, "%p ConnectionFileDescriptor::Connect (url = '%s')",
133 static_cast<void *>(this), path.str().c_str());
134
136
137 if (path.empty()) {
138 if (error_ptr)
139 *error_ptr = Status::FromErrorString("invalid connect arguments");
141 }
142
143 llvm::StringRef scheme;
144 std::tie(scheme, path) = path.split("://");
145
146 if (!path.empty()) {
147 auto method =
148 llvm::StringSwitch<ConnectionStatus (ConnectionFileDescriptor::*)(
149 llvm::StringRef, socket_id_callback_type, Status *)>(scheme)
151 .Cases("accept", "unix-accept",
153 .Case("unix-abstract-accept",
155 .Cases("connect", "tcp-connect",
159 .Case("unix-abstract-connect",
161#if LLDB_ENABLE_POSIX
165#endif
166 .Default(nullptr);
167
168 if (method) {
169 if (error_ptr)
170 *error_ptr = Status();
171 return (this->*method)(path, socket_id_callback, error_ptr);
172 }
173 }
174
175 if (error_ptr)
177 "unsupported connection URL: '%s'", path.str().c_str());
179}
180
182 size_t bytes_written = 0;
183 Status result = m_pipe.Write("i", 1, bytes_written);
184 return result.Success();
185}
186
189 LLDB_LOGF(log, "%p ConnectionFileDescriptor::Disconnect ()",
190 static_cast<void *>(this));
191
193
194 if (!IsConnected()) {
195 LLDB_LOGF(
196 log, "%p ConnectionFileDescriptor::Disconnect(): Nothing to disconnect",
197 static_cast<void *>(this));
199 }
200
201 // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is
202 // quite likely because somebody is doing a blocking read on our file
203 // descriptor. If that's the case, then send the "q" char to the command
204 // file channel so the read will wake up and the connection will then know to
205 // shut down.
206 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
207 if (!locker.try_lock()) {
208 if (m_pipe.CanWrite()) {
209 size_t bytes_written = 0;
210 Status result = m_pipe.Write("q", 1, bytes_written);
211 LLDB_LOGF(log,
212 "%p ConnectionFileDescriptor::Disconnect(): Couldn't get "
213 "the lock, sent 'q' to %d, error = '%s'.",
214 static_cast<void *>(this), m_pipe.GetWriteFileDescriptor(),
215 result.AsCString());
216 } else if (log) {
217 LLDB_LOGF(log,
218 "%p ConnectionFileDescriptor::Disconnect(): Couldn't get the "
219 "lock, but no command pipe is available.",
220 static_cast<void *>(this));
221 }
222 locker.lock();
223 }
224
225 // Prevents reads and writes during shutdown.
226 m_shutting_down = true;
227
228 Status error = m_io_sp->Close();
229 if (error.Fail())
230 status = eConnectionStatusError;
231 if (error_ptr)
232 *error_ptr = std::move(error);
233
234 // Close any pipes we were using for async interrupts
235 m_pipe.Close();
236
237 m_uri.clear();
238 m_shutting_down = false;
239 return status;
240}
241
242size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
243 const Timeout<std::micro> &timeout,
244 ConnectionStatus &status,
245 Status *error_ptr) {
247
248 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
249 if (!locker.try_lock()) {
250 LLDB_LOGF(log,
251 "%p ConnectionFileDescriptor::Read () failed to get the "
252 "connection lock.",
253 static_cast<void *>(this));
254 if (error_ptr)
255 *error_ptr = Status::FromErrorString(
256 "failed to get the connection lock for read.");
257
259 return 0;
260 }
261
262 if (m_shutting_down) {
263 if (error_ptr)
264 *error_ptr = Status::FromErrorString("shutting down");
265 status = eConnectionStatusError;
266 return 0;
267 }
268
269 status = BytesAvailable(timeout, error_ptr);
270 if (status != eConnectionStatusSuccess)
271 return 0;
272
274 size_t bytes_read = dst_len;
275 error = m_io_sp->Read(dst, bytes_read);
276
277 if (log) {
278 LLDB_LOGF(log,
279 "%p ConnectionFileDescriptor::Read() fd = %" PRIu64
280 ", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s",
281 static_cast<void *>(this),
282 static_cast<uint64_t>(m_io_sp->GetWaitableHandle()),
283 static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
284 static_cast<uint64_t>(bytes_read), error.AsCString());
285 }
286
287 if (bytes_read == 0) {
288 error.Clear(); // End-of-file. Do not automatically close; pass along for
289 // the end-of-file handlers.
291 }
292
293 if (error_ptr)
294 *error_ptr = error.Clone();
295
296 if (error.Fail()) {
297 uint32_t error_value = error.GetError();
298 switch (error_value) {
299 case EAGAIN: // The file was marked for non-blocking I/O, and no data were
300 // ready to be read.
301 if (m_io_sp->GetFdType() == IOObject::eFDTypeSocket)
303 else
305 return 0;
306
307 case EFAULT: // Buf points outside the allocated address space.
308 case EINTR: // A read from a slow device was interrupted before any data
309 // arrived by the delivery of a signal.
310 case EINVAL: // The pointer associated with fildes was negative.
311 case EIO: // An I/O error occurred while reading from the file system.
312 // The process group is orphaned.
313 // The file is a regular file, nbyte is greater than 0, the
314 // starting position is before the end-of-file, and the
315 // starting position is greater than or equal to the offset
316 // maximum established for the open file descriptor
317 // associated with fildes.
318 case EISDIR: // An attempt is made to read a directory.
319 case ENOBUFS: // An attempt to allocate a memory buffer fails.
320 case ENOMEM: // Insufficient memory is available.
321 status = eConnectionStatusError;
322 break; // Break to close....
323
324 case ENOENT: // no such file or directory
325 case EBADF: // fildes is not a valid file or socket descriptor open for
326 // reading.
327 case ENXIO: // An action is requested of a device that does not exist..
328 // A requested action cannot be performed by the device.
329 case ECONNRESET: // The connection is closed by the peer during a read
330 // attempt on a socket.
331 case ENOTCONN: // A read is attempted on an unconnected socket.
333 break; // Break to close....
334
335 case ETIMEDOUT: // A transmission timeout occurs during a read attempt on a
336 // socket.
338 return 0;
339
340 default:
341 LLDB_LOG(log, "this = {0}, unexpected error: {1}", this,
342 llvm::sys::StrError(error_value));
343 status = eConnectionStatusError;
344 break; // Break to close....
345 }
346
347 return 0;
348 }
349 return bytes_read;
350}
351
352size_t ConnectionFileDescriptor::Write(const void *src, size_t src_len,
353 ConnectionStatus &status,
354 Status *error_ptr) {
356 LLDB_LOGF(log,
357 "%p ConnectionFileDescriptor::Write (src = %p, src_len = %" PRIu64
358 ")",
359 static_cast<void *>(this), static_cast<const void *>(src),
360 static_cast<uint64_t>(src_len));
361
362 if (!IsConnected()) {
363 if (error_ptr)
364 *error_ptr = Status::FromErrorString("not connected");
366 return 0;
367 }
368
369 if (m_shutting_down) {
370 if (error_ptr)
371 *error_ptr = Status::FromErrorString("shutting down");
372 status = eConnectionStatusError;
373 return 0;
374 }
375
377
378 size_t bytes_sent = src_len;
379 error = m_io_sp->Write(src, bytes_sent);
380
381 if (log) {
382 LLDB_LOGF(log,
383 "%p ConnectionFileDescriptor::Write(fd = %" PRIu64
384 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64 " (error = %s)",
385 static_cast<void *>(this),
386 static_cast<uint64_t>(m_io_sp->GetWaitableHandle()),
387 static_cast<const void *>(src), static_cast<uint64_t>(src_len),
388 static_cast<uint64_t>(bytes_sent), error.AsCString());
389 }
390
391 if (error_ptr)
392 *error_ptr = error.Clone();
393
394 if (error.Fail()) {
395 switch (error.GetError()) {
396 case EAGAIN:
397 case EINTR:
399 return 0;
400
401 case ECONNRESET: // The connection is closed by the peer during a read
402 // attempt on a socket.
403 case ENOTCONN: // A read is attempted on an unconnected socket.
405 break; // Break to close....
406
407 default:
408 status = eConnectionStatusError;
409 break; // Break to close....
410 }
411
412 return 0;
413 }
414
416 return bytes_sent;
417}
418
420
421// This ConnectionFileDescriptor::BytesAvailable() uses select() via
422// SelectHelper
423//
424// PROS:
425// - select is consistent across most unix platforms
426// - The Apple specific version allows for unlimited fds in the fd_sets by
427// setting the _DARWIN_UNLIMITED_SELECT define prior to including the
428// required header files.
429// CONS:
430// - on non-Apple platforms, only supports file descriptors up to FD_SETSIZE.
431// This implementation will assert if it runs into that hard limit to let
432// users know that another ConnectionFileDescriptor::BytesAvailable() should
433// be used or a new version of ConnectionFileDescriptor::BytesAvailable()
434// should be written for the system that is running into the limitations.
435
438 Status *error_ptr) {
439 // Don't need to take the mutex here separately since we are only called from
440 // Read. If we ever get used more generally we will need to lock here as
441 // well.
442
444 LLDB_LOG(log, "this = {0}, timeout = {1}", this, timeout);
445
446 // Make a copy of the file descriptors to make sure we don't have another
447 // thread change these values out from under us and cause problems in the
448 // loop below where like in FS_SET()
449 const IOObject::WaitableHandle handle = m_io_sp->GetWaitableHandle();
450 const int pipe_fd = m_pipe.GetReadFileDescriptor();
451
452 if (handle != IOObject::kInvalidHandleValue) {
453 SelectHelper select_helper;
454 if (timeout)
455 select_helper.SetTimeout(*timeout);
456
457 select_helper.FDSetRead(handle);
458#if defined(_WIN32)
459 // select() won't accept pipes on Windows. The entire Windows codepath
460 // needs to be converted over to using WaitForMultipleObjects and event
461 // HANDLEs, but for now at least this will allow ::select() to not return
462 // an error.
463 const bool have_pipe_fd = false;
464#else
465 const bool have_pipe_fd = pipe_fd >= 0;
466#endif
467 if (have_pipe_fd)
468 select_helper.FDSetRead(pipe_fd);
469
470 while (handle == m_io_sp->GetWaitableHandle()) {
471
472 Status error = select_helper.Select();
473
474 if (error_ptr)
475 *error_ptr = error.Clone();
476
477 if (error.Fail()) {
478 switch (error.GetError()) {
479 case EBADF: // One of the descriptor sets specified an invalid
480 // descriptor.
482
483 case EINVAL: // The specified time limit is invalid. One of its
484 // components is negative or too large.
485 default: // Other unknown error
487
488 case ETIMEDOUT:
490
491 case EAGAIN: // The kernel was (perhaps temporarily) unable to
492 // allocate the requested number of file descriptors, or
493 // we have non-blocking IO
494 case EINTR: // A signal was delivered before the time limit
495 // expired and before any of the selected events occurred.
496 break; // Lets keep reading to until we timeout
497 }
498 } else {
499 if (select_helper.FDIsSetRead(handle))
501
502 if (select_helper.FDIsSetRead(pipe_fd)) {
503 // There is an interrupt or exit command in the command pipe Read the
504 // data from that pipe:
505 char c;
506
507 ssize_t bytes_read =
508 llvm::sys::RetryAfterSignal(-1, ::read, pipe_fd, &c, 1);
509 assert(bytes_read == 1);
510 UNUSED_IF_ASSERT_DISABLED(bytes_read);
511 switch (c) {
512 case 'q':
513 LLDB_LOGF(log,
514 "%p ConnectionFileDescriptor::BytesAvailable() "
515 "got data: %c from the command channel.",
516 static_cast<void *>(this), c);
518 case 'i':
519 // Interrupt the current read
521 }
522 }
523 }
524 }
525 }
526
527 if (error_ptr)
528 *error_ptr = Status::FromErrorString("not connected");
530}
531
533 Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name,
534 llvm::function_ref<void(Socket &)> post_listen_callback,
535 Status *error_ptr) {
537 std::unique_ptr<Socket> listening_socket =
538 Socket::Create(socket_protocol, error);
539 Socket *accepted_socket;
540
541 if (!error.Fail())
542 error = listening_socket->Listen(socket_name, 5);
543
544 if (!error.Fail()) {
545 post_listen_callback(*listening_socket);
546 error = listening_socket->Accept(/*timeout=*/std::nullopt, accepted_socket);
547 }
548
549 if (!error.Fail()) {
550 m_io_sp.reset(accepted_socket);
551 m_uri.assign(socket_name.str());
553 }
554
555 if (error_ptr)
556 *error_ptr = error.Clone();
558}
559
562 llvm::StringRef socket_name,
563 Status *error_ptr) {
565 std::unique_ptr<Socket> socket = Socket::Create(socket_protocol, error);
566
567 if (!error.Fail())
568 error = socket->Connect(socket_name);
569
570 if (!error.Fail()) {
571 m_io_sp = std::move(socket);
572 m_uri.assign(socket_name.str());
574 }
575
576 if (error_ptr)
577 *error_ptr = error.Clone();
579}
580
582 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
583 Status *error_ptr) {
584 return AcceptSocket(
585 Socket::ProtocolUnixDomain, socket_name,
586 [socket_id_callback, socket_name](Socket &listening_socket) {
587 socket_id_callback(socket_name);
588 },
589 error_ptr);
590}
591
593 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
594 Status *error_ptr) {
595 return ConnectSocket(Socket::ProtocolUnixDomain, socket_name, error_ptr);
596}
597
599 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
600 Status *error_ptr) {
601 return AcceptSocket(
602 Socket::ProtocolUnixAbstract, socket_name,
603 [socket_id_callback, socket_name](Socket &listening_socket) {
604 socket_id_callback(socket_name);
605 },
606 error_ptr);
607}
608
610 llvm::StringRef socket_name, socket_id_callback_type socket_id_callback,
611 Status *error_ptr) {
612 return ConnectSocket(Socket::ProtocolUnixAbstract, socket_name, error_ptr);
613}
614
616ConnectionFileDescriptor::AcceptTCP(llvm::StringRef socket_name,
617 socket_id_callback_type socket_id_callback,
618 Status *error_ptr) {
620 Socket::ProtocolTcp, socket_name,
621 [socket_id_callback](Socket &listening_socket) {
622 uint16_t port =
623 static_cast<TCPSocket &>(listening_socket).GetLocalPortNumber();
624 socket_id_callback(std::to_string(port));
625 },
626 error_ptr);
627 if (ret == eConnectionStatusSuccess)
628 m_uri.assign(
629 static_cast<TCPSocket *>(m_io_sp.get())->GetRemoteConnectionURI());
630 return ret;
631}
632
634ConnectionFileDescriptor::ConnectTCP(llvm::StringRef socket_name,
635 socket_id_callback_type socket_id_callback,
636 Status *error_ptr) {
637 return ConnectSocket(Socket::ProtocolTcp, socket_name, error_ptr);
638}
639
642 socket_id_callback_type socket_id_callback,
643 Status *error_ptr) {
644 if (error_ptr)
645 *error_ptr = Status();
646 llvm::Expected<std::unique_ptr<UDPSocket>> socket = Socket::UdpConnect(s);
647 if (!socket) {
648 if (error_ptr)
649 *error_ptr = Status::FromError(socket.takeError());
650 else
651 LLDB_LOG_ERROR(GetLog(LLDBLog::Connection), socket.takeError(),
652 "tcp connect failed: {0}");
654 }
655 m_io_sp = std::move(*socket);
656 m_uri.assign(std::string(s));
658}
659
662 socket_id_callback_type socket_id_callback,
663 Status *error_ptr) {
664#if LLDB_ENABLE_POSIX
665 // Just passing a native file descriptor within this current process that
666 // is already opened (possibly from a service or other source).
667 int fd = -1;
668
669 if (!s.getAsInteger(0, fd)) {
670 // We have what looks to be a valid file descriptor, but we should make
671 // sure it is. We currently are doing this by trying to get the flags
672 // from the file descriptor and making sure it isn't a bad fd.
673 errno = 0;
674 int flags = ::fcntl(fd, F_GETFL, 0);
675 if (flags == -1 || errno == EBADF) {
676 if (error_ptr)
678 "stale file descriptor: %s", s.str().c_str());
679 m_io_sp.reset();
681 } else {
682 // Don't take ownership of a file descriptor that gets passed to us
683 // since someone else opened the file descriptor and handed it to us.
684 // TODO: Since are using a URL to open connection we should
685 // eventually parse options using the web standard where we have
686 // "fd://123?opt1=value;opt2=value" and we can have an option be
687 // "owns=1" or "owns=0" or something like this to allow us to specify
688 // this. For now, we assume we must assume we don't own it.
689
690 std::unique_ptr<TCPSocket> tcp_socket;
691 tcp_socket = std::make_unique<TCPSocket>(fd, /*should_close=*/false);
692 // Try and get a socket option from this file descriptor to see if
693 // this is a socket and set m_is_socket accordingly.
694 int resuse;
695 bool is_socket =
696 !!tcp_socket->GetOption(SOL_SOCKET, SO_REUSEADDR, resuse);
697 if (is_socket)
698 m_io_sp = std::move(tcp_socket);
699 else
700 m_io_sp =
701 std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, false);
702 m_uri = s.str();
704 }
705 }
706
707 if (error_ptr)
709 "invalid file descriptor: \"%s\"", s.str().c_str());
710 m_io_sp.reset();
712#endif // LLDB_ENABLE_POSIX
713 llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
714}
715
717 llvm::StringRef s, socket_id_callback_type socket_id_callback,
718 Status *error_ptr) {
719#if LLDB_ENABLE_POSIX
720 std::string addr_str = s.str();
721 // file:///PATH
722 int fd = FileSystem::Instance().Open(addr_str.c_str(), O_RDWR);
723 if (fd == -1) {
724 if (error_ptr)
725 *error_ptr = Status::FromErrno();
727 }
728
729 if (::isatty(fd)) {
730 // Set up serial terminal emulation
731 struct termios options;
732 ::tcgetattr(fd, &options);
733
734 // Set port speed to maximum
735 ::cfsetospeed(&options, B115200);
736 ::cfsetispeed(&options, B115200);
737
738 // Raw input, disable echo and signals
739 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
740
741 // Make sure only one character is needed to return from a read
742 options.c_cc[VMIN] = 1;
743 options.c_cc[VTIME] = 0;
744
745 llvm::sys::RetryAfterSignal(-1, ::tcsetattr, fd, TCSANOW, &options);
746 }
747
748 m_io_sp = std::make_shared<NativeFile>(fd, File::eOpenOptionReadWrite, true);
750#endif // LLDB_ENABLE_POSIX
751 llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
752}
753
755 llvm::StringRef s, socket_id_callback_type socket_id_callback,
756 Status *error_ptr) {
757#if LLDB_ENABLE_POSIX
758 llvm::StringRef path, qs;
759 // serial:///PATH?k1=v1&k2=v2...
760 std::tie(path, qs) = s.split('?');
761
762 llvm::Expected<SerialPort::Options> serial_options =
764 if (!serial_options) {
765 if (error_ptr)
766 *error_ptr = Status::FromError(serial_options.takeError());
767 else
768 llvm::consumeError(serial_options.takeError());
770 }
771
772 int fd = FileSystem::Instance().Open(path.str().c_str(), O_RDWR);
773 if (fd == -1) {
774 if (error_ptr)
775 *error_ptr = Status::FromErrno();
777 }
778
779 llvm::Expected<std::unique_ptr<SerialPort>> serial_sp = SerialPort::Create(
780 fd, File::eOpenOptionReadWrite, serial_options.get(), true);
781 if (!serial_sp) {
782 if (error_ptr)
783 *error_ptr = Status::FromError(serial_sp.takeError());
784 else
785 llvm::consumeError(serial_sp.takeError());
787 }
788 m_io_sp = std::move(serial_sp.get());
789
791#endif // LLDB_ENABLE_POSIX
792 llvm_unreachable("this function should be only called w/ LLDB_ENABLE_POSIX");
793}
794
796 m_io_sp.reset(socket);
797 m_uri = socket->GetRemoteConnectionURI();
798}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
Definition: Log.h:369
#define LLDB_LOGF(log,...)
Definition: Log.h:376
#define LLDB_LOG_ERROR(log, error,...)
Definition: Log.h:392
lldb_private::Status Select()
void FDSetRead(lldb::socket_t fd)
void SetTimeout(const std::chrono::microseconds &timeout)
bool FDIsSetRead(lldb::socket_t fd) const
lldb::ConnectionStatus AcceptTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus AcceptAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectUDP(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectSerialPort(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
bool InterruptRead() override
Interrupts an ongoing Read() operation.
lldb::ConnectionStatus Connect(llvm::StringRef url, Status *error_ptr) override
Connect using the connect string url.
bool IsConnected() const override
Check if the connection is valid.
lldb::ConnectionStatus AcceptNamedSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
size_t Write(const void *src, size_t src_len, lldb::ConnectionStatus &status, Status *error_ptr) override
The actual write function that attempts to write to the communications protocol.
lldb::ConnectionStatus AcceptSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, llvm::function_ref< void(Socket &)> post_listen_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectFD(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectAbstractSocket(llvm::StringRef socket_name, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus Disconnect(Status *error_ptr) override
Disconnect the communications connection if one is currently connected.
lldb::ConnectionStatus BytesAvailable(const Timeout< std::micro > &timeout, Status *error_ptr)
lldb::ConnectionStatus ConnectFile(llvm::StringRef args, socket_id_callback_type socket_id_callback, Status *error_ptr)
lldb::ConnectionStatus ConnectSocket(Socket::SocketProtocol socket_protocol, llvm::StringRef socket_name, Status *error_ptr)
std::string GetURI() override
Returns a URI that describes this connection object.
lldb::ConnectionStatus ConnectTCP(llvm::StringRef host_and_port, socket_id_callback_type socket_id_callback, Status *error_ptr)
size_t Read(void *dst, size_t dst_len, const Timeout< std::micro > &timeout, lldb::ConnectionStatus &status, Status *error_ptr) override
The read function that attempts to read from the connection.
llvm::function_ref< void(llvm::StringRef local_socket_id)> socket_id_callback_type
A communication connection class.
Definition: Connection.h:41
int Open(const char *path, int flags, int mode=0600)
Wraps ::open in a platform-independent way.
static FileSystem & Instance()
@ eOpenOptionReadWrite
Definition: File.h:53
static const WaitableHandle kInvalidHandleValue
Definition: IOObject.h:30
Status Write(const void *buf, size_t size, size_t &bytes_written)
Definition: PipeBase.cpp:21
int GetReadFileDescriptor() const override
Definition: PipePosix.cpp:208
bool CanWrite() const override
Definition: PipePosix.cpp:271
void Close() override
Definition: PipePosix.cpp:248
Status CreateNew(bool child_process_inherit) override
Definition: PipePosix.cpp:80
int GetWriteFileDescriptor() const override
Definition: PipePosix.cpp:217
static llvm::Expected< std::unique_ptr< SerialPort > > Create(int fd, OpenOptions options, Options serial_options, bool transfer_ownership)
Definition: File.cpp:863
static llvm::Expected< Options > OptionsFromURL(llvm::StringRef urlqs)
Definition: File.cpp:808
static std::unique_ptr< Socket > Create(const SocketProtocol protocol, Status &error)
Definition: Socket.cpp:213
virtual std::string GetRemoteConnectionURI() const
Definition: Socket.h:153
static llvm::Expected< std::unique_ptr< UDPSocket > > UdpConnect(llvm::StringRef host_and_port)
Definition: Socket.cpp:283
An error handling class.
Definition: Status.h:118
static Status FromErrno()
Set the current error to errno.
Definition: Status.cpp:300
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition: Status.cpp:106
static Status FromErrorString(const char *str)
Definition: Status.h:141
const char * AsCString(const char *default_error_str="unknown error") const
Get the error string associated with the current error.
Definition: Status.cpp:195
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition: Status.cpp:137
bool Success() const
Test for success condition.
Definition: Status.cpp:304
std::string GetRemoteConnectionURI() const override
Definition: TCPSocket.cpp:110
#define UNUSED_IF_ASSERT_DISABLED(x)
Definition: lldb-defines.h:140
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition: Log.h:332
Definition: SBAddress.h:15
ConnectionStatus
Connection Status Types.
@ eConnectionStatusError
Check GetError() for details.
@ eConnectionStatusInterrupted
Interrupted read.
@ eConnectionStatusTimedOut
Request timed out.
@ eConnectionStatusEndOfFile
End-of-file encountered.
@ eConnectionStatusSuccess
Success.
@ eConnectionStatusLostConnection
Lost connection while connected to a valid connection.
@ eConnectionStatusNoConnection
No connection.