Browse Source

Removed broken non-blocking support.

Steven Engler 5 years ago
parent
commit
b850f6f6f3
2 changed files with 22 additions and 31 deletions
  1. 15 24
      src/basic_protocols.py
  2. 7 7
      src/throughput_protocols.py

+ 15 - 24
src/basic_protocols.py

@@ -59,23 +59,20 @@ class ProtocolHelper():
 	#
 #
 class Protocol():
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		"""
 		This function should be overridden. It runs a single iteration of the protocol.
 		"""
 		#
 		pass
 	#
-	def run(self, block=True):
+	def run(self):
 		while True:
-			finished = self._run_iteration(block=block)
+			finished = self._run_iteration()
 			#
 			if finished:
 				# protocol is done
 				return True
-			elif not block:
-				# not done the protocol yet, but don't block
-				return False
 			#
 		#
 	#
@@ -88,12 +85,12 @@ class ChainedProtocol(Protocol):
 		self.states = enum.Enum('CHAIN_STATES', 'READY_TO_BEGIN RUNNING DONE')
 		self.state = self.states.READY_TO_BEGIN
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			self.state = self.states.RUNNING
 		#
 		if self.state is self.states.RUNNING:
-			if self.protocols[self.current_protocol] is None or self.protocols[self.current_protocol].run(block=block):
+			if self.protocols[self.current_protocol] is None or self.protocols[self.current_protocol].run():
 				self.current_protocol += 1
 			#
 			if self.current_protocol >= len(self.protocols):
@@ -117,7 +114,7 @@ class Socks4Protocol(Protocol):
 		#
 		self.protocol_helper = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			self.protocol_helper = ProtocolHelper()
 			self.protocol_helper.set_buffer(self.socks_cmd(self.addr_port, self.username))
@@ -191,7 +188,7 @@ class PushDataProtocol(Protocol):
 		self.bytes_written = 0
 		self.protocol_helper = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			info = self.total_bytes.to_bytes(8, byteorder='big', signed=False)
 			info += len(self.byte_buffer).to_bytes(8, byteorder='big', signed=False)
@@ -206,9 +203,6 @@ class PushDataProtocol(Protocol):
 		#
 		if self.state is self.states.PUSH_DATA:
 			if self.use_acceleration:
-				if not block:
-					logging.warning('Protocol set to non-blocking, but using the blocking accelerated function.')
-				#
 				ret_val = accelerated_functions.push_data(self.socket.fileno(), self.total_bytes, self.byte_buffer)
 				if ret_val < 0:
 					raise ProtocolException('Error while pushing data.')
@@ -267,7 +261,7 @@ class PullDataProtocol(Protocol):
 		self._time_of_first_byte = None
 		self.elapsed_time = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			self.protocol_helper = ProtocolHelper()
 			self.state = self.states.RECV_INFO
@@ -283,9 +277,6 @@ class PullDataProtocol(Protocol):
 		#
 		if self.state is self.states.PULL_DATA:
 			if self.use_acceleration:
-				if not block:
-					logging.warning('Protocol set to non-blocking, but using the blocking accelerated function.')
-				#
 				(ret_val, elapsed_time) = accelerated_functions.pull_data(self.socket.fileno(), self.data_size, self.recv_buffer_len)
 				if ret_val < 0:
 					raise ProtocolException('Error while pulling data.')
@@ -344,7 +335,7 @@ class SendDataProtocol(Protocol):
 		#
 		self.protocol_helper = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			info_size = 20
 			info = len(self.send_data).to_bytes(info_size, byteorder='big', signed=False)
@@ -392,7 +383,7 @@ class ReceiveDataProtocol(Protocol):
 		self.data_size = None
 		self.received_data = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			self.protocol_helper = ProtocolHelper()
 			self.state = self.states.RECV_INFO
@@ -464,7 +455,7 @@ class SimpleClientConnectionProtocol(Protocol):
 			self.socket.connect(self.proxy)
 		#
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			if self.proxy is None:
 				self.sub_protocol = PushDataProtocol(self.socket, self.total_bytes, self.data_generator)
@@ -475,13 +466,13 @@ class SimpleClientConnectionProtocol(Protocol):
 			#
 		#
 		if self.state is self.states.CONNECT_TO_PROXY:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				self.sub_protocol = PushDataProtocol(self.socket, self.total_bytes, self.data_generator)
 				self.state = self.states.PUSH_DATA
 			#
 		#
 		if self.state is self.states.PUSH_DATA:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				self.state = self.states.DONE
 			#
 		#
@@ -502,13 +493,13 @@ class SimpleServerConnectionProtocol(Protocol):
 		#
 		self.sub_protocol = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			self.sub_protocol = PullDataProtocol(self.socket)
 			self.state = self.states.PULL_DATA
 		#
 		if self.state is self.states.PULL_DATA:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				if self.bandwidth_callback:
 					self.bandwidth_callback(self.conn_id, self.sub_protocol.data_size, self.sub_protocol.calc_transfer_rate())
 				#

+ 7 - 7
src/throughput_protocols.py

@@ -21,19 +21,19 @@ class ClientProtocol(basic_protocols.Protocol):
 		self.group_id = int(self.wait_until*1000) if self.wait_until is not None else 0
 		# a group id of 0 means no group
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			group_id_bytes = self.group_id.to_bytes(8, byteorder='big', signed=False)
 			self.sub_protocol = basic_protocols.SendDataProtocol(self.socket, group_id_bytes)
 			self.state = self.states.SEND_GROUP_ID
 		#
 		if self.state is self.states.SEND_GROUP_ID:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				self.state = self.states.WAIT
 			#
 		#
 		if self.state is self.states.WAIT:
-			if block and self.wait_until is not None:
+			if self.wait_until is not None:
 				time.sleep(self.wait_until-time.time())
 			#
 			if self.wait_until is None or time.time() >= self.wait_until:
@@ -44,7 +44,7 @@ class ClientProtocol(basic_protocols.Protocol):
 			#
 		#
 		if self.state is self.states.PUSH_DATA:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				self.state = self.states.DONE
 			#
 		#
@@ -67,13 +67,13 @@ class ServerProtocol(basic_protocols.Protocol):
 		#
 		self.sub_protocol = None
 	#
-	def _run_iteration(self, block=True):
+	def _run_iteration(self):
 		if self.state is self.states.READY_TO_BEGIN:
 			self.sub_protocol = basic_protocols.ReceiveDataProtocol(self.socket)
 			self.state = self.states.RECV_GROUP_ID
 		#
 		if self.state is self.states.RECV_GROUP_ID:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				group_id = int.from_bytes(self.sub_protocol.received_data, byteorder='big', signed=False)
 				if group_id == 0:
 					# a group of 0 means no group
@@ -85,7 +85,7 @@ class ServerProtocol(basic_protocols.Protocol):
 			#
 		#
 		if self.state is self.states.PULL_DATA:
-			if self.sub_protocol.run(block=block):
+			if self.sub_protocol.run():
 				if self.bandwidth_callback:
 					self.bandwidth_callback(self.conn_id, self.sub_protocol.data_size, self.sub_protocol.calc_transfer_rate())
 				#