diff --git a/src/Socket2.cpp b/src/Socket2.cpp
index 60c1f9b06a3ecee0c7e2a0841472c4bf46f6d142..698247b32c848bb7ec804455b18a983ff821526b 100644
--- a/src/Socket2.cpp
+++ b/src/Socket2.cpp
@@ -505,7 +505,6 @@ void Socket2::write(const Tango::DevVarCharArray *argin)
 	vector<unsigned char> argin_data;
 	argin_data << *argin;
 	size_t bytes_total = 0, bytes_to_write = argin_data.size();
-	int olength;
 
 	while (bytes_total < bytes_to_write) {
 		int s = select(WRITE);
@@ -533,12 +532,10 @@ void Socket2::write(const Tango::DevVarCharArray *argin)
 	timeval twait;
 	timerclear(&twait);
 	twait.tv_usec = 1000;
-	olength = max(output_queue_length(), 0);
-	while ((bytes_total - olength) != bytes_to_write) {
+	while (max(output_queue_length(), 0) != 0) {
 		if (! sleep(twait))
 			goto timeout;
 		timeradd(&twait, &twait, &twait);
-		olength = max(output_queue_length(), 0);
 	}
 
 	return;