# See below for the flags for the test client program
-shairport_sync_SOURCES = utilities/debug.c shairport.c bonjour_strings.c rtsp.c mdns.c common.c rtp.c player.c audio.c loudness.c activity_monitor.c
+shairport_sync_SOURCES = shairport.c bonjour_strings.c rtsp.c mdns.c common.c rtp.c player.c audio.c loudness.c activity_monitor.c utilities/debug.c utilities/network_utilities.c
if BUILD_FOR_DARWIN
AM_CXXFLAGS = -I/usr/local/include -Wno-multichar -Wall -Wextra -Wno-deprecated-declarations -pthread -DSYSCONFDIR=\"$(sysconfdir)\"
#include "ptp-utilities.h"
#include "rtsp.h"
#include "utilities/structured_buffer.h"
+#include "utilities/network_utilities.h"
void ap2_event_receiver_cleanup_handler(void *arg) {
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
memset(&remote_addr, 0, sizeof(remote_addr));
socklen_t addr_size = sizeof(remote_addr);
- int fd = accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
+ int fd = eintr_checked_accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
debug(2,
"Connection %d: ap2_event_receiver accepted a connection on socket %d and moved to a new "
"socket %d.",
}
} while (finished == 0);
+
debug(3, "Connection %d: AP2 Event Receiver RTP thread starting \"normal\" exit.",
conn->connection_number);
pthread_cleanup_pop(1); // close the socket
+
pthread_cleanup_pop(1); // do the cleanup
pthread_cleanup_pop(1); // delete the structured buffer
debug(2, "Connection %d: AP2 Event Receiver RTP thread \"normal\" exit.",
#include "player.h"
#include "rtsp.h"
#include "utilities/structured_buffer.h"
+#include "utilities/network_utilities.h"
void ap2_rc_event_receiver_cleanup_handler(void *arg) {
rtsp_conn_info *conn = (rtsp_conn_info *)arg;
memset(&remote_addr, 0, sizeof(remote_addr));
socklen_t addr_size = sizeof(remote_addr);
- int fd = accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
+ int fd = eintr_checked_accept(conn->event_socket, (struct sockaddr *)&remote_addr, &addr_size);
debug(2,
"Connection %d: ap2_rc_event_receiver accepted a connection on socket %d and moved to a "
"new "
#endif
#include "mdns.h"
+#include "utilities/network_utilities.h"
#define METADATA_SNDBUF (4 * 1024 * 1024)
// important -- demote the principal conn before cancelling it
if (principal_conn->fd > 0) {
debug(2,
- "Connection %d: %s has acquired play_lock and is forcing termination of Connection "
+ "Connection %d: %s is acquiring play_lock and is forcing termination of Connection "
"%d %s. Closing "
"RTSP connection socket %d: "
"from %s:%u to self at "
#endif
response = play_lock_acquired_by_breaking_in;
}
- usleep(1000000); // don't know why this delay is needed.
+ // usleep(1000000); // don't know why this delay is needed.
}
if ((principal_conn != NULL) && (response != play_lock_already_acquired))
debug(1, "Connection %d: %s has principal_conn.", conn->connection_number,
#endif
socklen_t size_of_reply = sizeof(SOCKADDR);
- conn->fd = accept(acceptfd, (struct sockaddr *)&conn->remote, &size_of_reply);
+ conn->fd = eintr_checked_accept(acceptfd, (struct sockaddr *)&conn->remote, &size_of_reply);
if (conn->fd < 0) {
debug(1, "Connection %d: New connection on port %d not accepted:", conn->connection_number,
config.port);
--- /dev/null
+/*
+ * Network Utilities. This file is part of Shairport Sync.
+ * Copyright (c) Mike Brady 2014--2025
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include "network_utilities.h"
+
+int eintr_checked_accept(int sockfd, struct sockaddr *addr,
+ socklen_t *addrlen) {
+ int response;
+ do {
+ response = accept(sockfd, addr, addrlen);
+
+ if (response == -1) {
+ char errorstring[1024];
+ strerror_r(errno, (char *)errorstring, sizeof(errorstring));
+ debug(1,
+ "error %d accept()ing a socketin ap2_event_receiver %d: \"%s\". Error %d is ignored.",
+ errno, errorstring, EINTR);
+ }
+
+ } while((response == -1) && (errno == EINTR));
+ return response;
+}
\ No newline at end of file
--- /dev/null
+#ifndef _NETWORK_UTILITIES_H
+#define _NETWORK_UTILITIES_H
+
+#include <sys/socket.h>
+
+#define restrict
+
+int eintr_checked_accept(int sockfd, struct sockaddr *addr,
+ socklen_t *addrlen);
+#endif // _NETWORK_UTILITIES_H