mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-19 21:27:57 +00:00
Don't continuously toggle fd blocking mode
This commit is contained in:
parent
256fdb11c9
commit
c04d015bc6
@ -62,7 +62,6 @@ static void process_command(char *line, struct cli_schema *cli_commands){
|
|||||||
|
|
||||||
static void read_lines(struct sched_ent *alarm){
|
static void read_lines(struct sched_ent *alarm){
|
||||||
struct command_state *state=(struct command_state *)alarm;
|
struct command_state *state=(struct command_state *)alarm;
|
||||||
set_nonblock(alarm->poll.fd);
|
|
||||||
ssize_t bytes = read(alarm->poll.fd, state->line_buff + state->line_pos, sizeof(state->line_buff) - state->line_pos);
|
ssize_t bytes = read(alarm->poll.fd, state->line_buff + state->line_pos, sizeof(state->line_buff) - state->line_pos);
|
||||||
if (bytes<=0){
|
if (bytes<=0){
|
||||||
// EOF?
|
// EOF?
|
||||||
@ -70,7 +69,6 @@ static void read_lines(struct sched_ent *alarm){
|
|||||||
alarm->poll.fd=-1;
|
alarm->poll.fd=-1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
set_block(alarm->poll.fd);
|
|
||||||
size_t i = state->line_pos;
|
size_t i = state->line_pos;
|
||||||
size_t processed=0;
|
size_t processed=0;
|
||||||
state->line_pos+=bytes;
|
state->line_pos+=bytes;
|
||||||
|
@ -252,6 +252,7 @@ int _watch(struct __sourceloc __whence, struct sched_ent *alarm)
|
|||||||
DEBUGF(io, "Adding watch %s, #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
|
DEBUGF(io, "Adding watch %s, #%d for %s", alloca_alarm_name(alarm), alarm->poll.fd, alloca_poll_events(alarm->poll.events));
|
||||||
if (fdcount>=MAX_WATCHED_FDS)
|
if (fdcount>=MAX_WATCHED_FDS)
|
||||||
return WHY("Too many file handles to watch");
|
return WHY("Too many file handles to watch");
|
||||||
|
set_nonblock(alarm->poll.fd);
|
||||||
fd_callbacks[fdcount]=alarm;
|
fd_callbacks[fdcount]=alarm;
|
||||||
alarm->poll.revents = 0;
|
alarm->poll.revents = 0;
|
||||||
alarm->_poll_index=fdcount;
|
alarm->_poll_index=fdcount;
|
||||||
@ -425,18 +426,11 @@ int fd_poll2(time_ms_t (*waiting)(time_ms_t, time_ms_t, time_ms_t), void (*wokeu
|
|||||||
for(i=fdcount -1;i>=0;i--){
|
for(i=fdcount -1;i>=0;i--){
|
||||||
if (fd_callbacks[i] && fd_callbacks[i]->poll.fd == fds[i].fd && fds[i].revents) {
|
if (fd_callbacks[i] && fd_callbacks[i]->poll.fd == fds[i].fd && fds[i].revents) {
|
||||||
errno=0;
|
errno=0;
|
||||||
int fd = fds[i].fd;
|
|
||||||
set_nonblock(fd);
|
|
||||||
// Work around OSX behaviour that doesn't set POLLERR on
|
// Work around OSX behaviour that doesn't set POLLERR on
|
||||||
// devices that have been deconfigured, e.g., a USB serial adapter
|
// devices that have been deconfigured, e.g., a USB serial adapter
|
||||||
// that has been removed.
|
// that has been removed.
|
||||||
if (errno == ENXIO) fds[i].revents|=POLLERR;
|
if (errno == ENXIO) fds[i].revents|=POLLERR;
|
||||||
call_alarm(fd_callbacks[i], fds[i].revents);
|
call_alarm(fd_callbacks[i], fds[i].revents);
|
||||||
// The alarm may have closed and unwatched the descriptor, make sure this descriptor still matches
|
|
||||||
if (i<fdcount && fds[i].fd == fd){
|
|
||||||
if (set_block(fds[i].fd))
|
|
||||||
FATALF("Alarm %p %s has a bad descriptor that wasn't closed!", fd_callbacks[i], alloca_alarm_name(fd_callbacks[i]));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// time may have passed while processing IO, or processing IO could trigger a new overdue alarm
|
// time may have passed while processing IO, or processing IO could trigger a new overdue alarm
|
||||||
|
1
httpd.c
1
httpd.c
@ -243,6 +243,7 @@ void httpd_server_poll(struct sched_ent *alarm)
|
|||||||
if (errno && errno != EAGAIN)
|
if (errno && errno != EAGAIN)
|
||||||
WARN_perror("accept");
|
WARN_perror("accept");
|
||||||
} else {
|
} else {
|
||||||
|
set_nonblock(sock);
|
||||||
++http_request_uuid_counter;
|
++http_request_uuid_counter;
|
||||||
strbuf_sprintf(&log_context, "httpd/%u", http_request_uuid_counter);
|
strbuf_sprintf(&log_context, "httpd/%u", http_request_uuid_counter);
|
||||||
struct sockaddr_in *peerip=NULL;
|
struct sockaddr_in *peerip=NULL;
|
||||||
|
@ -216,9 +216,7 @@ int overlay_mdp_send(int mdp_sockfd, overlay_mdp_frame *mdp, int flags, int time
|
|||||||
if (make_local_sockaddr(&addr, "mdp.socket") == -1)
|
if (make_local_sockaddr(&addr, "mdp.socket") == -1)
|
||||||
return WHY("Failed to make socket address");
|
return WHY("Failed to make socket address");
|
||||||
// Send to that socket
|
// Send to that socket
|
||||||
set_nonblock(mdp_sockfd);
|
|
||||||
ssize_t result = sendto(mdp_sockfd, mdp, (size_t)len, 0, &addr.addr, addr.addrlen);
|
ssize_t result = sendto(mdp_sockfd, mdp, (size_t)len, 0, &addr.addr, addr.addrlen);
|
||||||
set_block(mdp_sockfd);
|
|
||||||
if ((size_t)result != (size_t)len) {
|
if ((size_t)result != (size_t)len) {
|
||||||
if (result == -1)
|
if (result == -1)
|
||||||
WHYF_perror("sendto(fd=%d,len=%zu,addr=%s)", mdp_sockfd, (size_t)len, alloca_socket_address(&addr));
|
WHYF_perror("sendto(fd=%d,len=%zu,addr=%s)", mdp_sockfd, (size_t)len, alloca_socket_address(&addr));
|
||||||
@ -322,10 +320,8 @@ int overlay_mdp_recv(int mdp_sockfd, overlay_mdp_frame *mdp, mdp_port_t port, in
|
|||||||
recvaddr.addrlen = sizeof recvaddr.store;
|
recvaddr.addrlen = sizeof recvaddr.store;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
mdp->packetTypeAndFlags = 0;
|
mdp->packetTypeAndFlags = 0;
|
||||||
set_nonblock(mdp_sockfd);
|
|
||||||
|
|
||||||
len = recv_message(mdp_sockfd, &recvaddr, ttl, (unsigned char *)mdp, sizeof(overlay_mdp_frame));
|
len = recv_message(mdp_sockfd, &recvaddr, ttl, (unsigned char *)mdp, sizeof(overlay_mdp_frame));
|
||||||
set_block(mdp_sockfd);
|
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return -1; // no packet received
|
return -1; // no packet received
|
||||||
|
|
||||||
|
@ -662,10 +662,7 @@ int monitor_tell_clients(char *msg, int msglen, int mask)
|
|||||||
for(i=monitor_socket_count -1;i>=0;i--) {
|
for(i=monitor_socket_count -1;i>=0;i--) {
|
||||||
if (monitor_sockets[i].flags & mask) {
|
if (monitor_sockets[i].flags & mask) {
|
||||||
// DEBUG("Writing AUDIOPACKET to client");
|
// DEBUG("Writing AUDIOPACKET to client");
|
||||||
if ( set_nonblock(monitor_sockets[i].alarm.poll.fd) == -1
|
if ( write_all_nonblock(monitor_sockets[i].alarm.poll.fd, msg, msglen) == -1) {
|
||||||
|| write_all_nonblock(monitor_sockets[i].alarm.poll.fd, msg, msglen) == -1
|
|
||||||
|| set_block(monitor_sockets[i].alarm.poll.fd) == -1
|
|
||||||
) {
|
|
||||||
INFOF("Tearing down monitor client #%d", i);
|
INFOF("Tearing down monitor client #%d", i);
|
||||||
monitor_close(&monitor_sockets[i]);
|
monitor_close(&monitor_sockets[i]);
|
||||||
}
|
}
|
||||||
|
@ -215,6 +215,8 @@ overlay_bind_socket(const struct socket_address *addr){
|
|||||||
|
|
||||||
if (socket_bind(fd, addr))
|
if (socket_bind(fd, addr))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
|
set_nonblock(fd);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
|
|
||||||
@ -1070,7 +1072,6 @@ int overlay_broadcast_ensemble(struct network_destination *destination, struct o
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
set_block(interface->alarm.poll.fd);
|
|
||||||
ob_free(buffer);
|
ob_free(buffer);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -396,6 +396,7 @@ static int app_vomp_console(const struct cli_parsed *parsed, struct cli_context
|
|||||||
monitor_client_writeline(monitor_alarm.poll.fd, "monitor vomp %d\n",
|
monitor_client_writeline(monitor_alarm.poll.fd, "monitor vomp %d\n",
|
||||||
VOMP_CODEC_TEXT);
|
VOMP_CODEC_TEXT);
|
||||||
|
|
||||||
|
set_nonblock(STDIN_FILENO);
|
||||||
set_nonblock(monitor_alarm.poll.fd);
|
set_nonblock(monitor_alarm.poll.fd);
|
||||||
|
|
||||||
watch(&monitor_alarm);
|
watch(&monitor_alarm);
|
||||||
|
Loading…
Reference in New Issue
Block a user