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/IOObject.h"
20 #include "lldb/Host/Socket.h"
21 #include "lldb/Host/SocketAddress.h"
22 #include "lldb/Utility/SelectHelper.h"
29 #include <sys/types.h>
31 #ifndef LLDB_DISABLE_POSIX
38 // Other libraries and framework includes
39 #include "llvm/Support/ErrorHandling.h"
40 #if defined(__APPLE__)
41 #include "llvm/ADT/SmallVector.h"
44 #include "lldb/Core/Communication.h"
45 #include "lldb/Core/Timer.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"
53 using namespace lldb_private;
55 const char *ConnectionFileDescriptor::LISTEN_SCHEME = "listen";
56 const char *ConnectionFileDescriptor::ACCEPT_SCHEME = "accept";
57 const char *ConnectionFileDescriptor::UNIX_ACCEPT_SCHEME = "unix-accept";
58 const char *ConnectionFileDescriptor::CONNECT_SCHEME = "connect";
59 const char *ConnectionFileDescriptor::TCP_CONNECT_SCHEME = "tcp-connect";
60 const char *ConnectionFileDescriptor::UDP_SCHEME = "udp";
61 const char *ConnectionFileDescriptor::UNIX_CONNECT_SCHEME = "unix-connect";
62 const char *ConnectionFileDescriptor::UNIX_ABSTRACT_CONNECT_SCHEME =
63 "unix-abstract-connect";
64 const char *ConnectionFileDescriptor::FD_SCHEME = "fd";
65 const char *ConnectionFileDescriptor::FILE_SCHEME = "file";
69 llvm::Optional<llvm::StringRef> GetURLAddress(llvm::StringRef url,
70 llvm::StringRef scheme) {
71 if (!url.consume_front(scheme))
73 if (!url.consume_front("://"))
79 ConnectionFileDescriptor::ConnectionFileDescriptor(bool child_processes_inherit)
80 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
81 m_waiting_for_accept(false),
82 m_child_processes_inherit(child_processes_inherit) {
83 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
86 log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor ()",
87 static_cast<void *>(this));
90 ConnectionFileDescriptor::ConnectionFileDescriptor(int fd, bool owns_fd)
91 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
92 m_waiting_for_accept(false), m_child_processes_inherit(false) {
93 m_write_sp.reset(new File(fd, owns_fd));
94 m_read_sp.reset(new File(fd, false));
96 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
99 log->Printf("%p ConnectionFileDescriptor::ConnectionFileDescriptor (fd = "
101 static_cast<void *>(this), fd, owns_fd);
105 ConnectionFileDescriptor::ConnectionFileDescriptor(Socket *socket)
106 : Connection(), m_pipe(), m_mutex(), m_shutting_down(false),
107 m_waiting_for_accept(false), m_child_processes_inherit(false) {
108 InitializeSocket(socket);
111 ConnectionFileDescriptor::~ConnectionFileDescriptor() {
112 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION |
113 LIBLLDB_LOG_OBJECT));
115 log->Printf("%p ConnectionFileDescriptor::~ConnectionFileDescriptor ()",
116 static_cast<void *>(this));
121 void ConnectionFileDescriptor::OpenCommandPipe() {
124 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
125 // Make the command file descriptor here:
126 Error result = m_pipe.CreateNew(m_child_processes_inherit);
127 if (!result.Success()) {
129 log->Printf("%p ConnectionFileDescriptor::OpenCommandPipe () - could not "
131 static_cast<void *>(this), result.AsCString());
134 log->Printf("%p ConnectionFileDescriptor::OpenCommandPipe() - success "
135 "readfd=%d writefd=%d",
136 static_cast<void *>(this), m_pipe.GetReadFileDescriptor(),
137 m_pipe.GetWriteFileDescriptor());
141 void ConnectionFileDescriptor::CloseCommandPipe() {
142 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
144 log->Printf("%p ConnectionFileDescriptor::CloseCommandPipe()",
145 static_cast<void *>(this));
150 bool ConnectionFileDescriptor::IsConnected() const {
151 return (m_read_sp && m_read_sp->IsValid()) ||
152 (m_write_sp && m_write_sp->IsValid());
155 ConnectionStatus ConnectionFileDescriptor::Connect(llvm::StringRef path,
157 std::lock_guard<std::recursive_mutex> guard(m_mutex);
158 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
160 log->Printf("%p ConnectionFileDescriptor::Connect (url = '%s')",
161 static_cast<void *>(this), path.str().c_str());
166 llvm::Optional<llvm::StringRef> addr;
167 if ((addr = GetURLAddress(path, LISTEN_SCHEME))) {
168 // listen://HOST:PORT
169 return SocketListenAndAccept(*addr, error_ptr);
170 } else if ((addr = GetURLAddress(path, ACCEPT_SCHEME))) {
172 return NamedSocketAccept(*addr, error_ptr);
173 } else if ((addr = GetURLAddress(path, UNIX_ACCEPT_SCHEME))) {
175 return NamedSocketAccept(*addr, error_ptr);
176 } else if ((addr = GetURLAddress(path, CONNECT_SCHEME))) {
177 return ConnectTCP(*addr, error_ptr);
178 } else if ((addr = GetURLAddress(path, TCP_CONNECT_SCHEME))) {
179 return ConnectTCP(*addr, error_ptr);
180 } else if ((addr = GetURLAddress(path, UDP_SCHEME))) {
181 return ConnectUDP(*addr, error_ptr);
182 } else if ((addr = GetURLAddress(path, UNIX_CONNECT_SCHEME))) {
183 // unix-connect://SOCKNAME
184 return NamedSocketConnect(*addr, error_ptr);
185 } else if ((addr = GetURLAddress(path, UNIX_ABSTRACT_CONNECT_SCHEME))) {
186 // unix-abstract-connect://SOCKNAME
187 return UnixAbstractSocketConnect(*addr, error_ptr);
189 #ifndef LLDB_DISABLE_POSIX
190 else if ((addr = GetURLAddress(path, FD_SCHEME))) {
191 // Just passing a native file descriptor within this current process
192 // that is already opened (possibly from a service or other source).
195 if (!addr->getAsInteger(0, fd)) {
196 // We have what looks to be a valid file descriptor, but we
197 // should make sure it is. We currently are doing this by trying to
198 // get the flags from the file descriptor and making sure it
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
211 // to us since someone else opened the file descriptor and
213 // TODO: Since are using a URL to open connection we should
214 // eventually parse options using the web standard where we
215 // have "fd://123?opt1=value;opt2=value" and we can have an
216 // option be "owns=1" or "owns=0" or something like this to
217 // allow us to specify this. For now, we assume we must
218 // assume we don't own it.
220 std::unique_ptr<TCPSocket> tcp_socket;
221 tcp_socket.reset(new TCPSocket(fd, false));
222 // Try and get a socket option from this file descriptor to
223 // see if this is a socket and set m_is_socket accordingly.
226 !!tcp_socket->GetOption(SOL_SOCKET, SO_REUSEADDR, resuse);
228 m_read_sp = std::move(tcp_socket);
229 m_write_sp = m_read_sp;
231 m_read_sp.reset(new File(fd, false));
232 m_write_sp.reset(new File(fd, false));
235 return eConnectionStatusSuccess;
240 error_ptr->SetErrorStringWithFormat("invalid file descriptor: \"%s\"",
244 return eConnectionStatusError;
245 } else if ((addr = GetURLAddress(path, FILE_SCHEME))) {
246 std::string addr_str = addr->str();
250 fd = ::open(addr_str.c_str(), O_RDWR);
251 } while (fd == -1 && errno == EINTR);
255 error_ptr->SetErrorToErrno();
256 return eConnectionStatusError;
260 // Set up serial terminal emulation
261 struct termios options;
262 ::tcgetattr(fd, &options);
264 // Set port speed to maximum
265 ::cfsetospeed(&options, B115200);
266 ::cfsetispeed(&options, B115200);
268 // Raw input, disable echo and signals
269 options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);
271 // Make sure only one character is needed to return from a read
272 options.c_cc[VMIN] = 1;
273 options.c_cc[VTIME] = 0;
275 ::tcsetattr(fd, TCSANOW, &options);
278 int flags = ::fcntl(fd, F_GETFL, 0);
280 if ((flags & O_NONBLOCK) == 0) {
282 ::fcntl(fd, F_SETFL, flags);
285 m_read_sp.reset(new File(fd, true));
286 m_write_sp.reset(new File(fd, false));
287 return eConnectionStatusSuccess;
291 error_ptr->SetErrorStringWithFormat("unsupported connection URL: '%s'",
293 return eConnectionStatusError;
296 error_ptr->SetErrorString("invalid connect arguments");
297 return eConnectionStatusError;
300 bool ConnectionFileDescriptor::InterruptRead() {
301 size_t bytes_written = 0;
302 Error result = m_pipe.Write("i", 1, bytes_written);
303 return result.Success();
306 ConnectionStatus ConnectionFileDescriptor::Disconnect(Error *error_ptr) {
307 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
309 log->Printf("%p ConnectionFileDescriptor::Disconnect ()",
310 static_cast<void *>(this));
312 ConnectionStatus status = eConnectionStatusSuccess;
314 if (!IsConnected()) {
317 "%p ConnectionFileDescriptor::Disconnect(): Nothing to disconnect",
318 static_cast<void *>(this));
319 return eConnectionStatusSuccess;
322 if (m_read_sp && m_read_sp->IsValid() &&
323 m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
324 static_cast<Socket &>(*m_read_sp).PreDisconnect();
326 // Try to get the ConnectionFileDescriptor's mutex. If we fail, that is quite
328 // because somebody is doing a blocking read on our file descriptor. If
330 // then send the "q" char to the command file channel so the read will wake up
331 // and the connection
332 // will then know to shut down.
334 m_shutting_down = true;
336 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
337 if (!locker.try_lock()) {
338 if (m_pipe.CanWrite()) {
339 size_t bytes_written = 0;
340 Error result = m_pipe.Write("q", 1, bytes_written);
342 log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get "
343 "the lock, sent 'q' to %d, error = '%s'.",
344 static_cast<void *>(this), m_pipe.GetWriteFileDescriptor(),
347 log->Printf("%p ConnectionFileDescriptor::Disconnect(): Couldn't get the "
348 "lock, but no command pipe is available.",
349 static_cast<void *>(this));
354 Error error = m_read_sp->Close();
355 Error error2 = m_write_sp->Close();
356 if (error.Fail() || error2.Fail())
357 status = eConnectionStatusError;
359 *error_ptr = error.Fail() ? error : error2;
361 // Close any pipes we were using for async interrupts
365 m_shutting_down = false;
369 size_t ConnectionFileDescriptor::Read(void *dst, size_t dst_len,
370 const Timeout<std::micro> &timeout,
371 ConnectionStatus &status,
373 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
375 std::unique_lock<std::recursive_mutex> locker(m_mutex, std::defer_lock);
376 if (!locker.try_lock()) {
378 log->Printf("%p ConnectionFileDescriptor::Read () failed to get the "
380 static_cast<void *>(this));
382 error_ptr->SetErrorString("failed to get the connection lock for read.");
384 status = eConnectionStatusTimedOut;
388 if (m_shutting_down) {
389 status = eConnectionStatusError;
393 status = BytesAvailable(timeout, error_ptr);
394 if (status != eConnectionStatusSuccess)
398 size_t bytes_read = dst_len;
399 error = m_read_sp->Read(dst, bytes_read);
402 log->Printf("%p ConnectionFileDescriptor::Read() fd = %" PRIu64
403 ", dst = %p, dst_len = %" PRIu64 ") => %" PRIu64 ", error = %s",
404 static_cast<void *>(this),
405 static_cast<uint64_t>(m_read_sp->GetWaitableHandle()),
406 static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
407 static_cast<uint64_t>(bytes_read), error.AsCString());
410 if (bytes_read == 0) {
411 error.Clear(); // End-of-file. Do not automatically close; pass along for
412 // the end-of-file handlers.
413 status = eConnectionStatusEndOfFile;
420 uint32_t error_value = error.GetError();
421 switch (error_value) {
422 case EAGAIN: // The file was marked for non-blocking I/O, and no data were
424 if (m_read_sp->GetFdType() == IOObject::eFDTypeSocket)
425 status = eConnectionStatusTimedOut;
427 status = eConnectionStatusSuccess;
430 case EFAULT: // Buf points outside the allocated address space.
431 case EINTR: // A read from a slow device was interrupted before any data
432 // arrived by the delivery of a signal.
433 case EINVAL: // The pointer associated with fildes was negative.
434 case EIO: // An I/O error occurred while reading from the file system.
435 // The process group is orphaned.
436 // The file is a regular file, nbyte is greater than 0,
437 // the starting position is before the end-of-file, and
438 // the starting position is greater than or equal to the
439 // offset maximum established for the open file
440 // descriptor associated with fildes.
441 case EISDIR: // An attempt is made to read a directory.
442 case ENOBUFS: // An attempt to allocate a memory buffer fails.
443 case ENOMEM: // Insufficient memory is available.
444 status = eConnectionStatusError;
445 break; // Break to close....
447 case ENOENT: // no such file or directory
448 case EBADF: // fildes is not a valid file or socket descriptor open for
450 case ENXIO: // An action is requested of a device that does not exist..
451 // A requested action cannot be performed by the device.
452 case ECONNRESET: // The connection is closed by the peer during a read
453 // attempt on a socket.
454 case ENOTCONN: // A read is attempted on an unconnected socket.
455 status = eConnectionStatusLostConnection;
456 break; // Break to close....
458 case ETIMEDOUT: // A transmission timeout occurs during a read attempt on a
460 status = eConnectionStatusTimedOut;
466 "%p ConnectionFileDescriptor::Read (), unexpected error: %s",
467 static_cast<void *>(this), strerror(error_value));
468 status = eConnectionStatusError;
469 break; // Break to close....
477 size_t ConnectionFileDescriptor::Write(const void *src, size_t src_len,
478 ConnectionStatus &status,
480 Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION));
483 "%p ConnectionFileDescriptor::Write (src = %p, src_len = %" PRIu64 ")",
484 static_cast<void *>(this), static_cast<const void *>(src),
485 static_cast<uint64_t>(src_len));
487 if (!IsConnected()) {
489 error_ptr->SetErrorString("not connected");
490 status = eConnectionStatusNoConnection;
496 size_t bytes_sent = src_len;
497 error = m_write_sp->Write(src, bytes_sent);
500 log->Printf("%p ConnectionFileDescriptor::Write(fd = %" PRIu64
501 ", src = %p, src_len = %" PRIu64 ") => %" PRIu64
503 static_cast<void *>(this),
504 static_cast<uint64_t>(m_write_sp->GetWaitableHandle()),
505 static_cast<const void *>(src), static_cast<uint64_t>(src_len),
506 static_cast<uint64_t>(bytes_sent), error.AsCString());
513 switch (error.GetError()) {
516 status = eConnectionStatusSuccess;
519 case ECONNRESET: // The connection is closed by the peer during a read
520 // attempt on a socket.
521 case ENOTCONN: // A read is attempted on an unconnected socket.
522 status = eConnectionStatusLostConnection;
523 break; // Break to close....
526 status = eConnectionStatusError;
527 break; // Break to close....
533 status = eConnectionStatusSuccess;
537 std::string ConnectionFileDescriptor::GetURI() { return m_uri; }
539 // This ConnectionFileDescriptor::BytesAvailable() uses select() via
543 // - select is consistent across most unix platforms
544 // - The Apple specific version allows for unlimited fds in the fd_sets by
545 // setting the _DARWIN_UNLIMITED_SELECT define prior to including the
546 // required header files.
548 // - on non-Apple platforms, only supports file descriptors up to FD_SETSIZE.
549 // This implementation will assert if it runs into that hard limit to let
550 // users know that another ConnectionFileDescriptor::BytesAvailable() should
551 // be used or a new version of ConnectionFileDescriptor::BytesAvailable()
552 // should be written for the system that is running into the limitations.
555 ConnectionFileDescriptor::BytesAvailable(const Timeout<std::micro> &timeout,
557 // Don't need to take the mutex here separately since we are only called from
559 // ever get used more generally we will need to lock here as well.
561 Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_CONNECTION));
562 LLDB_LOG(log, "this = {0}, timeout = {1}", this, timeout);
564 // Make a copy of the file descriptors to make sure we don't
565 // have another thread change these values out from under us
566 // and cause problems in the loop below where like in FS_SET()
567 const IOObject::WaitableHandle handle = m_read_sp->GetWaitableHandle();
568 const int pipe_fd = m_pipe.GetReadFileDescriptor();
570 if (handle != IOObject::kInvalidHandleValue) {
571 SelectHelper select_helper;
573 select_helper.SetTimeout(*timeout);
575 select_helper.FDSetRead(handle);
576 #if defined(_MSC_VER)
577 // select() won't accept pipes on Windows. The entire Windows codepath
579 // converted over to using WaitForMultipleObjects and event HANDLEs, but for
581 // this will allow ::select() to not return an error.
582 const bool have_pipe_fd = false;
584 const bool have_pipe_fd = pipe_fd >= 0;
587 select_helper.FDSetRead(pipe_fd);
589 while (handle == m_read_sp->GetWaitableHandle()) {
591 Error error = select_helper.Select();
597 switch (error.GetError()) {
598 case EBADF: // One of the descriptor sets specified an invalid
600 return eConnectionStatusLostConnection;
602 case EINVAL: // The specified time limit is invalid. One of its
603 // components is negative or too large.
604 default: // Other unknown error
605 return eConnectionStatusError;
608 return eConnectionStatusTimedOut;
610 case EAGAIN: // The kernel was (perhaps temporarily) unable to
611 // allocate the requested number of file descriptors,
612 // or we have non-blocking IO
613 case EINTR: // A signal was delivered before the time limit
614 // expired and before any of the selected events
616 break; // Lets keep reading to until we timeout
619 if (select_helper.FDIsSetRead(handle))
620 return eConnectionStatusSuccess;
622 if (select_helper.FDIsSetRead(pipe_fd)) {
623 // There is an interrupt or exit command in the command pipe
624 // Read the data from that pipe:
630 bytes_read = ::read(pipe_fd, buffer, sizeof(buffer));
631 } while (bytes_read < 0 && errno == EINTR);
636 log->Printf("%p ConnectionFileDescriptor::BytesAvailable() "
637 "got data: %c from the command channel.",
638 static_cast<void *>(this), buffer[0]);
639 return eConnectionStatusEndOfFile;
641 // Interrupt the current read
642 return eConnectionStatusInterrupted;
650 error_ptr->SetErrorString("not connected");
651 return eConnectionStatusLostConnection;
655 ConnectionFileDescriptor::NamedSocketAccept(llvm::StringRef socket_name,
657 Socket *socket = nullptr;
659 Socket::UnixDomainAccept(socket_name, m_child_processes_inherit, socket);
662 m_write_sp.reset(socket);
663 m_read_sp = m_write_sp;
665 return eConnectionStatusError;
667 m_uri.assign(socket_name);
668 return eConnectionStatusSuccess;
672 ConnectionFileDescriptor::NamedSocketConnect(llvm::StringRef socket_name,
674 Socket *socket = nullptr;
676 Socket::UnixDomainConnect(socket_name, m_child_processes_inherit, socket);
679 m_write_sp.reset(socket);
680 m_read_sp = m_write_sp;
682 return eConnectionStatusError;
684 m_uri.assign(socket_name);
685 return eConnectionStatusSuccess;
688 lldb::ConnectionStatus
689 ConnectionFileDescriptor::UnixAbstractSocketConnect(llvm::StringRef socket_name,
691 Socket *socket = nullptr;
692 Error error = Socket::UnixAbstractConnect(socket_name,
693 m_child_processes_inherit, socket);
696 m_write_sp.reset(socket);
697 m_read_sp = m_write_sp;
699 return eConnectionStatusError;
701 m_uri.assign(socket_name);
702 return eConnectionStatusSuccess;
706 ConnectionFileDescriptor::SocketListenAndAccept(llvm::StringRef s,
708 m_port_predicate.SetValue(0, eBroadcastNever);
710 Socket *socket = nullptr;
711 m_waiting_for_accept = true;
712 Error error = Socket::TcpListen(s, m_child_processes_inherit, socket,
717 return eConnectionStatusError;
719 std::unique_ptr<Socket> listening_socket_up;
721 listening_socket_up.reset(socket);
723 error = listening_socket_up->Accept(s, m_child_processes_inherit, socket);
724 listening_socket_up.reset();
728 return eConnectionStatusError;
730 InitializeSocket(socket);
731 return eConnectionStatusSuccess;
734 ConnectionStatus ConnectionFileDescriptor::ConnectTCP(llvm::StringRef s,
736 Socket *socket = nullptr;
737 Error error = Socket::TcpConnect(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;
749 ConnectionStatus ConnectionFileDescriptor::ConnectUDP(llvm::StringRef s,
751 Socket *socket = nullptr;
752 Error error = Socket::UdpConnect(s, m_child_processes_inherit, socket);
755 m_write_sp.reset(socket);
756 m_read_sp = m_write_sp;
758 return eConnectionStatusError;
761 return eConnectionStatusSuccess;
764 uint16_t ConnectionFileDescriptor::GetListeningPort(uint32_t timeout_sec) {
765 uint16_t bound_port = 0;
766 if (timeout_sec == UINT32_MAX)
767 m_port_predicate.WaitForValueNotEqualTo(0, bound_port);
769 m_port_predicate.WaitForValueNotEqualTo(0, bound_port,
770 std::chrono::seconds(timeout_sec));
774 bool ConnectionFileDescriptor::GetChildProcessesInherit() const {
775 return m_child_processes_inherit;
778 void ConnectionFileDescriptor::SetChildProcessesInherit(
779 bool child_processes_inherit) {
780 m_child_processes_inherit = child_processes_inherit;
783 void ConnectionFileDescriptor::InitializeSocket(Socket *socket) {
784 assert(socket->GetSocketProtocol() == Socket::ProtocolTcp);
785 TCPSocket *tcp_socket = static_cast<TCPSocket *>(socket);
787 m_write_sp.reset(socket);
788 m_read_sp = m_write_sp;
790 strm.Printf("connect://%s:%u", tcp_socket->GetRemoteIPAddress().c_str(),
791 tcp_socket->GetRemotePortNumber());
792 m_uri = strm.GetString();