aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2020-04-20 20:38:58 +0200
committercbdev <cb@cbcdn.com>2020-04-20 20:38:58 +0200
commit8773fca1f7d2ffed68b6af4967b537d989a1e5b5 (patch)
tree079cce18262307c244bddd554be2467822a01f64 /backends
parentf053dc36fd515e8d7952e1bdefdc0050226a27c4 (diff)
downloadmidimonster-8773fca1f7d2ffed68b6af4967b537d989a1e5b5.tar.gz
midimonster-8773fca1f7d2ffed68b6af4967b537d989a1e5b5.tar.bz2
midimonster-8773fca1f7d2ffed68b6af4967b537d989a1e5b5.zip
Print platform-specific error messages for socket calls
Diffstat (limited to 'backends')
-rw-r--r--backends/artnet.c15
-rw-r--r--backends/maweb.c2
-rw-r--r--backends/openpixelcontrol.c2
-rw-r--r--backends/osc.c4
-rw-r--r--backends/rtpmidi.c15
-rw-r--r--backends/rtpmidi.md4
-rw-r--r--backends/sacn.c35
7 files changed, 37 insertions, 40 deletions
diff --git a/backends/artnet.c b/backends/artnet.c
index 585895b..76962b4 100644
--- a/backends/artnet.c
+++ b/backends/artnet.c
@@ -224,17 +224,12 @@ static int artnet_transmit(instance* inst, artnet_output_universe* output){
memcpy(frame.data, data->data.out, 512);
if(sendto(artnet_fd[data->fd_index].fd, (uint8_t*) &frame, sizeof(frame), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
- #ifndef _WIN32
- if(errno != EAGAIN){
- LOGPF("Failed to output frame for instance %s: %s", inst->name, strerror(errno));
- #else
+ #ifdef _WIN32
if(WSAGetLastError() != WSAEWOULDBLOCK){
- char* error = NULL;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error, 0, NULL);
- LOGPF("Failed to output frame for instance %s: %s", inst->name, error);
- LocalFree(error);
+ #else
+ if(errno != EAGAIN){
#endif
+ LOGPF("Failed to output frame for instance %s: %s", inst->name, mmbackend_socket_strerror(errno));
return 1;
}
//reschedule frame output
@@ -414,7 +409,7 @@ static int artnet_handle(size_t num, managed_fd* fds){
#else
if(bytes_read < 0 && errno != EAGAIN){
#endif
- LOGPF("Failed to receive data: %s", strerror(errno));
+ LOGPF("Failed to receive data: %s", mmbackend_socket_strerror(errno));
}
if(bytes_read == 0){
diff --git a/backends/maweb.c b/backends/maweb.c
index 6861d75..2804508 100644
--- a/backends/maweb.c
+++ b/backends/maweb.c
@@ -774,7 +774,7 @@ static int maweb_handle_fd(instance* inst){
bytes_read = recv(data->fd, data->buffer + data->offset, bytes_left - 1, 0);
if(bytes_read < 0){
- LOGPF("Failed to receive: %s", strerror(errno));
+ LOGPF("Failed to receive on %s: %s", inst->name, mmbackend_socket_strerror(errno));
//TODO close, reopen
return 1;
}
diff --git a/backends/openpixelcontrol.c b/backends/openpixelcontrol.c
index 2a5e01f..1f8d46a 100644
--- a/backends/openpixelcontrol.c
+++ b/backends/openpixelcontrol.c
@@ -534,7 +534,7 @@ static int openpixel_client_handle(instance* inst, int fd){
ssize_t bytes = recv(fd, buffer, sizeof(buffer), 0);
if(bytes <= 0){
if(bytes < 0){
- LOGPF("Failed to receive from client: %s", strerror(errno));
+ LOGPF("Failed to receive from client: %s", mmbackend_socket_strerror(errno));
}
//close the connection
diff --git a/backends/osc.c b/backends/osc.c
index 72a7b50..8b552b9 100644
--- a/backends/osc.c
+++ b/backends/osc.c
@@ -696,7 +696,7 @@ static int osc_output_channel(instance* inst, size_t channel){
//output packet
if(sendto(data->fd, xmit_buf, offset, 0, (struct sockaddr*) &(data->dest), data->dest_len) < 0){
- LOGPF("Failed to transmit packet: %s", strerror(errno));
+ LOGPF("Failed to transmit packet: %s", mmbackend_socket_strerror(errno));
}
return 0;
}
@@ -917,7 +917,7 @@ static int osc_handle(size_t num, managed_fd* fds){
#else
if(bytes_read < 0 && errno != EAGAIN){
#endif
- LOGPF("Failed to receive data for instance %s: %s", inst->name, strerror(errno));
+ LOGPF("Failed to receive data for instance %s: %s", inst->name, mmbackend_socket_strerror(errno));
}
if(bytes_read == 0){
diff --git a/backends/rtpmidi.c b/backends/rtpmidi.c
index 6aef5a3..52cb0c5 100644
--- a/backends/rtpmidi.c
+++ b/backends/rtpmidi.c
@@ -27,6 +27,20 @@
//TODO timeout non-responsive peers (connected = 0) to allow discovery to reconnect them
//TODO ipv6-mapped-ipv4 creates problems when connecting on a ipv4-bound instance
+/*
+ * CAVEAT EMPTOR: This is one of the largest backends yet, due to the
+ * sheer number of protocols involved and their respective complexity.
+ * The following RFCs may be useful for understanding this backend:
+ * * RFC 6295 (MIDI Payload for RTP)
+ * * RFC 1035 (DNS)
+ * * RFC 6762 (mDNS)
+ * * RFC 6763 (DNS Service Discovery)
+ * * RFC 2782 (SRV RR for DNS)
+ * * To a lesser extent, RFC3550 (RTP)
+ * Additionally, a strong understanding of the MIDI data stream as well as the details of multicast
+ * networking for IPv4 and IPv6 are very helpful.
+ */
+
static struct /*_rtpmidi_global*/ {
int mdns_fd;
char* mdns_name;
@@ -235,7 +249,6 @@ bail:
return -1;
}
-//TODO this should be trimmed down a bit
static int rtpmidi_announce_addrs(){
char repr[INET6_ADDRSTRLEN + 1] = "", iface[2048] = "";
union {
diff --git a/backends/rtpmidi.md b/backends/rtpmidi.md
index 2194a05..13fd1f6 100644
--- a/backends/rtpmidi.md
+++ b/backends/rtpmidi.md
@@ -15,8 +15,8 @@ selectable per-instance, with some methods requiring additional global configura
configured in the instance configuration as well as previously unknown peers that
voluntarily send data to the instance.
* AppleMIDI session management: The instance will be able to communicate (either as participant
- or initiator) in an AppleMIDI session, which can optionally be announced via mDNS (better
- known as "Bonjour" to Apple users).
+ or initiator) in an AppleMIDI session, which will be announced via mDNS (better
+ known as "Bonjour" to Apple users) if possible.
Note that instances that receive data from multiple peers will combine all inputs into one
stream, which may lead to inconsistencies during playback.
diff --git a/backends/sacn.c b/backends/sacn.c
index b3376d7..0444949 100644
--- a/backends/sacn.c
+++ b/backends/sacn.c
@@ -101,7 +101,7 @@ static int sacn_listener(char* host, char* port, uint8_t flags){
if(flags & mcast_loop){
//set IP_MCAST_LOOP to allow local applications to receive output
if(setsockopt(fd, IPPROTO_IP, IP_MULTICAST_LOOP, (void*)&yes, sizeof(yes)) < 0){
- LOGPF("Failed to re-enable IP_MULTICAST_LOOP on socket: %s", strerror(errno));
+ LOGPF("Failed to re-enable IP_MULTICAST_LOOP on socket: %s", mmbackend_socket_strerror(errno));
}
}
@@ -313,17 +313,12 @@ static int sacn_transmit(instance* inst, sacn_output_universe* output){
memcpy((((uint8_t*)pdu.data.data) + 1), data->data.out, 512);
if(sendto(global_cfg.fd[data->fd_index].fd, (uint8_t*) &pdu, sizeof(pdu), 0, (struct sockaddr*) &data->dest_addr, data->dest_len) < 0){
- #ifndef _WIN32
- if(errno != EAGAIN){
- LOGPF("Failed to output frame for instance %s: %s", inst->name, strerror(errno));
- #else
+ #ifdef _WIN32
if(WSAGetLastError() != WSAEWOULDBLOCK){
- char* error = NULL;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error, 0, NULL);
- LOGPF("Failed to output frame for instance %s: %s", inst->name, error);
- LocalFree(error);
+ #else
+ if(errno != EAGAIN){
#endif
+ LOGPF("Failed to output frame for instance %s: %s", inst->name, mmbackend_socket_strerror(errno));
return 1;
}
@@ -512,19 +507,13 @@ static void sacn_discovery(size_t fd){
memcpy(pdu.data.data, global_cfg.fd[fd].universe + page * 512, universes * sizeof(uint16_t));
if(sendto(global_cfg.fd[fd].fd, (uint8_t*) &pdu, sizeof(pdu) - (512 - universes) * sizeof(uint16_t), 0, (struct sockaddr*) &discovery_dest, sizeof(discovery_dest)) < 0){
- #ifndef _WIN32
- if(errno != EAGAIN){
- LOGPF("Failed to output universe discovery frame for interface %" PRIsize_t ": %s", fd, strerror(errno));
- }
- #else
+ #ifdef _WIN32
if(WSAGetLastError() != WSAEWOULDBLOCK){
- char* error = NULL;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
- NULL, WSAGetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &error, 0, NULL);
- LOGPF("Failed to output universe discovery frame for interface %" PRIsize_t ": %s", fd, error);
- LocalFree(error);
- }
+ #else
+ if(errno != EAGAIN){
#endif
+ LOGPF("Failed to output universe discovery frame for interface %" PRIsize_t ": %s", fd, mmbackend_socket_strerror(errno));
+ }
}
}
}
@@ -603,7 +592,7 @@ static int sacn_handle(size_t num, managed_fd* fds){
#else
if(bytes_read < 0 && errno != EAGAIN){
#endif
- LOGPF("Failed to receive data: %s", strerror(errno));
+ LOGPF("Failed to receive data: %s", mmbackend_socket_strerror(errno));
}
if(bytes_read == 0){
@@ -655,7 +644,7 @@ static int sacn_start(size_t n, instance** inst){
if(!data->unicast_input){
mcast_req.imr_multiaddr.s_addr = htobe32(((uint32_t) 0xefff0000) | ((uint32_t) data->uni));
if(setsockopt(global_cfg.fd[data->fd_index].fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (uint8_t*) &mcast_req, sizeof(mcast_req))){
- LOGPF("Failed to join Multicast group for universe %u on instance %s: %s", data->uni, inst[u]->name, strerror(errno));
+ LOGPF("Failed to join Multicast group for universe %u on instance %s: %s", data->uni, inst[u]->name, mmbackend_socket_strerror(errno));
}
}