From b00ce4fe429d2c9a5e08d5ac6c6bdb454c9e0567 Mon Sep 17 00:00:00 2001
From: Alessio Igor Bogani <alessio.bogani@elettra.eu>
Date: Wed, 7 Feb 2024 13:00:28 +0100
Subject: [PATCH] Consolidate checks for timeout

---
 src/USB2.cpp | 24 ++++++------------------
 1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/src/USB2.cpp b/src/USB2.cpp
index 791e01b..e469894 100644
--- a/src/USB2.cpp
+++ b/src/USB2.cpp
@@ -384,6 +384,12 @@ void USB2::always_executed_hook()
 		return;
 	}
 
+	if (! timeout) {
+		set_state(Tango::FAULT);
+		set_status("Invalid timeout");
+		return;
+	}
+
 	try {
 		if (! dev_handle) {
 			open();
@@ -504,12 +510,6 @@ void USB2::write(const Tango::DevVarCharArray *argin)
 	
 	check_init();
 
-	if(!timeout) {
-		Tango::Except::throw_exception( "",
-				"Invalid timeout",
-				"USB2::write()");
-	}
-
 	unsigned char *argin_data = new unsigned char[argin->length()];
 	for(unsigned int i=0; i<argin->length(); ++i)
 	{
@@ -561,12 +561,6 @@ Tango::DevVarCharArray *USB2::read(Tango::DevLong argin)
 	
 	check_init();
 	
-	if(!timeout) {
-		Tango::Except::throw_exception( "",
-				"Invalid timeout",
-				"USB2::write()");
-	}
-	
 	if (argin < 0)
 	{
 		Tango::Except::throw_exception("",
@@ -619,12 +613,6 @@ Tango::DevVarCharArray *USB2::read_until(const Tango::DevVarCharArray *argin)
 	
 	check_init();
 	
-	if(!timeout) {
-		Tango::Except::throw_exception( "",
-				"Invalid timeout",
-				"USB2::write()");
-	}
-	
 	if (argin->length() != 1)
 	{
 		Tango::Except::throw_exception("",
-- 
GitLab