From a79e3f82d6c19f9991327444ea156380801bffda Mon Sep 17 00:00:00 2001
From: Jan Breuer <jan.breuer@jaybee.cz>
Date: 周日, 14 2月 2016 00:25:03 +0800
Subject: [PATCH] Emit also queue overflow error (issue #66)

---
 libscpi/src/error.c |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/libscpi/src/error.c b/libscpi/src/error.c
index 9afd0f4..9d8e756 100644
--- a/libscpi/src/error.c
+++ b/libscpi/src/error.c
@@ -114,11 +114,13 @@
     return result;
 }
 
-static void SCPI_ErrorAddInternal(scpi_t * context, int16_t err) {
+static scpi_bool_t SCPI_ErrorAddInternal(scpi_t * context, int16_t err) {
     if (!fifo_add(&context->error_queue, err)) {
         fifo_remove_last(&context->error_queue, NULL);
         fifo_add(&context->error_queue, SCPI_ERROR_QUEUE_OVERFLOW);
+        return FALSE;
     }
+    return TRUE;
 }
 
 struct error_reg {
@@ -150,7 +152,7 @@
 
     int i;
 
-    SCPI_ErrorAddInternal(context, err);
+    scpi_bool_t queue_overflow = !SCPI_ErrorAddInternal(context, err);
 
     for (i = 0; i < ERROR_DEFS_N; i++) {
         if ((err <= errs[i].from) && (err >= errs[i].to)) {
@@ -159,6 +161,9 @@
     }
 
     SCPI_ErrorEmit(context, err);
+    if (queue_overflow) {
+        SCPI_ErrorEmit(context, SCPI_ERROR_QUEUE_OVERFLOW);
+    }
 
     if (context) {
         context->cmd_error = TRUE;
@@ -179,14 +184,14 @@
 #else
 #define XE(def, val, str)
 #endif
-            LIST_OF_ERRORS
+        LIST_OF_ERRORS
 
 #if USE_USER_ERROR_LIST
-                    LIST_OF_USER_ERRORS
+        LIST_OF_USER_ERRORS
 #endif
 #undef X
 #undef XE
-                default: return "Unknown error";
+        default: return "Unknown error";
     }
 }
 

--
Gitblit v1.9.1