Skip to content

Commit f4b9bd6

Browse files
committed
Remove socket sendfile wrong implementation
1 parent a656c51 commit f4b9bd6

File tree

2 files changed

+8
-26
lines changed

2 files changed

+8
-26
lines changed

extra_tests/snippets/stdlib_socket.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@
2323
assert recv_a == MESSAGE_A
2424
assert recv_b == MESSAGE_B
2525

26+
fd = open('README.md', 'rb')
27+
connector.sendfile(fd)
28+
recv_readme = connection.recv(os.stat('README.md').st_size)
29+
# need this because sendfile leaves the cursor at the end of the file
30+
fd.seek(0)
31+
assert recv_readme == fd.read()
32+
fd.close()
33+
2634
# fileno
2735
if os.name == "posix":
2836
connector_fd = connector.fileno()

vm/src/stdlib/socket.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::pyobject::{
2121
BorrowValue, Either, IntoPyObject, PyClassImpl, PyObjectRef, PyRef, PyResult, PyValue,
2222
StaticType, TryFromObject,
2323
};
24-
use crate::stdlib::os::rust_file;
2524
use crate::vm::VirtualMachine;
2625

2726
#[cfg(unix)]
@@ -221,31 +220,6 @@ impl PySocket {
221220
Ok(())
222221
}
223222

224-
#[pymethod]
225-
fn sendfile(&self, fd: i64, offset: OptionalArg<u64>, count: OptionalArg<u64>, vm: &VirtualMachine) -> PyResult<usize> {
226-
let mut file = rust_file(fd);
227-
let mut bufsize: u64 = 0;
228-
229-
if let Ok(metadata) = file.metadata() {
230-
bufsize = metadata.len();
231-
}
232-
233-
if let OptionalArg::Present(c) = count {
234-
bufsize = c;
235-
}
236-
237-
let mut buffer = vec![0u8; bufsize as usize];
238-
239-
let n = file
240-
.read(&mut buffer)
241-
.map_err(|err| err.into_pyexception(vm))?;
242-
243-
buffer.truncate(n);
244-
245-
let bytes = PyBytesLike::try_from_object(vm, vm.ctx.new_bytes(buffer))?;
246-
self.send(bytes, vm)
247-
}
248-
249223
#[pymethod]
250224
fn close(&self) {
251225
*self.sock_mut() = invalid_sock();

0 commit comments

Comments
 (0)