diff --git a/ecal/core/src/io/ecal_memfile.cpp b/ecal/core/src/io/ecal_memfile.cpp index 5d1b84dfdf..6c671845b5 100644 --- a/ecal/core/src/io/ecal_memfile.cpp +++ b/ecal/core/src/io/ecal_memfile.cpp @@ -87,7 +87,7 @@ namespace eCAL if (!memfile::db::AddFile(name_, create_, create_ ? len_ + m_header.int_hdr_size : SIZEOF_PARTIAL_STRUCT(SInternalHeader, int_hdr_size), m_memfile_info)) { #ifndef NDEBUG - printf("Could not create memory file: %s.\n\n", name_); + printf("Could not create memory file: %s.\n", name_); #endif return(false); } @@ -98,7 +98,7 @@ namespace eCAL if(!m_memfile_mutex.Create(name_, m_auto_sanitizing)) { #ifndef NDEBUG - printf("Could not create memory file mutex: %s.\n\n", name_); + printf("Could not create memory file mutex: %s.\n", name_); #endif return(false); } diff --git a/ecal/core/src/io/ecal_memfile_sync.cpp b/ecal/core/src/io/ecal_memfile_sync.cpp index ee22d8a363..ce071df73d 100644 --- a/ecal/core/src/io/ecal_memfile_sync.cpp +++ b/ecal/core/src/io/ecal_memfile_sync.cpp @@ -251,12 +251,12 @@ namespace eCAL // create the memory file if (!m_memfile.Create(m_memfile_name.c_str(), true, memfile_size)) { - Logging::Log(log_level_error, std::string(m_base_name + "::CSyncMemoryFile::Create - FAILED : ") + m_memfile_name); + Logging::Log(log_level_error, std::string("CSyncMemoryFile::Create FAILED : ") + m_memfile_name); return false; } #ifndef NDEBUG - Logging::Log(log_level_debug2, std::string(m_base_name + "::CSyncMemoryFile::Create - SUCCESS : ") + m_memfile_name); + Logging::Log(log_level_debug2, std::string("CSyncMemoryFile::Create SUCCESS : ") + m_memfile_name); #endif // initialize memory file with empty header diff --git a/ecal/core/src/io/ecal_memfile_sync.h b/ecal/core/src/io/ecal_memfile_sync.h index daefd5add5..a6756116d0 100644 --- a/ecal/core/src/io/ecal_memfile_sync.h +++ b/ecal/core/src/io/ecal_memfile_sync.h @@ -57,6 +57,7 @@ namespace eCAL std::string GetName() const; size_t GetSize() const; + bool IsCreated() const { return m_created; }; protected: bool Create(const std::string& base_name_, size_t size_); diff --git a/ecal/core/src/io/linux/ecal_memfile_os.cpp b/ecal/core/src/io/linux/ecal_memfile_os.cpp index 8857bce875..5d2fb89132 100644 --- a/ecal/core/src/io/linux/ecal_memfile_os.cpp +++ b/ecal/core/src/io/linux/ecal_memfile_os.cpp @@ -60,7 +60,14 @@ namespace eCAL umask(previous_umask); // reset umask to previous permissions if (mem_file_info_.memfile == -1) { - std::cout << "shm_open failed : " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; + if(create_) + { + std::cerr << "shm_open failed to CREATE memory file (memfile::os::AllocFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; + } + else + { + std::cerr << "shm_open failed to OPEN memory file (memfile::os::AllocFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; + } mem_file_info_.memfile = 0; mem_file_info_.name = ""; mem_file_info_.exists = false; @@ -101,7 +108,7 @@ namespace eCAL // truncate file if (::ftruncate(mem_file_info_.memfile, mem_file_info_.size) != 0) { - std::cout << "ftruncate failed : " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; + std::cerr << "ftruncate failed (memfile::os::MapFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; } } @@ -113,7 +120,7 @@ namespace eCAL if (mem_file_info_.mem_address == MAP_FAILED) { mem_file_info_.mem_address = nullptr; - std::cout << "mmap failed : " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; + std::cerr << "mmap failed (memfile::os::MapFile): " << mem_file_info_.name << " errno: " << strerror(errno) << std::endl; return(false); } } diff --git a/ecal/core/src/readwrite/ecal_writer.cpp b/ecal/core/src/readwrite/ecal_writer.cpp index 5a18c3d08d..aa289ffcdb 100644 --- a/ecal/core/src/readwrite/ecal_writer.cpp +++ b/ecal/core/src/readwrite/ecal_writer.cpp @@ -1057,10 +1057,16 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - m_writer.udp_mc.Create(m_host_name, m_topic_name, m_topic_id); + if (m_writer.udp_mc.Create(m_host_name, m_topic_name, m_topic_id)) + { #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER - SUCCESS"); #endif + } + else + { + Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::UDP_MC_WRITER - FAILED"); + } break; case TLayer::eSendMode::smode_none: case TLayer::eSendMode::smode_off: @@ -1081,10 +1087,16 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - m_writer.shm.Create(m_host_name, m_topic_name, m_topic_id); + if (m_writer.shm.Create(m_host_name, m_topic_name, m_topic_id)) + { #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::SHM_WRITER"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::SHM_WRITER - SUCCESS"); #endif + } + else + { + Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::SHM_WRITER - FAILED"); + } break; case TLayer::eSendMode::smode_none: case TLayer::eSendMode::smode_off: @@ -1105,10 +1117,16 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - m_writer.tcp.Create(m_host_name, m_topic_name, m_topic_id); + if (m_writer.tcp.Create(m_host_name, m_topic_name, m_topic_id)) + { #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::TCP_WRITER"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::TCP_WRITER - SUCCESS"); #endif + } + else + { + Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::TCP_WRITER - FAILED"); + } break; case TLayer::eSendMode::smode_none: case TLayer::eSendMode::smode_off: @@ -1129,10 +1147,16 @@ namespace eCAL { case TLayer::eSendMode::smode_auto: case TLayer::eSendMode::smode_on: - m_writer.inproc.Create(m_host_name, m_topic_name, m_topic_id); + if (m_writer.inproc.Create(m_host_name, m_topic_name, m_topic_id)) + { #ifndef NDEBUG - Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::INPROC_WRITER"); + Logging::Log(log_level_debug4, m_topic_name + "::CDataWriter::Create::INPROC_WRITER - SUCCESS"); #endif + } + else + { + Logging::Log(log_level_error, m_topic_name + "::CDataWriter::Create::INPROC_WRITER - FAILED"); + } break; default: m_writer.inproc.Destroy(); diff --git a/ecal/core/src/readwrite/ecal_writer_shm.cpp b/ecal/core/src/readwrite/ecal_writer_shm.cpp index 5dbee9cd44..fd11fd548d 100644 --- a/ecal/core/src/readwrite/ecal_writer_shm.cpp +++ b/ecal/core/src/readwrite/ecal_writer_shm.cpp @@ -79,9 +79,7 @@ namespace eCAL m_memory_file_attr.timeout_ack_ms = Config::GetMemfileAckTimeoutMs(); // initialize memory file buffer - SetBufferCount(m_buffer_count); - - m_created = true; + m_created = SetBufferCount(m_buffer_count);; return m_created; } @@ -124,12 +122,21 @@ namespace eCAL memory_file_size = m_memory_file_attr.min_size; } - // recreate memory file vector + // create memory file vector m_memory_file_vec.clear(); while (m_memory_file_vec.size() < buffer_count_) { auto sync_memfile = std::make_shared(m_memfile_base_name, memory_file_size, m_memory_file_attr); - m_memory_file_vec.push_back(sync_memfile); + if (sync_memfile->IsCreated()) + { + m_memory_file_vec.push_back(sync_memfile); + } + else + { + m_memory_file_vec.clear(); + Logging::Log(log_level_error, "CDataWriterSHM::SetBufferCount - FAILED"); + return false; + } } return true;