mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Don't shuffle monitor client connections on close
This commit is contained in:
parent
ef533e0c55
commit
f78a4d69a2
40
monitor.c
40
monitor.c
@ -87,6 +87,7 @@ struct monitor_context {
|
||||
|
||||
char line[MONITOR_LINE_LENGTH];
|
||||
int line_length;
|
||||
#define MONITOR_STATE_UNUSED 0
|
||||
#define MONITOR_STATE_COMMAND 1
|
||||
#define MONITOR_STATE_DATA 2
|
||||
int state;
|
||||
@ -96,7 +97,7 @@ struct monitor_context {
|
||||
};
|
||||
|
||||
#define MAX_MONITOR_SOCKETS 8
|
||||
int monitor_socket_count=0;
|
||||
unsigned monitor_socket_count=0;
|
||||
struct monitor_context monitor_sockets[MAX_MONITOR_SOCKETS];
|
||||
|
||||
int monitor_process_command(struct monitor_context *c);
|
||||
@ -174,22 +175,13 @@ void monitor_poll(struct sched_ent *alarm)
|
||||
}
|
||||
|
||||
static void monitor_close(struct monitor_context *c){
|
||||
struct monitor_context *last;
|
||||
|
||||
INFO("Tearing down monitor client");
|
||||
INFOF("Tearing down monitor client fd=%d", c->alarm.poll.fd);
|
||||
|
||||
unwatch(&c->alarm);
|
||||
close(c->alarm.poll.fd);
|
||||
c->alarm.poll.fd=-1;
|
||||
|
||||
monitor_socket_count--;
|
||||
last = &monitor_sockets[monitor_socket_count];
|
||||
if (last != c){
|
||||
unwatch(&last->alarm);
|
||||
bcopy(last, c,
|
||||
sizeof(struct monitor_context));
|
||||
watch(&c->alarm);
|
||||
}
|
||||
c->state=MONITOR_STATE_UNUSED;
|
||||
c->flags=0;
|
||||
}
|
||||
|
||||
void monitor_client_poll(struct sched_ent *alarm)
|
||||
@ -312,7 +304,7 @@ static void monitor_new_client(int s) {
|
||||
ucred_t *ucred;
|
||||
#endif
|
||||
uid_t otheruid;
|
||||
struct monitor_context *c;
|
||||
struct monitor_context *c=NULL;
|
||||
|
||||
if (set_nonblock(s) == -1)
|
||||
goto error;
|
||||
@ -355,13 +347,23 @@ static void monitor_new_client(int s) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
if (monitor_socket_count >= MAX_MONITOR_SOCKETS
|
||||
||monitor_socket_count < 0) {
|
||||
write_str(s, "\nCLOSE:All sockets busy\n");
|
||||
goto error;
|
||||
|
||||
unsigned i;
|
||||
for (i=0;i<monitor_socket_count;i++){
|
||||
if (monitor_sockets[i].state == MONITOR_STATE_UNUSED){
|
||||
c = &monitor_sockets[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c = &monitor_sockets[monitor_socket_count++];
|
||||
if (!c){
|
||||
if (monitor_socket_count >= MAX_MONITOR_SOCKETS) {
|
||||
write_str(s, "\nCLOSE:All sockets busy\n");
|
||||
goto error;
|
||||
}
|
||||
|
||||
c = &monitor_sockets[monitor_socket_count++];
|
||||
}
|
||||
c->alarm.function = monitor_client_poll;
|
||||
client_stats.name = "monitor_client_poll";
|
||||
c->alarm.stats=&client_stats;
|
||||
|
1
serval.h
1
serval.h
@ -415,7 +415,6 @@ int monitor_announce_link(int hop_count, struct subscriber *transmitter, struct
|
||||
int monitor_tell_clients(char *msg, int msglen, int mask);
|
||||
int monitor_tell_formatted(int mask, char *fmt, ...);
|
||||
int monitor_client_interested(int mask);
|
||||
extern int monitor_socket_count;
|
||||
|
||||
int scrapeProcNetRoute();
|
||||
int lsif();
|
||||
|
12
vomp.c
12
vomp.c
@ -698,7 +698,7 @@ static int vomp_update(struct vomp_call_state *call)
|
||||
vomp_send_status_remote(call);
|
||||
|
||||
// tell monitor clients
|
||||
if (monitor_socket_count && monitor_client_interested(MONITOR_VOMP))
|
||||
if (monitor_client_interested(MONITOR_VOMP))
|
||||
monitor_call_status(call);
|
||||
|
||||
return 0;
|
||||
@ -749,10 +749,9 @@ static int vomp_process_audio(struct vomp_call_state *call, struct overlay_buffe
|
||||
return 0;
|
||||
|
||||
/* Pass audio frame to all registered listeners */
|
||||
if (monitor_socket_count)
|
||||
monitor_send_audio(call, codec, decoded_time, decoded_sequence,
|
||||
ob_current_ptr(payload),
|
||||
audio_len, delay);
|
||||
monitor_send_audio(call, codec, decoded_time, decoded_sequence,
|
||||
ob_current_ptr(payload),
|
||||
audio_len, delay);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -925,8 +924,7 @@ int vomp_mdp_received(struct internal_mdp_header *header, struct overlay_buffer
|
||||
// Though we could use this information to indicate a network error.
|
||||
recvr_state = call->local.state;
|
||||
|
||||
if ((!monitor_socket_count)
|
||||
&&(!monitor_client_interested(MONITOR_VOMP)))
|
||||
if (!monitor_client_interested(MONITOR_VOMP))
|
||||
{
|
||||
/* No registered listener, so we cannot answer the call, so just reject
|
||||
it. */
|
||||
|
Loading…
Reference in New Issue
Block a user