1 //===-- ConnectionSharedMemory.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 #include "lldb/Core/ConnectionSharedMemory.h"
19 #include <sys/types.h>
22 // Other libraries and framework includes
24 #include "lldb/lldb-private-log.h"
25 #include "lldb/Core/Communication.h"
26 #include "lldb/Core/Log.h"
29 using namespace lldb_private;
31 ConnectionSharedMemory::ConnectionSharedMemory () :
39 ConnectionSharedMemory::~ConnectionSharedMemory ()
45 ConnectionSharedMemory::IsConnected () const
51 ConnectionSharedMemory::Connect (const char *s, Error *error_ptr)
55 // if (strstr(s, "shm-create://"))
58 // else if (strstr(s, "shm-connect://"))
62 // error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
63 // return eConnectionStatusError;
66 error_ptr->SetErrorString("invalid connect arguments");
67 return eConnectionStatusError;
71 ConnectionSharedMemory::Disconnect (Error *error_ptr)
76 shm_unlink (m_name.c_str());
79 return eConnectionStatusSuccess;
83 ConnectionSharedMemory::Read (void *dst,
85 uint32_t timeout_usec,
86 ConnectionStatus &status,
89 status = eConnectionStatusSuccess;
94 ConnectionSharedMemory::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
96 status = eConnectionStatusSuccess;
101 ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
103 return eConnectionStatusLostConnection;
107 ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error *error_ptr)
112 error_ptr->SetErrorString("already open");
113 return eConnectionStatusError;
116 m_name.assign (name);
120 m_fd = ::shm_open (m_name.c_str(), oflag, S_IRUSR|S_IWUSR);
123 ::ftruncate (m_fd, size);
125 if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
126 return eConnectionStatusSuccess;
129 return eConnectionStatusError;