connectToFile edit that allows for custom socket passing

Change-Id: Id5da9d9c50d1997f997c9e738d8f680098901509
This commit is contained in:
Thulinma 2022-12-26 13:33:06 +01:00
parent 9c0b0e28d8
commit 877216efd0
2 changed files with 12 additions and 3 deletions

View file

@ -1876,7 +1876,8 @@ namespace Mist{
sentHeader = true;
}
bool Output::connectToFile(std::string file, bool append){
bool Output::connectToFile(std::string file, bool append, Socket::Connection *conn){
if (!conn){conn = &myConn;}
int flags = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
int mode = O_RDWR | O_CREAT | (append ? O_APPEND : O_TRUNC);
if (!Util::createPathFor(file)){
@ -1889,7 +1890,15 @@ namespace Mist{
return false;
}
int r = dup2(outFile, myConn.getSocket());
//Ensure the Socket::Connection is valid before we overwrite the socket
if (!*conn){
static int tmpFd = open("/dev/null", O_RDWR);
conn->open(tmpFd);
//We always want to close sockets opened in this way on fork
Util::Procs::socketList.insert(tmpFd);
}
int r = dup2(outFile, conn->getSocket());
if (r == -1){
ERROR_MSG("Failed to create an alias for the socket using dup2: %s.", strerror(errno));
return false;

View file

@ -45,7 +45,7 @@ namespace Mist{
uint64_t endTime();
void setBlocking(bool blocking);
bool selectDefaultTracks();
bool connectToFile(std::string file, bool append = false);
bool connectToFile(std::string file, bool append = false, Socket::Connection *conn = 0);
static bool listenMode(){return true;}
uint32_t currTrackCount() const;
virtual bool isReadyForPlay();