mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-30 09:58:55 +00:00
make sure monitor sockets are nonblocking before doing anything
to them.
This commit is contained in:
parent
5d6f2b0517
commit
4bbe250595
17
monitor.c
17
monitor.c
@ -205,7 +205,8 @@ int monitor_poll()
|
|||||||
errno=0;
|
errno=0;
|
||||||
int bytes;
|
int bytes;
|
||||||
struct monitor_context *c=&monitor_sockets[monitor_socket_count];
|
struct monitor_context *c=&monitor_sockets[monitor_socket_count];
|
||||||
|
fcntl(c->socket,F_SETFL,
|
||||||
|
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
switch(c->state) {
|
switch(c->state) {
|
||||||
case MONITOR_STATE_COMMAND:
|
case MONITOR_STATE_COMMAND:
|
||||||
bytes=1;
|
bytes=1;
|
||||||
@ -214,6 +215,7 @@ int monitor_poll()
|
|||||||
/* line too long */
|
/* line too long */
|
||||||
c->line[MONITOR_LINE_LENGTH-1]=0;
|
c->line[MONITOR_LINE_LENGTH-1]=0;
|
||||||
monitor_process_command(i,c->line);
|
monitor_process_command(i,c->line);
|
||||||
|
bytes=-1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bytes=read(c->socket,&c->line[c->line_length],1);
|
bytes=read(c->socket,&c->line[c->line_length],1);
|
||||||
@ -293,6 +295,9 @@ int monitor_process_command(int index,char *cmd)
|
|||||||
struct monitor_context *c=&monitor_sockets[index];
|
struct monitor_context *c=&monitor_sockets[index];
|
||||||
c->line_length=0;
|
c->line_length=0;
|
||||||
|
|
||||||
|
fcntl(c->socket,F_SETFL,
|
||||||
|
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
|
|
||||||
if (strlen(cmd)>80) {
|
if (strlen(cmd)>80) {
|
||||||
write(c->socket,"ERROR:Command too long\n",
|
write(c->socket,"ERROR:Command too long\n",
|
||||||
strlen("ERROR:Command too long\n"));
|
strlen("ERROR:Command too long\n"));
|
||||||
@ -335,6 +340,9 @@ int monitor_process_command(int index,char *cmd)
|
|||||||
vomp_mdp_event(&mdp,NULL,0);
|
vomp_mdp_event(&mdp,NULL,0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fcntl(c->socket,F_SETFL,
|
||||||
|
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
|
|
||||||
char msg[1024];
|
char msg[1024];
|
||||||
snprintf(msg,1024,"MONITORSTATUS:%d\n",c->flags);
|
snprintf(msg,1024,"MONITORSTATUS:%d\n",c->flags);
|
||||||
write(c->socket,msg,strlen(msg));
|
write(c->socket,msg,strlen(msg));
|
||||||
@ -351,6 +359,9 @@ int monitor_process_data(int index)
|
|||||||
if (vomp_sample_size(c->sample_codec)!=c->data_offset)
|
if (vomp_sample_size(c->sample_codec)!=c->data_offset)
|
||||||
return WHY("Ignoring sample block of incorrect size");
|
return WHY("Ignoring sample block of incorrect size");
|
||||||
|
|
||||||
|
fcntl(c->socket,F_SETFL,
|
||||||
|
fcntl(c->socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
|
|
||||||
vomp_call_state *call=vomp_find_call_by_session(c->sample_call_session_token);
|
vomp_call_state *call=vomp_find_call_by_session(c->sample_call_session_token);
|
||||||
if (!call) {
|
if (!call) {
|
||||||
write(c->socket,"ERROR:No such call\n",strlen("ERROR:No such call\n"));
|
write(c->socket,"ERROR:No such call\n",strlen("ERROR:No such call\n"));
|
||||||
@ -385,6 +396,8 @@ int monitor_call_status(vomp_call_state *call)
|
|||||||
continue;
|
continue;
|
||||||
nextInSameSlot:
|
nextInSameSlot:
|
||||||
errno=0;
|
errno=0;
|
||||||
|
fcntl(monitor_sockets[i].socket,F_SETFL,
|
||||||
|
fcntl(monitor_sockets[i].socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
write(monitor_sockets[i].socket,msg,strlen(msg));
|
write(monitor_sockets[i].socket,msg,strlen(msg));
|
||||||
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
|
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
|
||||||
/* error sending update, so kill monitor socket */
|
/* error sending update, so kill monitor socket */
|
||||||
@ -431,6 +444,8 @@ int monitor_send_audio(vomp_call_state *call,overlay_mdp_frame *audio)
|
|||||||
continue;
|
continue;
|
||||||
nextInSameSlot:
|
nextInSameSlot:
|
||||||
errno=0;
|
errno=0;
|
||||||
|
fcntl(monitor_sockets[i].socket,F_SETFL,
|
||||||
|
fcntl(monitor_sockets[i].socket, F_GETFL, NULL)|O_NONBLOCK);
|
||||||
write(monitor_sockets[i].socket,msg,msglen);
|
write(monitor_sockets[i].socket,msg,msglen);
|
||||||
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
|
if (errno&&(errno!=EINTR)&&(errno!=EAGAIN)) {
|
||||||
/* error sending update, so kill monitor socket */
|
/* error sending update, so kill monitor socket */
|
||||||
|
Loading…
Reference in New Issue
Block a user