Skip to content

Commit 715d31e

Browse files
author
Francesco Mecatti
committed
Buffer flush control
1 parent d00ce2a commit 715d31e

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

ProtocolImplementation/ClientProtocolImplementation/ClientProtocol.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,15 @@ def download_file(self, file):
4141
file.write(self.s.recv(BUFFSIZENUM))
4242
dim -= BUFFSIZENUM
4343
file.write(self.s.recv(dim))
44-
if file.tell() != original_dim:
45-
self.status_handler.error_file_recv_incomplete()
46-
raise ConnectionError("FileRecvIncomplete")
47-
else:
48-
self.status_handler.ok()
44+
cont = 0
45+
while file.tell() != original_dim and cont < 1000: # Flush buffer function
46+
file.write(self.s.recv(BUFFSIZENUM))
47+
cont += 1
48+
if file.tell() != original_dim:
49+
self.status_handler.error_file_recv_incomplete()
50+
raise ConnectionError("FileRecvIncomplete")
51+
else:
52+
self.status_handler.ok()
4953
self.status_handler.end()
5054

5155

ProtocolImplementation/ServerProtocolImplementation/ServerProtocol.py

+17-15
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ def get_input(self, text):
1919
self.status_handler.input()
2020
self.s.sendall(text.encode())
2121
data = self.s.recv(CODEBYTES)
22-
logging.debug(data)
22+
# logging.debug(data)
2323
if not self.status_handler.is_code("OK", data):
2424
raise ConnectionError("Client not confirming")
2525

2626
data = self.s.recv(CODEBYTES)
27-
logging.debug(data)
27+
# logging.debug(data)
2828
if not self.status_handler.is_code("Response", data):
2929
raise ConnectionError("Client not responding")
3030
data = self.s.recv(BUFFSIZENUM).decode().strip()
@@ -58,20 +58,22 @@ def get_file(self, file: BinaryIO, filename):
5858
file.write(self.s.recv(BUFFSIZENUM))
5959
dim -= BUFFSIZENUM
6060
file.write(self.s.recv(dim))
61-
logging.debug(file.tell())
62-
logging.debug(original_dim)
63-
while file.tell() != original_dim:
64-
logging.debug(file.tell())
65-
logging.debug(original_dim)
61+
# logging.debug(file.tell())
62+
# logging.debug(original_dim)
63+
cont = 0
64+
while file.tell() != original_dim and cont < 1000: # Flush buffer function
65+
# logging.debug(file.tell())
66+
# logging.debug(original_dim)
6667
file.write(self.s.recv(BUFFSIZENUM))
67-
# if file.tell() != original_dim: # Size check has no meaning because file size depends on the filesystem
68-
# self.status_handler.error_file_recv_incomplete()
69-
# raise ConnectionError("FileRecvIncomplete")
70-
# else:
71-
# logging.info("File received")
72-
# self.status_handler.ok()
73-
logging.info("File received")
74-
self.status_handler.ok()
68+
cont += 1
69+
if file.tell() != original_dim:
70+
self.status_handler.error_file_recv_incomplete()
71+
raise ConnectionError("FileRecvIncomplete")
72+
else:
73+
logging.info("File received")
74+
self.status_handler.ok()
75+
# logging.info("File received")
76+
# self.status_handler.ok()
7577
self.status_handler.end()
7678

7779
def send_file(self, file, filename):

0 commit comments

Comments
 (0)