mirror of https://github.com/m-labs/artiq.git
Rust: set the SOF_KEEPALIVE flag on session sockets.
This commit is contained in:
parent
2b3bc30396
commit
0e2cd38135
|
@ -103,6 +103,10 @@ pub struct udp_pcb {
|
|||
pub const TCP_WRITE_FLAG_COPY: u8 = 0x01;
|
||||
pub const TCP_WRITE_FLAG_MORE: u8 = 0x02;
|
||||
|
||||
pub const SOF_REUSEADDR: u8 = 0x04;
|
||||
pub const SOF_KEEPALIVE: u8 = 0x08;
|
||||
pub const SOF_BROADCAST: u8 = 0x20;
|
||||
|
||||
extern {
|
||||
pub fn pbuf_alloc(l: pbuf_layer, length: u16, type_: pbuf_type) -> *mut pbuf;
|
||||
pub fn pbuf_realloc(p: *mut pbuf, length: u16);
|
||||
|
@ -144,6 +148,7 @@ extern {
|
|||
|
||||
// nonstandard
|
||||
pub fn tcp_sndbuf_(pcb: *mut tcp_pcb) -> u16;
|
||||
pub fn tcp_so_options_(pcb: *mut tcp_pcb) -> *mut u8;
|
||||
|
||||
pub fn udp_new() -> *mut udp_pcb;
|
||||
pub fn udp_new_ip_type(type_: ip_addr_type) -> *mut udp_pcb;
|
||||
|
|
|
@ -397,6 +397,18 @@ impl TcpListener {
|
|||
pub fn try_accept(&self) -> Option<TcpStream> {
|
||||
self.state.borrow_mut().backlog.pop_front()
|
||||
}
|
||||
|
||||
pub fn keepalive(&self) -> bool {
|
||||
unsafe { *lwip_sys::tcp_so_options_(self.raw) & lwip_sys::SOF_KEEPALIVE != 0 }
|
||||
}
|
||||
|
||||
pub fn set_keepalive(&self, keepalive: bool) {
|
||||
if keepalive {
|
||||
unsafe { *lwip_sys::tcp_so_options_(self.raw) |= lwip_sys::SOF_KEEPALIVE }
|
||||
} else {
|
||||
unsafe { *lwip_sys::tcp_so_options_(self.raw) &= !lwip_sys::SOF_KEEPALIVE }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TcpListener {
|
||||
|
|
|
@ -391,6 +391,14 @@ impl<'a> TcpListener<'a> {
|
|||
pub fn acceptable(&self) -> bool {
|
||||
self.lower.state().borrow().acceptable()
|
||||
}
|
||||
|
||||
pub fn keepalive(&self) -> bool {
|
||||
self.lower.keepalive()
|
||||
}
|
||||
|
||||
pub fn set_keepalive(&self, keepalive: bool) {
|
||||
self.lower.set_keepalive(keepalive)
|
||||
}
|
||||
}
|
||||
|
||||
pub use lwip::Shutdown;
|
||||
|
|
|
@ -396,6 +396,7 @@ pub fn thread(waiter: Waiter, spawner: Spawner) {
|
|||
|
||||
let addr = SocketAddr::new(IP_ANY, 1381);
|
||||
let listener = TcpListener::bind(waiter, addr).expect("cannot bind socket");
|
||||
listener.set_keepalive(true);
|
||||
info!("accepting network sessions in Rust");
|
||||
|
||||
let mut kernel_thread = None;
|
||||
|
|
|
@ -237,6 +237,10 @@ u16_t tcp_sndbuf_(struct tcp_pcb *pcb) {
|
|||
return tcp_sndbuf(pcb);
|
||||
}
|
||||
|
||||
u8_t* tcp_so_options_(struct tcp_pcb *pcb) {
|
||||
return &pcb->so_options;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
irq_setmask(0);
|
||||
|
|
Loading…
Reference in New Issue