Re: [hatari-devel] (raw) MIDI connection reliability?

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Hi,

On 18.6.2022 16.05, Eero Tamminen wrote:
Anyway, since EOF is guaranteed to be negative, it shouldn't
really matter much in this case, so never mind, let's just
leave the code as it is.

I think I need to update logging to check errno instead of return value.   Now it ignores all errors as they all get mapped to EOF return value.

Does attached patch look OK? I mean, can we trust on errno being set (glibc fgetc manual does not say anything about errno)...


	- Eero
diff --git a/src/midi.c b/src/midi.c
index 6c951b80..d7fb8e07 100644
--- a/src/midi.c
+++ b/src/midi.c
@@ -23,6 +23,7 @@
 const char Midi_fileid[] = "Hatari midi.c";
 
 #include <SDL_types.h>
+#include <errno.h>
 
 #include "main.h"
 #include "configuration.h"
@@ -313,7 +314,7 @@ void Midi_InterruptHandler_Update(void)
 
 	/* Read the bytes in, if we have any */
 	nInChar = Midi_Host_ReadByte();
-	if (nInChar >= 0)
+	if (nInChar != EOF)
 	{
 		LOG_TRACE(TRACE_MIDI, "MIDI: Read character -> $%x\n", nInChar);
 		/* Copy into our internal queue */
@@ -326,8 +327,8 @@ void Midi_InterruptHandler_Update(void)
 #ifndef HAVE_PORTMIDI
 	else if (pMidiFhIn)
 	{
-		if (nInChar != EOF)
-			LOG_TRACE(TRACE_MIDI, "MIDI: read error %d (does not stop MIDI)\n", nInChar);
+		if (errno)
+			LOG_TRACE(TRACE_MIDI, "MIDI: read error (does not stop MIDI): %s\n", strerror(errno));
 		clearerr(pMidiFhIn);
 	}
 #endif


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/