Skip to content

Commit

Permalink
Merge pull request #80 from hbeni/master-noUDPMumAPImsgs
Browse files Browse the repository at this point in the history
Fix #78: deadlock on udp-server shutdown
  • Loading branch information
hbeni authored Feb 17, 2021
2 parents b28a40e + 1f150f5 commit 98831ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion client/mumble-plugin/fgcom-mumble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ void fgcom_setPluginActive(bool active) {

// restore old transmission mode
merr = mumAPI.requestLocalUserTransmissionMode(ownPluginID, fgcom_prevTransmissionMode);

// disable PTT overwrite
merr = mumAPI.requestMicrophoneActivationOvewrite(ownPluginID, false);
}

fgcom_inSpecialChannel = active;
Expand Down Expand Up @@ -190,7 +193,6 @@ void fgcom_handlePTT() {
// plugin deactivation will already handle setting the old transmission mode,
// so the mic will be open according to that...
pluginDbg("Handling PTT state: PLUGIN NOT ACTIVE");
mumAPI.requestMicrophoneActivationOvewrite(ownPluginID, false);
}
}

Expand Down
21 changes: 11 additions & 10 deletions client/mumble-plugin/lib/io_UDPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ bool fgcom_udp_shutdowncmd = false;
bool udpServerRunning = false;
void fgcom_spawnUDPServer() {
pluginLog("[UDP-server] server starting");
int fgcom_UDPServer_sockfd;
char buffer[MAXLINE];
int fgcom_UDPServer_sockfd;
char buffer[MAXLINE];
struct sockaddr_in servaddr, cliaddr;

#ifdef MINGW_WIN64
Expand Down Expand Up @@ -616,24 +616,25 @@ void fgcom_spawnUDPServer() {
clientHost = inet_ntoa(cliaddr.sin_addr);
std::string clientHost_str = std::string(clientHost);

// Print info to client, so we know what ports are in use
if (firstdata.count(clientPort) == 0 && sizeof(buffer) > 4) {
firstdata[clientPort] = true;
pluginLog("[UDP-server] server connection established from "+clientHost_str+":"+std::to_string(clientPort));
mumAPI.log(ownPluginID, std::string("UDP server connection established from "+clientHost_str+":"+std::to_string(clientPort)).c_str());
}

// Allow the udp server to be shut down when receiving SHUTDOWN command
if (strstr(buffer, "SHUTDOWN") && fgcom_udp_shutdowncmd) {
pluginLog("[UDP-server] shutdown command recieved, server stopping now");
fgcom_udp_shutdowncmd = false;
close(fgcom_UDPServer_sockfd);
mumAPI.log(ownPluginID, std::string("UDP server at port "+std::to_string(fgcom_udp_port_used)+" stopped").c_str());
//mumAPI.log(ownPluginID, std::string("UDP server at port "+std::to_string(fgcom_udp_port_used)+" stopped").c_str());
// ^^ note: as long as the mumAPI is synchronuous/blocking, we cannot emit that message: it causes mumble's main thread to block/deadlock.
break;

} else {
// let the incoming data be handled

// Print info to client, so we know what ports are in use
if (firstdata.count(clientPort) == 0 && sizeof(buffer) > 4) {
firstdata[clientPort] = true;
pluginLog("[UDP-server] server connection established from "+clientHost_str+":"+std::to_string(clientPort));
mumAPI.log(ownPluginID, std::string("UDP server connection established from "+clientHost_str+":"+std::to_string(clientPort)).c_str());
}

std::map<int, fgcom_udp_parseMsg_result> updates; // so we can send updates to remotes
updates = fgcom_udp_parseMsg(buffer, clientPort, clientHost_str);

Expand Down

0 comments on commit 98831ec

Please sign in to comment.