Using system wide temp directory for shared memory socket 9for linux

snaps to be able to share).
This commit is contained in:
brunoherbelin
2020-11-07 18:54:33 +01:00
parent fcc014e5d1
commit 1c1a0e9b33
4 changed files with 20 additions and 3 deletions

View File

@@ -223,7 +223,7 @@ void NetworkStream::update()
// make sure the shared memory socket exists
if (config_.protocol == NetworkToolkit::SHM_RAW) {
// for shared memory, the parameter is a file location in settings
parameter = SystemToolkit::full_filename(SystemToolkit::settings_path(), "shm") + parameter;
parameter = SystemToolkit::full_filename(SystemToolkit::temp_path(), "shm") + parameter;
// try few times to see if file exists and wait 20ms each time
for(int trial = 0; trial < 5; trial ++){
if ( SystemToolkit::file_exists(parameter))
@@ -232,7 +232,7 @@ void NetworkStream::update()
}
// failed to find the shm socket file: cannot connect
if (!SystemToolkit::file_exists(parameter)) {
Log::Warning("Cannot connect to shared memory.");
Log::Warning("Cannot connect to shared memory %s.", parameter.c_str());
failed_ = true;
}
parameter = "\"" + parameter + "\"";

View File

@@ -358,7 +358,7 @@ void VideoStreamer::addFrame (FrameBuffer *frame_buffer, float dt)
}
else if (config_.protocol == NetworkToolkit::SHM_RAW) {
// TODO rename SHM socket "shm_PORT"
std::string path = SystemToolkit::full_filename(SystemToolkit::settings_path(), "shm");
std::string path = SystemToolkit::full_filename(SystemToolkit::temp_path(), "shm");
path += std::to_string(config_.port);
g_object_set (G_OBJECT (gst_bin_get_by_name (GST_BIN (pipeline_), "sink")),
"socket-path", path.c_str(), NULL);

View File

@@ -254,6 +254,20 @@ string SystemToolkit::settings_path()
}
}
string SystemToolkit::temp_path()
{
string temp;
const char *tmpdir = getenv("TMPDIR");
if (tmpdir)
temp = std::string(tmpdir);
else
temp = std::string( P_tmpdir );
temp += PATH_SEP;
return temp;
}
string SystemToolkit::full_filename(const std::string& path, const string &filename)
{
string fullfilename = path;

View File

@@ -27,6 +27,9 @@ namespace SystemToolkit
// get the OS dependent path where to store settings
std::string settings_path();
// get the OS dependent path where to store temporary files
std::string temp_path();
// builds the OS dependent complete file name
std::string full_filename(const std::string& path, const std::string& filename);