1 //===-- ConnectionFileDescriptorPosix.cpp -----------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #if defined(__APPLE__)
11 // Enable this special support for Apple builds where we can have unlimited
12 // select bounds. We tried switching to poll() and kqueue and we were panicing
13 // the kernel, so we have to stick with select for now.
14 #define _DARWIN_UNLIMITED_SELECT
17 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
18 #include "lldb/Host/Config.h"
19 #include "lldb/Host/Socket.h"
20 #include "lldb/Host/SocketAddress.h"
21 #include "lldb/Utility/SelectHelper.h"
22 #include "lldb/Utility/Timeout.h"
29 #include <sys/types.h>
31 #ifndef LLDB_DISABLE_POSIX
39 // Other libraries and framework includes
40 #include "llvm/Support/Errno.h"
41 #include "llvm/Support/ErrorHandling.h"
42 #if defined(__APPLE__)
43 #include "llvm/ADT/SmallVector.h"
46 #include "lldb/Host/Host.h"
47 #include "lldb/Host/Socket.h"
48 #include "lldb/Host/common/TCPSocket.h"
49 #include "lldb/Utility/Log.h"
50 #include "lldb/Utility/StreamString.h"
51 #include "lldb/Utility/Timer.h"
54 using namespace lldb_private;
56 const char *ConnectionFileDescriptor::LISTEN_SCHEME = "listen";
57 const char *ConnectionFileDescriptor::ACCEPT_SCHEME = "accept";
58 const char *ConnectionFileDescriptor::UNIX_ACCEPT_SCHEME = "unix-accept";
59 const char *ConnectionFileDescriptor::CONNECT_SCHEME = "connect";
60 const char *ConnectionFileDescriptor::TCP_CONNECT_SCHEME = "tcp-connect";
61 const char *ConnectionFileDescriptor::UDP_SCHEME = "udp";
62 const char *ConnectionFileDescriptor::UNIX_CONNECT_SCHEME = "unix-connect";
63 const char *ConnectionFileDescriptor::UNIX_ABSTRACT_CONNECT_SCHEME =
64 "unix-abstract-connect";
65 const char *ConnectionFileDescriptor::FD_SCHEME = "fd";
66 const char *ConnectionFileDescriptor::FILE_SCHEME = "file";
70 llvm::Optional<llvm::StringRef> GetURLAddress(llvm::StringRef url,
71 llvm::StringRef scheme) {
72 if (!url.consume_front(scheme))
74 if (!url.consume_front("://"))
80 ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit)
81 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
82 m_waiting_for_accept(false),
83 m_child_processes_inherit(child_processes_inherit) {
84 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
87 log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor ()",
88 static_cast<void *>(this));
91 ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd)
92 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
93 m_waiting_for_accept(false), m_child_processes_inherit(false) {
94 m_write_sp.reset(new File(fd, owns_fd));
95 m_read_sp.reset(new File(fd, false));
97 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
100 log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = "
102 static_cast<void *>(this), fd, owns_fd);
106 ConnectionFileDescriptor::ConnectionFileDescriptor(Socket *socket)
107 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
108 m_waiting_for_accept(false), m_child_processes_inherit(false) {
109 InitializeSocket(socket);
112 ConnectionFileDescriptor::~ConnectionFileDescriptor() {
113 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
114 LIBLLDB_LOG_OBJECT));
116 log->Printf("%p ConnectionFileDescriptor::~ConnectionFileDescriptor ()",
117 static_cast<void *>(this));
122 void ConnectionFileDescriptor::OpenCommandPipe() {
125 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
126 // Make the command file descriptor here:
127 Status result = m_pipe.CreateNew(m_child_processes_inherit);
128 if (!result.Success()) {
130 log->Printf("%p ConnectionFileDescriptor::OpenCommandPipe () - could not "
132 static_cast<void *>(this), result.AsCString());
135 log->Printf("%p ConnectionFileDescriptor::OpenCommandPipe() - success "
136 "readfd=%d writefd=%d",
137 static_cast<void *>(this), m_pipe.GetReadFileDescriptor(),
138 m_pipe.GetWriteFileDescriptor());
142 void ConnectionFileDescriptor::CloseCommandPipe() {
143 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
145 log->Printf("%p ConnectionFileDescriptor::CloseCommandPipe()",
146 static_cast<void *>(this));
151 bool ConnectionFileDescriptor::IsConnected() const {
152 return (m_read_sp && m_read_sp->IsValid()) ||
153 (m_write_sp && m_write_sp->IsValid());
156 ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
158 std::lock_guard<std::recursive_mutex> guard(m_mutex);
159 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
161 log->Printf("%p ConnectionFileDescriptor::Connect (url = '%s')",
162 static_cast<void *>(this), path.str().c_str());
167 llvm::Optional<llvm::StringRef> addr;
168 if ((addr = GetURLAddress(path, LISTEN_SCHEME))) {
169 // listen://HOST:PORT
170 return SocketListenAndAccept(*addr, error_ptr);
171 } else if ((addr = GetURLAddress(path, ACCEPT_SCHEME))) {
173 return NamedSocketAccept(*addr, error_ptr);
174 } else if ((addr = GetURLAddress(path, UNIX_ACCEPT_SCHEME))) {
176 return NamedSocketAccept(*addr, error_ptr);
177 } else if ((addr = GetURLAddress(path, CONNECT_SCHEME))) {
178 return ConnectTCP(*addr, error_ptr);
179 } else if ((addr = GetURLAddress(path, TCP_CONNECT_SCHEME))) {
180 return ConnectTCP(*addr, error_ptr);
181 } else if ((addr = GetURLAddress(path, UDP_SCHEME))) {
182 return ConnectUDP(*addr, error_ptr);
183 } else if ((addr = GetURLAddress(path, UNIX_CONNECT_SCHEME))) {
184 // unix-connect://SOCKNAME
185 return NamedSocketConnect(*addr, error_ptr);
186 } else if ((addr = GetURLAddress(path, UNIX_ABSTRACT_CONNECT_SCHEME))) {
187 // unix-abstract-connect://SOCKNAME
188 return UnixAbstractSocketConnect(*addr, error_ptr);
190 #ifndef LLDB_DISABLE_POSIX
191 else if ((addr = GetURLAddress(path, FD_SCHEME))) {
192 // Just passing a native file descriptor within this current process
193 // that is already opened (possibly from a service or other source).
196 if (!addr->getAsInteger(0, fd)) {
197 // We have what looks to be a valid file descriptor, but we
198 // should make sure it is. We currently are doing this by trying to
199 // get the flags from the file descriptor and making sure it
202 int flags = ::fcntl(fd, F_GETFL, 0);
203 if (flags == -1 || errno == EBADF) {
205 error_ptr->SetErrorStringWithFormat("stale file descriptor: %s",
209 return eConnectionStatusError;
211 // Don't take ownership of a file descriptor that gets passed
212 // to us since someone else opened the file descriptor and
214 // TODO: Since are using a URL to open connection we should
215 // eventually parse options using the web standard where we
216 // have "fd://123?opt1=value;opt2=value" and we can have an
217 // option be "owns=1" or "owns=0" or something like this to
218 // allow us to specify this. For now, we assume we must
219 // assume we don't own it.
221 std::unique_ptr<TCPSocket> tcp_socket;
222 tcp_socket.reset(new TCPSocket(fd, false, false));
223 // Try and get a socket option from this file descriptor to
224 // see if this is a socket and set m_is_socket accordingly.
227 !!tcp_socket->GetOption(SOL_SOCKET, SO_REUSEADDR, resuse);
229 m_read_sp = std::move(tcp_socket);
230 m_write_sp = m_read_sp;
232 m_read_sp.reset(new File(fd, false));
233 m_write_sp.reset(new File(fd, false));
236 return eConnectionStatusSuccess;
241 error_ptr->SetErrorStringWithFormat("invalid file descriptor: \"%s\"",
245 return eConnectionStatusError;
246 } else if ((addr = GetURLAddress(path, FILE_SCHEME))) {
247 std::string addr_str = addr->str();
249 int fd = llvm::sys::RetryAfterSignal(-1, ::open, addr_str.c_str(), O_RDWR);
252 error_ptr->SetErrorToErrno();
253 return eConnectionStatusError;
257 // Set up serial terminal emulation
258 struct termios options;
259 ::tcgetattr(fd, &options);
261 // Set port speed to maximum
262 ::cfsetospeed(&options, B115200);
263 ::cfsetispeed(&options, B115200);
265 // Raw input, disable echo and signals
266 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
268 // Make sure only one character is needed to return from a read
269 options.c_cc[VMIN] = 1;
270 options.c_cc[VTIME] = 0;
272 ::tcsetattr(fd, TCSANOW, &options);
275 int flags = ::fcntl(fd, F_GETFL, 0);
277 if ((flags & O_NONBLOCK) == 0) {
279 ::fcntl(fd, F_SETFL, flags);
282 m_read_sp.reset(new File(fd, true));
283 m_write_sp.reset(new File(fd, false));
284 return eConnectionStatusSuccess;
288 error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'",
290 return eConnectionStatusError;
293 error_ptr->SetErrorString("invalid connect arguments");
294 return eConnectionStatusError;
297 bool ConnectionFileDescriptor::InterruptRead() {
298 size_t bytes_written = 0;
299 Status result = m_pipe.Write("i", 1, bytes_written);
300 return result.Success();
303 ConnectionStatus ConnectionFileDescriptor::Disconnect(Status *error_ptr) {
304 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
306 log->Printf("%p ConnectionFileDescriptor::Disconnect ()",
307 static_cast<void *>(this));
309 ConnectionStatus status = eConnectionStatusSuccess;
311 if (!IsConnected()) {
314 "%p ConnectionFileDescriptor::Disconnect(): Nothing to disconnect",
315 static_cast<void *>(this));
316 return eConnectionStatusSuccess;
319 if (m_read_sp && m_read_sp->IsValid() &&
320 m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
321 static_cast<Socket &>(*m_read_sp).PreDisconnect();
323 // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is quite
325 // because somebody is doing a blocking read on our file descriptor. If
327 // then send the "q" char to the command file channel so the read will wake up
328 // and the connection
329 // will then know to shut down.
331 m_shutting_down = true;
333 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
334 if (!locker.try_lock()) {
335 if (m_pipe.CanWrite()) {
336 size_t bytes_written = 0;
337 Status result = m_pipe.Write("q", 1, bytes_written);
339 log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get "
340 "the lock, sent 'q' to %d, error = '%s'.",
341 static_cast<void *>(this), m_pipe.GetWriteFileDescriptor(),
344 log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the "
345 "lock, but no command pipe is available.",
346 static_cast<void *>(this));
351 Status error = m_read_sp->Close();
352 Status error2 = m_write_sp->Close();
353 if (error.Fail() || error2.Fail())
354 status = eConnectionStatusError;
356 *error_ptr = error.Fail() ? error : error2;
358 // Close any pipes we were using for async interrupts
362 m_shutting_down = false;
366 size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
367 const Timeout<std::micro> &timeout,
368 ConnectionStatus &status,
370 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
372 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
373 if (!locker.try_lock()) {
375 log->Printf("%p ConnectionFileDescriptor::Read () failed to get the "
377 static_cast<void *>(this));
379 error_ptr->SetErrorString("failed to get the connection lock for read.");
381 status = eConnectionStatusTimedOut;
385 if (m_shutting_down) {
386 status = eConnectionStatusError;
390 status = BytesAvailable(timeout, error_ptr);
391 if (status != eConnectionStatusSuccess)
395 size_t bytes_read = dst_len;
396 error = m_read_sp->Read(dst, bytes_read);
399 log->Printf("%p ConnectionFileDescriptor::Read() fd = %" PRIu64
400 ", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s",
401 static_cast<void *>(this),
402 static_cast<uint64_t>(m_read_sp->GetWaitableHandle()),
403 static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
404 static_cast<uint64_t>(bytes_read), error.AsCString());
407 if (bytes_read == 0) {
408 error.Clear(); // End-of-file. Do not automatically close; pass along for
409 // the end-of-file handlers.
410 status = eConnectionStatusEndOfFile;
417 uint32_t error_value = error.GetError();
418 switch (error_value) {
419 case EAGAIN: // The file was marked for non-blocking I/O, and no data were
421 if (m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
422 status = eConnectionStatusTimedOut;
424 status = eConnectionStatusSuccess;
427 case EFAULT: // Buf points outside the allocated address space.
428 case EINTR: // A read from a slow device was interrupted before any data
429 // arrived by the delivery of a signal.
430 case EINVAL: // The pointer associated with fildes was negative.
431 case EIO: // An I/O error occurred while reading from the file system.
432 // The process group is orphaned.
433 // The file is a regular file, nbyte is greater than 0,
434 // the starting position is before the end-of-file, and
435 // the starting position is greater than or equal to the
436 // offset maximum established for the open file
437 // descriptor associated with fildes.
438 case EISDIR: // An attempt is made to read a directory.
439 case ENOBUFS: // An attempt to allocate a memory buffer fails.
440 case ENOMEM: // Insufficient memory is available.
441 status = eConnectionStatusError;
442 break; // Break to close....
444 case ENOENT: // no such file or directory
445 case EBADF: // fildes is not a valid file or socket descriptor open for
447 case ENXIO: // An action is requested of a device that does not exist..
448 // A requested action cannot be performed by the device.
449 case ECONNRESET: // The connection is closed by the peer during a read
450 // attempt on a socket.
451 case ENOTCONN: // A read is attempted on an unconnected socket.
452 status = eConnectionStatusLostConnection;
453 break; // Break to close....
455 case ETIMEDOUT: // A transmission timeout occurs during a read attempt on a
457 status = eConnectionStatusTimedOut;
461 LLDB_LOG(log, "this = {0}, unexpected error: {1}", this,
462 llvm::sys::StrError(error_value));
463 status = eConnectionStatusError;
464 break; // Break to close....
472 size_t ConnectionFileDescriptor::Write(const void *src, size_t src_len,
473 ConnectionStatus &status,
475 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
478 "%p ConnectionFileDescriptor::Write (src = %p, src_len = %" PRIu64 ")",
479 static_cast<void *>(this), static_cast<const void *>(src),
480 static_cast<uint64_t>(src_len));
482 if (!IsConnected()) {
484 error_ptr->SetErrorString("not connected");
485 status = eConnectionStatusNoConnection;
491 size_t bytes_sent = src_len;
492 error = m_write_sp->Write(src, bytes_sent);
495 log->Printf("%p ConnectionFileDescriptor::Write(fd = %" PRIu64
496 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64
498 static_cast<void *>(this),
499 static_cast<uint64_t>(m_write_sp->GetWaitableHandle()),
500 static_cast<const void *>(src), static_cast<uint64_t>(src_len),
501 static_cast<uint64_t>(bytes_sent), error.AsCString());
508 switch (error.GetError()) {
511 status = eConnectionStatusSuccess;
514 case ECONNRESET: // The connection is closed by the peer during a read
515 // attempt on a socket.
516 case ENOTCONN: // A read is attempted on an unconnected socket.
517 status = eConnectionStatusLostConnection;
518 break; // Break to close....
521 status = eConnectionStatusError;
522 break; // Break to close....
528 status = eConnectionStatusSuccess;
532 std::string ConnectionFileDescriptor::GetURI() { return m_uri; }
534 // This ConnectionFileDescriptor::BytesAvailable() uses select() via
538 // - select is consistent across most unix platforms
539 // - The Apple specific version allows for unlimited fds in the fd_sets by
540 // setting the _DARWIN_UNLIMITED_SELECT define prior to including the
541 // required header files.
543 // - on non-Apple platforms, only supports file descriptors up to FD_SETSIZE.
544 // This implementation will assert if it runs into that hard limit to let
545 // users know that another ConnectionFileDescriptor::BytesAvailable() should
546 // be used or a new version of ConnectionFileDescriptor::BytesAvailable()
547 // should be written for the system that is running into the limitations.
550 ConnectionFileDescriptor::BytesAvailable(const Timeout<std::micro> &timeout,
552 // Don't need to take the mutex here separately since we are only called from
554 // ever get used more generally we will need to lock here as well.
556 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_CONNECTION));
557 LLDB_LOG(log, "this = {0}, timeout = {1}", this, timeout);
559 // Make a copy of the file descriptors to make sure we don't
560 // have another thread change these values out from under us
561 // and cause problems in the loop below where like in FS_SET()
562 const IOObject::WaitableHandle handle = m_read_sp->GetWaitableHandle();
563 const int pipe_fd = m_pipe.GetReadFileDescriptor();
565 if (handle != IOObject::kInvalidHandleValue) {
566 SelectHelper select_helper;
568 select_helper.SetTimeout(*timeout);
570 select_helper.FDSetRead(handle);
571 #if defined(_MSC_VER)
572 // select() won't accept pipes on Windows. The entire Windows codepath
574 // converted over to using WaitForMultipleObjects and event HANDLEs, but for
576 // this will allow ::select() to not return an error.
577 const bool have_pipe_fd = false;
579 const bool have_pipe_fd = pipe_fd >= 0;
582 select_helper.FDSetRead(pipe_fd);
584 while (handle == m_read_sp->GetWaitableHandle()) {
586 Status error = select_helper.Select();
592 switch (error.GetError()) {
593 case EBADF: // One of the descriptor sets specified an invalid
595 return eConnectionStatusLostConnection;
597 case EINVAL: // The specified time limit is invalid. One of its
598 // components is negative or too large.
599 default: // Other unknown error
600 return eConnectionStatusError;
603 return eConnectionStatusTimedOut;
605 case EAGAIN: // The kernel was (perhaps temporarily) unable to
606 // allocate the requested number of file descriptors,
607 // or we have non-blocking IO
608 case EINTR: // A signal was delivered before the time limit
609 // expired and before any of the selected events
611 break; // Lets keep reading to until we timeout
614 if (select_helper.FDIsSetRead(handle))
615 return eConnectionStatusSuccess;
617 if (select_helper.FDIsSetRead(pipe_fd)) {
618 // There is an interrupt or exit command in the command pipe
619 // Read the data from that pipe:
622 ssize_t bytes_read = llvm::sys::RetryAfterSignal(-1, ::read, pipe_fd, &c, 1);
623 assert(bytes_read == 1);
628 log->Printf("%p ConnectionFileDescriptor::BytesAvailable() "
629 "got data: %c from the command channel.",
630 static_cast<void *>(this), c);
631 return eConnectionStatusEndOfFile;
633 // Interrupt the current read
634 return eConnectionStatusInterrupted;
642 error_ptr->SetErrorString("not connected");
643 return eConnectionStatusLostConnection;
647 ConnectionFileDescriptor::NamedSocketAccept(llvm::StringRef socket_name,
649 Socket *socket = nullptr;
651 Socket::UnixDomainAccept(socket_name, m_child_processes_inherit, socket);
654 m_write_sp.reset(socket);
655 m_read_sp = m_write_sp;
657 return eConnectionStatusError;
659 m_uri.assign(socket_name);
660 return eConnectionStatusSuccess;
664 ConnectionFileDescriptor::NamedSocketConnect(llvm::StringRef socket_name,
666 Socket *socket = nullptr;
668 Socket::UnixDomainConnect(socket_name, m_child_processes_inherit, socket);
671 m_write_sp.reset(socket);
672 m_read_sp = m_write_sp;
674 return eConnectionStatusError;
676 m_uri.assign(socket_name);
677 return eConnectionStatusSuccess;
680 lldb::ConnectionStatus
681 ConnectionFileDescriptor::UnixAbstractSocketConnect(llvm::StringRef socket_name,
683 Socket *socket = nullptr;
684 Status error = Socket::UnixAbstractConnect(socket_name,
685 m_child_processes_inherit, socket);
688 m_write_sp.reset(socket);
689 m_read_sp = m_write_sp;
691 return eConnectionStatusError;
693 m_uri.assign(socket_name);
694 return eConnectionStatusSuccess;
698 ConnectionFileDescriptor::SocketListenAndAccept(llvm::StringRef s,
700 m_port_predicate.SetValue(0, eBroadcastNever);
702 Socket *socket = nullptr;
703 m_waiting_for_accept = true;
704 Status error = Socket::TcpListen(s, m_child_processes_inherit, socket,
709 return eConnectionStatusError;
711 std::unique_ptr<Socket> listening_socket_up;
713 listening_socket_up.reset(socket);
715 error = listening_socket_up->Accept(socket);
716 listening_socket_up.reset();
720 return eConnectionStatusError;
722 InitializeSocket(socket);
723 return eConnectionStatusSuccess;
726 ConnectionStatus ConnectionFileDescriptor::ConnectTCP(llvm::StringRef s,
728 Socket *socket = nullptr;
729 Status error = Socket::TcpConnect(s, m_child_processes_inherit, socket);
732 m_write_sp.reset(socket);
733 m_read_sp = m_write_sp;
735 return eConnectionStatusError;
738 return eConnectionStatusSuccess;
741 ConnectionStatus ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s,
743 Socket *socket = nullptr;
744 Status error = Socket::UdpConnect(s, m_child_processes_inherit, socket);
747 m_write_sp.reset(socket);
748 m_read_sp = m_write_sp;
750 return eConnectionStatusError;
753 return eConnectionStatusSuccess;
756 uint16_t ConnectionFileDescriptor::GetListeningPort(uint32_t timeout_sec) {
757 uint16_t bound_port = 0;
758 if (timeout_sec == UINT32_MAX)
759 m_port_predicate.WaitForValueNotEqualTo(0, bound_port);
761 m_port_predicate.WaitForValueNotEqualTo(0, bound_port,
762 std::chrono::seconds(timeout_sec));
766 bool ConnectionFileDescriptor::GetChildProcessesInherit() const {
767 return m_child_processes_inherit;
770 void ConnectionFileDescriptor::SetChildProcessesInherit(
771 bool child_processes_inherit) {
772 m_child_processes_inherit = child_processes_inherit;
775 void ConnectionFileDescriptor::InitializeSocket(Socket *socket) {
776 assert(socket->GetSocketProtocol() == Socket::ProtocolTcp);
777 TCPSocket *tcp_socket = static_cast<TCPSocket *>(socket);
779 m_write_sp.reset(socket);
780 m_read_sp = m_write_sp;
782 strm.Printf("connect://%s:%u", tcp_socket->GetRemoteIPAddress().c_str(),
783 tcp_socket->GetRemotePortNumber());
784 m_uri = strm.GetString();