Skip to content

Commit d51d602

Browse files
authored
Merge pull request #276 from 879650736/axnet
smoltcp_impl: Add Nagle, and Capacity Interfaces
2 parents 2b697cf + 380f5fd commit d51d602

File tree

1 file changed

+43
-0
lines changed
  • modules/axnet/src/smoltcp_impl

1 file changed

+43
-0
lines changed

modules/axnet/src/smoltcp_impl/tcp.rs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,49 @@ impl TcpSocket {
343343
}),
344344
}
345345
}
346+
347+
/// Checks if Nagle's algorithm is enabled for this TCP socket.
348+
#[inline]
349+
pub fn nodelay(&self) -> AxResult<bool> {
350+
if let Some(h) = unsafe { self.handle.get().read() } {
351+
Ok(SOCKET_SET.with_socket::<tcp::Socket, _, _>(h, |socket| socket.nagle_enabled()))
352+
} else {
353+
ax_err!(NotConnected, "socket is not connected")
354+
}
355+
}
356+
357+
/// Enables or disables Nagle's algorithm for this TCP socket.
358+
#[inline]
359+
pub fn set_nodelay(&self, enabled: bool) -> AxResult<()> {
360+
if let Some(h) = unsafe { self.handle.get().read() } {
361+
SOCKET_SET.with_socket_mut::<tcp::Socket, _, _>(h, |socket| {
362+
socket.set_nagle_enabled(enabled);
363+
});
364+
Ok(())
365+
} else {
366+
ax_err!(NotConnected, "socket is not connected")
367+
}
368+
}
369+
370+
/// Returns the maximum capacity of the receive buffer in bytes.
371+
#[inline]
372+
pub fn recv_capacity(&self) -> AxResult<usize> {
373+
if let Some(h) = unsafe { self.handle.get().read() } {
374+
Ok(SOCKET_SET.with_socket::<tcp::Socket, _, _>(h, |socket| socket.recv_capacity()))
375+
} else {
376+
ax_err!(NotConnected, "socket is not connected")
377+
}
378+
}
379+
380+
/// Returns the maximum capacity of the send buffer in bytes.
381+
#[inline]
382+
pub fn send_capacity(&self) -> AxResult<usize> {
383+
if let Some(h) = unsafe { self.handle.get().read() } {
384+
Ok(SOCKET_SET.with_socket::<tcp::Socket, _, _>(h, |socket| socket.send_capacity()))
385+
} else {
386+
ax_err!(NotConnected, "socket is not connected")
387+
}
388+
}
346389
}
347390

348391
/// Private methods

0 commit comments

Comments
 (0)