Skip to content

Commit 9b5ba06

Browse files
committed
Return addr in accept
1 parent 86b60fa commit 9b5ba06

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

tests/snippets/stdlib_socket.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
connector = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
1414
connector.connect(("127.0.0.1", listener.getsockname()[1]))
15-
connection = listener.accept()[0]
15+
(connection, addr) = listener.accept()
16+
assert addr == connector.getsockname()
1617

1718
connector.send(MESSAGE_A)
1819
connection.send(MESSAGE_B)

vm/src/stdlib/socket.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl Connection {
6868
match self {
6969
Connection::TcpListener(con) => con.local_addr(),
7070
Connection::UdpSocket(con) => con.local_addr(),
71-
_ => Err(io::Error::new(io::ErrorKind::Other, "oh no!")),
71+
Connection::TcpStream(con) => con.local_addr(),
7272
}
7373
}
7474

@@ -263,8 +263,8 @@ fn socket_accept(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
263263
None => return Err(vm.new_type_error("".to_string())),
264264
};
265265

266-
let tcp_stream = match ret {
267-
Ok((socket, _addr)) => socket,
266+
let (tcp_stream, addr) = match ret {
267+
Ok((socket, addr)) => (socket, addr),
268268
_ => return Err(vm.new_type_error("".to_string())),
269269
};
270270

@@ -281,7 +281,7 @@ fn socket_accept(vm: &mut VirtualMachine, args: PyFuncArgs) -> PyResult {
281281
zelf.typ(),
282282
);
283283

284-
let elements = RefCell::new(vec![sock_obj, vm.get_none()]);
284+
let elements = RefCell::new(vec![sock_obj, get_addr_tuple(vm, addr)?]);
285285

286286
Ok(PyObject::new(
287287
PyObjectPayload::Sequence { elements },

0 commit comments

Comments
 (0)