-
Notifications
You must be signed in to change notification settings - Fork 445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create UDP and TCP sockets #223
Comments
The lifetimes of all sockets unify with each other, so you need to group them like this: let mut udp_rx_payload = [0; 128];
let mut udp_tx_payload = [0; 128];
let mut tcp_rx_payload = [0; 128];
let mut tcp_tx_payload = [0; 128];
let mut udp_tx_metadata = [PacketMetadata::EMPTY; 1];
let mut udp_rx_metadata = [PacketMetadata::EMPTY; 1];
let udp_socket = UdpSocket::new(
UdpSocketBuffer::new(udp_rx_metadata.as_mut(), udp_rx_payload.as_mut()),
UdpSocketBuffer::new(udp_tx_metadata.as_mut(), udp_tx_payload.as_mut()),
);
let tcp_socket = TcpSocket::new(
TcpSocketBuffer::new(tcp_rx_payload.as_mut()),
TcpSocketBuffer::new(tcp_tx_payload.as_mut()),
);
let mut sockets = [None, None];
let mut socket_set = SocketSet::new(sockets.as_mut());
let udp_handle = socket_set.add(udp_socket);
let tcp_handle = socket_set.add(tcp_socket); cf. #48 |
That gives me the same error as before:
Is there something in the surrounding code that I need to check? All of this code exists in |
Oh sorry, I didn't go far enough. You need... let mut udp_rx_payload = [0; 128];
let mut udp_tx_payload = [0; 128];
let mut tcp_rx_payload = [0; 128];
let mut tcp_tx_payload = [0; 128];
let mut udp_tx_metadata = [PacketMetadata::EMPTY; 1];
let mut udp_rx_metadata = [PacketMetadata::EMPTY; 1];
let udp_rx_buffer = UdpSocketBuffer::new(udp_rx_metadata.as_mut(), udp_rx_payload.as_mut());
let udp_tx_buffer = UdpSocketBuffer::new(udp_tx_metadata.as_mut(), udp_tx_payload.as_mut());
let tcp_rx_buffer = TcpSocketBuffer::new(tcp_rx_metadata.as_mut(), tcp_rx_payload.as_mut());
let tcp_tx_buffer = TcpSocketBuffer::new(tcp_tx_metadata.as_mut(), tcp_tx_payload.as_mut());
let udp_socket = UdpSocket::new(udp_rx_buffer, udp_tx_buffer);
let tcp_socket = TcpSocket::new(tcp_rx_buffer, tcp_tx_buffer);
let mut sockets = [None, None];
let mut socket_set = SocketSet::new(sockets.as_mut());
let udp_handle = socket_set.add(udp_socket);
let tcp_handle = socket_set.add(tcp_socket); |
(There is a small typo above. |
Can you post your project somewhere? In any case, here's a working example: https://github.com/m-labs/ionpak/blob/master/firmware/src/main.rs#L158-L194. |
I just made it public. Here is the code in question (without the suggested changes): https://github.com/crawford/PoE/blob/3f26e93afc082af7fc9c40eb1b5c55354afa071a/firmware/src/main.rs#L113. |
@crawford Hmm, I can compile your code with the nightly compiler. (Maybe thanks to the NLL?) |
@progval Did you uncomment line 131? |
@whitequark I'm now getting an eerily similar error after refactoring my Device implementation. This code fails with the following error message:
I wonder if both this failure and the original actually stem from the type definition of Interface and InterfaceBuilder. Both of these structs dictate that DeviceT is a Device of any lifetime (including 'static), but my Device does not implement 'static (unlike the Device in IonPak). I've been trying to modify smoltcp to lift that restriction, but I haven't been able to satisfy the borrow checker yet. EDIT: I was able to fix this last error by breaking up the lifetimes. Changing something like this: struct MAC<'a> {
rx_buffer: &'a mut RxBuffer<'a>,
tx_buffer: &'a mut TxBuffer<'a>,
} into this: struct MAC<'a, 'b: 'a> {
rx_buffer: &'a mut RxBuffer<'b>,
tx_buffer: &'a mut TxBuffer<'b>,
} |
Does it change anything if you move |
@birkenfeld Unfortunately, no. |
This has been fixed by #304. |
I'm trying to create two listening sockets, one UDP and one TCP, with the following code:
When I try to build this, I get the following error:
If I comment out either of the calls to
socket_set.add
, it builds and runs.I'm using rustc 1.28.0-nightly (c2d46037f 2018-05-24).
The text was updated successfully, but these errors were encountered: