diff options
author | pzread <netfirewall@gmail.com> | 2013-05-31 01:04:19 +0800 |
---|---|---|
committer | pzread <netfirewall@gmail.com> | 2013-05-31 01:04:19 +0800 |
commit | 42463e2fc315928c3b14bd77de5c6741edade365 (patch) | |
tree | 629a46aba852314d1e38006d3fc55cb6f1b82709 /src/py/netio.py | |
parent | 05c48532dc67c44d12682de3ece293e6f2a412f3 (diff) | |
download | taiwan-online-judge-42463e2fc315928c3b14bd77de5c6741edade365.tar.gz taiwan-online-judge-42463e2fc315928c3b14bd77de5c6741edade365.tar.zst taiwan-online-judge-42463e2fc315928c3b14bd77de5c6741edade365.zip |
Add cancel sendfile
Diffstat (limited to 'src/py/netio.py')
-rw-r--r-- | src/py/netio.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/py/netio.py b/src/py/netio.py index 2910207..df19627 100644 --- a/src/py/netio.py +++ b/src/py/netio.py @@ -289,7 +289,7 @@ class SocketConnection(Connection): self.main_stream.write(struct.pack('l',len(data)) + data) - def send_file(self,filekey,filepath): + def send_file(self,filekey,filepath,callback): def _conn_cb(): self._add_sendfile(filekey,_fail_cb) @@ -306,7 +306,7 @@ class SocketConnection(Connection): os.close(fd) - print('send done') + callback() def _fail_cb(): try: @@ -328,7 +328,7 @@ class SocketConnection(Connection): file_stream.set_close_callback(lambda stream : _fail_cb()) file_stream.connect(_conn_cb) - def recv_file(self,filekey,filesize,filepath): + def recv_file(self,filekey,filesize,filepath,callback): def _conn_cb(stream): nonlocal file_stream @@ -343,9 +343,10 @@ class SocketConnection(Connection): file_stream.close() os.close(fd) - print('recv done') print(time.perf_counter() - st) + callback() + def _fail_cb(): try: del self._sendfile_filekeymap[filekey] |