|
13 | 13 | //! operations, using MCTP-specific addressing structures. |
14 | 14 | //! |
15 | 15 | //! [`MctpSocket`] provides support for blocking socket operations |
16 | | -//! [sendto](MctpSocket::sendto), [`recvfrom`](MctpSocket::recvfrom) and |
17 | | -//! [`bind`](MctpSocket::bind). |
| 16 | +//! [`sendto`](MctpSocket::sendto), [`sendmsg`](MctpSocket::sendmsg), |
| 17 | +//! ([`recvfrom`](MctpSocket::recvfrom) and [`bind`](MctpSocket::bind). |
18 | 18 | //! |
19 | 19 | //! ```no_run |
20 | 20 | //! use mctp_linux; |
@@ -205,27 +205,6 @@ impl MctpSocket { |
205 | 205 | Ok((len, addr)) |
206 | 206 | } |
207 | 207 |
|
208 | | - fn io_sendto( |
209 | | - &self, |
210 | | - buf: &[u8], |
211 | | - addr: &MctpSockAddr, |
212 | | - ) -> std::io::Result<usize> { |
213 | | - let (addr_ptr, addr_len) = addr.as_raw(); |
214 | | - let buf_ptr = buf.as_ptr() as *const libc::c_void; |
215 | | - let buf_len = buf.len() as libc::size_t; |
216 | | - let fd = self.as_raw_fd(); |
217 | | - |
218 | | - let rc = unsafe { |
219 | | - libc::sendto(fd, buf_ptr, buf_len, 0, addr_ptr, addr_len) |
220 | | - }; |
221 | | - |
222 | | - if rc < 0 { |
223 | | - Err(Error::last_os_error()) |
224 | | - } else { |
225 | | - Ok(rc as usize) |
226 | | - } |
227 | | - } |
228 | | - |
229 | 208 | fn io_sendmsg( |
230 | 209 | &self, |
231 | 210 | bufs: &[&[u8]], |
@@ -262,7 +241,19 @@ impl MctpSocket { |
262 | 241 | /// |
263 | 242 | /// Essentially a wrapper around [libc::sendto]. |
264 | 243 | pub fn sendto(&self, buf: &[u8], addr: &MctpSockAddr) -> Result<usize> { |
265 | | - self.io_sendto(buf, addr).map_err(mctp::Error::Io) |
| 244 | + self.sendmsg(&[buf], addr) |
| 245 | + } |
| 246 | + |
| 247 | + /// Blocking send to a socket, given a slice of buffers and address, returning |
| 248 | + /// the number of bytes sent. |
| 249 | + /// |
| 250 | + /// Essentially a wrapper around [libc::sendmsg]. |
| 251 | + pub fn sendmsg( |
| 252 | + &self, |
| 253 | + bufs: &[&[u8]], |
| 254 | + addr: &MctpSockAddr, |
| 255 | + ) -> Result<usize> { |
| 256 | + self.io_sendmsg(bufs, addr).map_err(mctp::Error::Io) |
266 | 257 | } |
267 | 258 |
|
268 | 259 | /// Bind the socket to a local address. |
@@ -408,10 +399,7 @@ impl MctpSocketAsync { |
408 | 399 | buf: &[u8], |
409 | 400 | addr: &MctpSockAddr, |
410 | 401 | ) -> Result<usize> { |
411 | | - self.0 |
412 | | - .write_with(|io| io.io_sendto(buf, addr)) |
413 | | - .await |
414 | | - .map_err(mctp::Error::Io) |
| 402 | + self.sendmsg(&[buf], addr).await |
415 | 403 | } |
416 | 404 |
|
417 | 405 | /// Send a message to a given address, from a set of buffers. |
|
0 commit comments