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"
16 #include "lldb/Host/windows/windows.h"
21 #include <sys/types.h>
25 // Other libraries and framework includes
27 #include "llvm/Support/MathExtras.h"
28 #include "lldb/lldb-private-log.h"
29 #include "lldb/Core/Communication.h"
30 #include "lldb/Core/Log.h"
33 using namespace lldb_private;
35 ConnectionSharedMemory::ConnectionSharedMemory () :
43 ConnectionSharedMemory::~ConnectionSharedMemory ()
49 ConnectionSharedMemory::IsConnected () const
55 ConnectionSharedMemory::Connect (const char *s, Error *error_ptr)
59 // if (strstr(s, "shm-create://"))
62 // else if (strstr(s, "shm-connect://"))
66 // error_ptr->SetErrorStringWithFormat ("unsupported connection URL: '%s'", s);
67 // return eConnectionStatusError;
70 error_ptr->SetErrorString("invalid connect arguments");
71 return eConnectionStatusError;
75 ConnectionSharedMemory::Disconnect (Error *error_ptr)
84 shm_unlink (m_name.c_str());
88 return eConnectionStatusSuccess;
92 ConnectionSharedMemory::Read (void *dst,
94 uint32_t timeout_usec,
95 ConnectionStatus &status,
98 status = eConnectionStatusSuccess;
103 ConnectionSharedMemory::Write (const void *src, size_t src_len, ConnectionStatus &status, Error *error_ptr)
105 status = eConnectionStatusSuccess;
110 ConnectionSharedMemory::BytesAvailable (uint32_t timeout_usec, Error *error_ptr)
112 return eConnectionStatusLostConnection;
116 ConnectionSharedMemory::Open (bool create, const char *name, size_t size, Error *error_ptr)
121 error_ptr->SetErrorString("already open");
122 return eConnectionStatusError;
125 m_name.assign (name);
130 handle = CreateFileMapping(
131 INVALID_HANDLE_VALUE,
139 handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name);
141 m_fd = _open_osfhandle((intptr_t)handle, 0);
146 m_fd = ::shm_open (m_name.c_str(), oflag, S_IRUSR|S_IWUSR);
149 ::ftruncate (m_fd, size);
152 if (m_mmap.MemoryMapFromFileDescriptor(m_fd, 0, size, true, false) == size)
153 return eConnectionStatusSuccess;
156 return eConnectionStatusError;