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 that
193 // 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 should make
198 // sure it is. We currently are doing this by trying to get the flags
199 // from the file descriptor and making sure it isn't a bad fd.
201 int flags = ::fcntl(fd, F_GETFL, 0);
202 if (flags == -1 || errno == EBADF) {
204 error_ptr->SetErrorStringWithFormat("stale file descriptor: %s",
208 return eConnectionStatusError;
210 // Don't take ownership of a file descriptor that gets passed to us
211 // since someone else opened the file descriptor and handed it to us.
212 // TODO: Since are using a URL to open connection we should
213 // eventually parse options using the web standard where we have
214 // "fd://123?opt1=value;opt2=value" and we can have an option be
215 // "owns=1" or "owns=0" or something like this to allow us to specify
216 // this. For now, we assume we must assume we don't own it.
218 std::unique_ptr<TCPSocket> tcp_socket;
219 tcp_socket.reset(new TCPSocket(fd, false, false));
220 // Try and get a socket option from this file descriptor to see if
221 // this is a socket and set m_is_socket accordingly.
224 !!tcp_socket->GetOption(SOL_SOCKET, SO_REUSEADDR, resuse);
226 m_read_sp = std::move(tcp_socket);
227 m_write_sp = m_read_sp;
229 m_read_sp.reset(new File(fd, false));
230 m_write_sp.reset(new File(fd, false));
233 return eConnectionStatusSuccess;
238 error_ptr->SetErrorStringWithFormat("invalid file descriptor: \"%s\"",
242 return eConnectionStatusError;
243 } else if ((addr = GetURLAddress(path, FILE_SCHEME))) {
244 std::string addr_str = addr->str();
246 int fd = llvm::sys::RetryAfterSignal(-1, ::open, addr_str.c_str(), O_RDWR);
249 error_ptr->SetErrorToErrno();
250 return eConnectionStatusError;
254 // Set up serial terminal emulation
255 struct termios options;
256 ::tcgetattr(fd, &options);
258 // Set port speed to maximum
259 ::cfsetospeed(&options, B115200);
260 ::cfsetispeed(&options, B115200);
262 // Raw input, disable echo and signals
263 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
265 // Make sure only one character is needed to return from a read
266 options.c_cc[VMIN] = 1;
267 options.c_cc[VTIME] = 0;
269 ::tcsetattr(fd, TCSANOW, &options);
272 int flags = ::fcntl(fd, F_GETFL, 0);
274 if ((flags & O_NONBLOCK) == 0) {
276 ::fcntl(fd, F_SETFL, flags);
279 m_read_sp.reset(new File(fd, true));
280 m_write_sp.reset(new File(fd, false));
281 return eConnectionStatusSuccess;
285 error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'",
287 return eConnectionStatusError;
290 error_ptr->SetErrorString("invalid connect arguments");
291 return eConnectionStatusError;
294 bool ConnectionFileDescriptor::InterruptRead() {
295 size_t bytes_written = 0;
296 Status result = m_pipe.Write("i", 1, bytes_written);
297 return result.Success();
300 ConnectionStatus ConnectionFileDescriptor::Disconnect(Status *error_ptr) {
301 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
303 log->Printf("%p ConnectionFileDescriptor::Disconnect ()",
304 static_cast<void *>(this));
306 ConnectionStatus status = eConnectionStatusSuccess;
308 if (!IsConnected()) {
311 "%p ConnectionFileDescriptor::Disconnect(): Nothing to disconnect",
312 static_cast<void *>(this));
313 return eConnectionStatusSuccess;
316 if (m_read_sp && m_read_sp->IsValid() &&
317 m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
318 static_cast<Socket &>(*m_read_sp).PreDisconnect();
320 // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is
321 // quite likely because somebody is doing a blocking read on our file
322 // descriptor. If that's the case, then send the "q" char to the command
323 // file channel so the read will wake up and the connection will then know to
326 m_shutting_down = true;
328 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
329 if (!locker.try_lock()) {
330 if (m_pipe.CanWrite()) {
331 size_t bytes_written = 0;
332 Status result = m_pipe.Write("q", 1, bytes_written);
334 log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get "
335 "the lock, sent 'q' to %d, error = '%s'.",
336 static_cast<void *>(this), m_pipe.GetWriteFileDescriptor(),
339 log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the "
340 "lock, but no command pipe is available.",
341 static_cast<void *>(this));
346 Status error = m_read_sp->Close();
347 Status error2 = m_write_sp->Close();
348 if (error.Fail() || error2.Fail())
349 status = eConnectionStatusError;
351 *error_ptr = error.Fail() ? error : error2;
353 // Close any pipes we were using for async interrupts
357 m_shutting_down = false;
361 size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
362 const Timeout<std::micro> &timeout,
363 ConnectionStatus &status,
365 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
367 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
368 if (!locker.try_lock()) {
370 log->Printf("%p ConnectionFileDescriptor::Read () failed to get the "
372 static_cast<void *>(this));
374 error_ptr->SetErrorString("failed to get the connection lock for read.");
376 status = eConnectionStatusTimedOut;
380 if (m_shutting_down) {
381 status = eConnectionStatusError;
385 status = BytesAvailable(timeout, error_ptr);
386 if (status != eConnectionStatusSuccess)
390 size_t bytes_read = dst_len;
391 error = m_read_sp->Read(dst, bytes_read);
394 log->Printf("%p ConnectionFileDescriptor::Read() fd = %" PRIu64
395 ", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s",
396 static_cast<void *>(this),
397 static_cast<uint64_t>(m_read_sp->GetWaitableHandle()),
398 static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
399 static_cast<uint64_t>(bytes_read), error.AsCString());
402 if (bytes_read == 0) {
403 error.Clear(); // End-of-file. Do not automatically close; pass along for
404 // the end-of-file handlers.
405 status = eConnectionStatusEndOfFile;
412 uint32_t error_value = error.GetError();
413 switch (error_value) {
414 case EAGAIN: // The file was marked for non-blocking I/O, and no data were
416 if (m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
417 status = eConnectionStatusTimedOut;
419 status = eConnectionStatusSuccess;
422 case EFAULT: // Buf points outside the allocated address space.
423 case EINTR: // A read from a slow device was interrupted before any data
424 // arrived by the delivery of a signal.
425 case EINVAL: // The pointer associated with fildes was negative.
426 case EIO: // An I/O error occurred while reading from the file system.
427 // The process group is orphaned.
428 // The file is a regular file, nbyte is greater than 0, the
429 // starting position is before the end-of-file, and the
430 // starting position is greater than or equal to the offset
431 // maximum established for the open file descriptor
432 // associated with fildes.
433 case EISDIR: // An attempt is made to read a directory.
434 case ENOBUFS: // An attempt to allocate a memory buffer fails.
435 case ENOMEM: // Insufficient memory is available.
436 status = eConnectionStatusError;
437 break; // Break to close....
439 case ENOENT: // no such file or directory
440 case EBADF: // fildes is not a valid file or socket descriptor open for
442 case ENXIO: // An action is requested of a device that does not exist..
443 // A requested action cannot be performed by the device.
444 case ECONNRESET: // The connection is closed by the peer during a read
445 // attempt on a socket.
446 case ENOTCONN: // A read is attempted on an unconnected socket.
447 status = eConnectionStatusLostConnection;
448 break; // Break to close....
450 case ETIMEDOUT: // A transmission timeout occurs during a read attempt on a
452 status = eConnectionStatusTimedOut;
456 LLDB_LOG(log, "this = {0}, unexpected error: {1}", this,
457 llvm::sys::StrError(error_value));
458 status = eConnectionStatusError;
459 break; // Break to close....
467 size_t ConnectionFileDescriptor::Write(const void *src, size_t src_len,
468 ConnectionStatus &status,
470 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
473 "%p ConnectionFileDescriptor::Write (src = %p, src_len = %" PRIu64 ")",
474 static_cast<void *>(this), static_cast<const void *>(src),
475 static_cast<uint64_t>(src_len));
477 if (!IsConnected()) {
479 error_ptr->SetErrorString("not connected");
480 status = eConnectionStatusNoConnection;
486 size_t bytes_sent = src_len;
487 error = m_write_sp->Write(src, bytes_sent);
490 log->Printf("%p ConnectionFileDescriptor::Write(fd = %" PRIu64
491 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64
493 static_cast<void *>(this),
494 static_cast<uint64_t>(m_write_sp->GetWaitableHandle()),
495 static_cast<const void *>(src), static_cast<uint64_t>(src_len),
496 static_cast<uint64_t>(bytes_sent), error.AsCString());
503 switch (error.GetError()) {
506 status = eConnectionStatusSuccess;
509 case ECONNRESET: // The connection is closed by the peer during a read
510 // attempt on a socket.
511 case ENOTCONN: // A read is attempted on an unconnected socket.
512 status = eConnectionStatusLostConnection;
513 break; // Break to close....
516 status = eConnectionStatusError;
517 break; // Break to close....
523 status = eConnectionStatusSuccess;
527 std::string ConnectionFileDescriptor::GetURI() { return m_uri; }
529 // This ConnectionFileDescriptor::BytesAvailable() uses select() via
533 // - select is consistent across most unix platforms
534 // - The Apple specific version allows for unlimited fds in the fd_sets by
535 // setting the _DARWIN_UNLIMITED_SELECT define prior to including the
536 // required header files.
538 // - on non-Apple platforms, only supports file descriptors up to FD_SETSIZE.
539 // This implementation will assert if it runs into that hard limit to let
540 // users know that another ConnectionFileDescriptor::BytesAvailable() should
541 // be used or a new version of ConnectionFileDescriptor::BytesAvailable()
542 // should be written for the system that is running into the limitations.
545 ConnectionFileDescriptor::BytesAvailable(const Timeout<std::micro> &timeout,
547 // Don't need to take the mutex here separately since we are only called from
548 // Read. If we ever get used more generally we will need to lock here as
551 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_CONNECTION));
552 LLDB_LOG(log, "this = {0}, timeout = {1}", this, timeout);
554 // Make a copy of the file descriptors to make sure we don't have another
555 // thread change these values out from under us and cause problems in the
556 // loop below where like in FS_SET()
557 const IOObject::WaitableHandle handle = m_read_sp->GetWaitableHandle();
558 const int pipe_fd = m_pipe.GetReadFileDescriptor();
560 if (handle != IOObject::kInvalidHandleValue) {
561 SelectHelper select_helper;
563 select_helper.SetTimeout(*timeout);
565 select_helper.FDSetRead(handle);
566 #if defined(_MSC_VER)
567 // select() won't accept pipes on Windows. The entire Windows codepath
568 // needs to be converted over to using WaitForMultipleObjects and event
569 // HANDLEs, but for now at least this will allow ::select() to not return
571 const bool have_pipe_fd = false;
573 const bool have_pipe_fd = pipe_fd >= 0;
576 select_helper.FDSetRead(pipe_fd);
578 while (handle == m_read_sp->GetWaitableHandle()) {
580 Status error = select_helper.Select();
586 switch (error.GetError()) {
587 case EBADF: // One of the descriptor sets specified an invalid
589 return eConnectionStatusLostConnection;
591 case EINVAL: // The specified time limit is invalid. One of its
592 // components is negative or too large.
593 default: // Other unknown error
594 return eConnectionStatusError;
597 return eConnectionStatusTimedOut;
599 case EAGAIN: // The kernel was (perhaps temporarily) unable to
600 // allocate the requested number of file descriptors, or
601 // we have non-blocking IO
602 case EINTR: // A signal was delivered before the time limit
603 // expired and before any of the selected events occurred.
604 break; // Lets keep reading to until we timeout
607 if (select_helper.FDIsSetRead(handle))
608 return eConnectionStatusSuccess;
610 if (select_helper.FDIsSetRead(pipe_fd)) {
611 // There is an interrupt or exit command in the command pipe Read the
612 // data from that pipe:
615 ssize_t bytes_read = llvm::sys::RetryAfterSignal(-1, ::read, pipe_fd, &c, 1);
616 assert(bytes_read == 1);
621 log->Printf("%p ConnectionFileDescriptor::BytesAvailable() "
622 "got data: %c from the command channel.",
623 static_cast<void *>(this), c);
624 return eConnectionStatusEndOfFile;
626 // Interrupt the current read
627 return eConnectionStatusInterrupted;
635 error_ptr->SetErrorString("not connected");
636 return eConnectionStatusLostConnection;
640 ConnectionFileDescriptor::NamedSocketAccept(llvm::StringRef socket_name,
642 Socket *socket = nullptr;
644 Socket::UnixDomainAccept(socket_name, m_child_processes_inherit, socket);
647 m_write_sp.reset(socket);
648 m_read_sp = m_write_sp;
650 return eConnectionStatusError;
652 m_uri.assign(socket_name);
653 return eConnectionStatusSuccess;
657 ConnectionFileDescriptor::NamedSocketConnect(llvm::StringRef socket_name,
659 Socket *socket = nullptr;
661 Socket::UnixDomainConnect(socket_name, m_child_processes_inherit, socket);
664 m_write_sp.reset(socket);
665 m_read_sp = m_write_sp;
667 return eConnectionStatusError;
669 m_uri.assign(socket_name);
670 return eConnectionStatusSuccess;
673 lldb::ConnectionStatus
674 ConnectionFileDescriptor::UnixAbstractSocketConnect(llvm::StringRef socket_name,
676 Socket *socket = nullptr;
677 Status error = Socket::UnixAbstractConnect(socket_name,
678 m_child_processes_inherit, socket);
681 m_write_sp.reset(socket);
682 m_read_sp = m_write_sp;
684 return eConnectionStatusError;
686 m_uri.assign(socket_name);
687 return eConnectionStatusSuccess;
691 ConnectionFileDescriptor::SocketListenAndAccept(llvm::StringRef s,
693 m_port_predicate.SetValue(0, eBroadcastNever);
695 Socket *socket = nullptr;
696 m_waiting_for_accept = true;
697 Status error = Socket::TcpListen(s, m_child_processes_inherit, socket,
702 return eConnectionStatusError;
704 std::unique_ptr<Socket> listening_socket_up;
706 listening_socket_up.reset(socket);
708 error = listening_socket_up->Accept(socket);
709 listening_socket_up.reset();
713 return eConnectionStatusError;
715 InitializeSocket(socket);
716 return eConnectionStatusSuccess;
719 ConnectionStatus ConnectionFileDescriptor::ConnectTCP(llvm::StringRef s,
721 Socket *socket = nullptr;
722 Status error = Socket::TcpConnect(s, m_child_processes_inherit, socket);
725 m_write_sp.reset(socket);
726 m_read_sp = m_write_sp;
728 return eConnectionStatusError;
731 return eConnectionStatusSuccess;
734 ConnectionStatus ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s,
736 Socket *socket = nullptr;
737 Status error = Socket::UdpConnect(s, m_child_processes_inherit, socket);
740 m_write_sp.reset(socket);
741 m_read_sp = m_write_sp;
743 return eConnectionStatusError;
746 return eConnectionStatusSuccess;
750 ConnectionFileDescriptor::GetListeningPort(const Timeout<std::micro> &timeout) {
751 auto Result = m_port_predicate.WaitForValueNotEqualTo(0, timeout);
752 return Result ? *Result : 0;
755 bool ConnectionFileDescriptor::GetChildProcessesInherit() const {
756 return m_child_processes_inherit;
759 void ConnectionFileDescriptor::SetChildProcessesInherit(
760 bool child_processes_inherit) {
761 m_child_processes_inherit = child_processes_inherit;
764 void ConnectionFileDescriptor::InitializeSocket(Socket *socket) {
765 assert(socket->GetSocketProtocol() == Socket::ProtocolTcp);
766 TCPSocket *tcp_socket = static_cast<TCPSocket *>(socket);
768 m_write_sp.reset(socket);
769 m_read_sp = m_write_sp;
771 strm.Printf("connect://%s:%u", tcp_socket->GetRemoteIPAddress().c_str(),
772 tcp_socket->GetRemotePortNumber());
773 m_uri = strm.GetString();