Skip to content

Commit 0ae21b3

Browse files
committed
Rearrange mctp trait arguments for consistency
Previously arguments to send() and return value from recv() had different orders. These are now consistent, always ordered (typ, ic, buf, resp) where applicable. pldm and control protocol handlers are updated likewise. Signed-off-by: Matt Johnston <[email protected]>
1 parent d854a29 commit 0ae21b3

File tree

10 files changed

+32
-33
lines changed

10 files changed

+32
-33
lines changed

mctp-estack/src/control.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ pub fn respond_error<'a>(
226226
pub fn mctp_control_rx_req<'f, 'l, L>(
227227
listener: &'l mut L,
228228
buf: &'f mut [u8],
229-
) -> mctp::Result<(L::RespChannel<'l>, MctpControlMsg<'f>)>
229+
) -> mctp::Result<(MctpControlMsg<'f>, L::RespChannel<'l>)>
230230
where
231231
L: Listener,
232232
{
233-
let (buf, ch, typ, ic) = listener.recv(buf)?;
233+
let (typ, ic, buf, ch) = listener.recv(buf)?;
234234
if ic.0 {
235235
return Err(Error::InvalidInput);
236236
}
@@ -240,7 +240,7 @@ where
240240
}
241241

242242
let msg = MctpControlMsg::from_buf(buf).map_err(|_| Error::InvalidInput)?;
243-
Ok((ch, msg))
243+
Ok((msg, ch))
244244
}
245245

246246
/// A Control Message handler.

mctp-estack/src/router.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ impl mctp::AsyncReqChannel for RouterAsyncReqChannel<'_> {
770770
async fn recv<'f>(
771771
&mut self,
772772
buf: &'f mut [u8],
773-
) -> Result<(&'f mut [u8], MsgType, MsgIC)> {
773+
) -> Result<(MsgType, MsgIC, &'f mut [u8])> {
774774
let Some(Tag::Owned(tv)) = self.sent_tag else {
775775
debug!("recv without send");
776776
return Err(Error::BadArgument);
@@ -782,8 +782,7 @@ impl mctp::AsyncReqChannel for RouterAsyncReqChannel<'_> {
782782
.await?;
783783
debug_assert_eq!(tag, recv_tag);
784784
debug_assert_eq!(eid, self.eid);
785-
Ok((buf, typ, ic))
786-
// todo!()
785+
Ok((typ, ic, buf))
787786
}
788787

789788
fn remote_eid(&self) -> Eid {
@@ -857,7 +856,7 @@ impl<'r> mctp::AsyncListener for RouterAsyncListener<'r> {
857856
async fn recv<'f>(
858857
&mut self,
859858
buf: &'f mut [u8],
860-
) -> mctp::Result<(&'f mut [u8], Self::RespChannel<'_>, MsgType, MsgIC)>
859+
) -> mctp::Result<(MsgType, MsgIC, &'f mut [u8], Self::RespChannel<'_>)>
861860
{
862861
let (msg, eid, typ, tag, ic) = self
863862
.router
@@ -875,7 +874,7 @@ impl<'r> mctp::AsyncListener for RouterAsyncListener<'r> {
875874
router: self.router,
876875
typ,
877876
};
878-
Ok((msg, resp, typ, ic))
877+
Ok((typ, ic, msg, resp))
879878
}
880879
}
881880

mctp-linux/examples/mctp-req.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() -> std::io::Result<()> {
2525
// Receive a response. We create a 16-byte vec to read into; ep.recv()
2626
// will return the sub-slice containing just the response data.
2727
let mut rx_buf = vec![0u8; 16];
28-
let (rx_buf, eid, ic) = ep.recv(&mut rx_buf)?;
28+
let (eid, ic, rx_buf) = ep.recv(&mut rx_buf)?;
2929

3030
println!("response from {}, ic {:?}: {:x?}", eid, ic, rx_buf);
3131

mctp-linux/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl mctp::ReqChannel for MctpLinuxReq {
363363
fn recv<'f>(
364364
&mut self,
365365
buf: &'f mut [u8],
366-
) -> Result<(&'f mut [u8], MsgType, MsgIC)> {
366+
) -> Result<(MsgType, MsgIC, &'f mut [u8])> {
367367
if !self.sent {
368368
return Err(mctp::Error::BadArgument);
369369
}
@@ -374,7 +374,7 @@ impl mctp::ReqChannel for MctpLinuxReq {
374374
// Kernel gave us a message from a different sender?
375375
return Err(mctp::Error::Other);
376376
}
377-
Ok((&mut buf[..sz], typ, ic))
377+
Ok((typ, ic, &mut buf[..sz]))
378378
}
379379

380380
fn remote_eid(&self) -> Eid {
@@ -429,7 +429,7 @@ impl mctp::Listener for MctpLinuxListener {
429429
fn recv<'f>(
430430
&mut self,
431431
buf: &'f mut [u8],
432-
) -> Result<(&'f mut [u8], MctpLinuxResp<'_>, MsgType, MsgIC)> {
432+
) -> Result<(MsgType, MsgIC, &'f mut [u8], MctpLinuxResp<'_>)> {
433433
let (sz, addr) = self.sock.recvfrom(buf)?;
434434
let src = Eid(addr.0.smctp_addr);
435435
let (typ, ic) = mctp::decode_type_ic(addr.0.smctp_type);
@@ -448,7 +448,7 @@ impl mctp::Listener for MctpLinuxListener {
448448
listener: self,
449449
typ,
450450
};
451-
Ok((&mut buf[..sz], ep, typ, ic))
451+
Ok((typ, ic, &mut buf[..sz], ep))
452452
}
453453
}
454454

mctp/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ pub trait ReqChannel {
265265
fn recv<'f>(
266266
&mut self,
267267
buf: &'f mut [u8],
268-
) -> Result<(&'f mut [u8], MsgType, MsgIC)>;
268+
) -> Result<(MsgType, MsgIC, &'f mut [u8])>;
269269

270270
/// Return the remote Endpoint ID
271271
fn remote_eid(&self) -> Eid;
@@ -292,7 +292,7 @@ pub trait AsyncReqChannel {
292292
fn recv<'f>(
293293
&mut self,
294294
buf: &'f mut [u8],
295-
) -> impl Future<Output = Result<(&'f mut [u8], MsgType, MsgIC)>>;
295+
) -> impl Future<Output = Result<(MsgType, MsgIC, &'f mut [u8])>>;
296296

297297
/// Return the remote Endpoint ID
298298
fn remote_eid(&self) -> Eid;
@@ -410,7 +410,7 @@ pub trait Listener {
410410
fn recv<'f>(
411411
&mut self,
412412
buf: &'f mut [u8],
413-
) -> Result<(&'f mut [u8], Self::RespChannel<'_>, MsgType, MsgIC)>;
413+
) -> Result<(MsgType, MsgIC, &'f mut [u8], Self::RespChannel<'_>)>;
414414
}
415415

416416
#[allow(missing_docs)]
@@ -431,7 +431,7 @@ pub trait AsyncListener {
431431
&mut self,
432432
buf: &'f mut [u8],
433433
) -> impl Future<
434-
Output = Result<(&'f mut [u8], Self::RespChannel<'_>, MsgType, MsgIC)>,
434+
Output = Result<(MsgType, MsgIC, &'f mut [u8], Self::RespChannel<'_>)>,
435435
>;
436436
}
437437

pldm-fw/src/ua.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ where
348348

349349
loop {
350350
// we should be in update mode, handle incoming data requests
351-
let (mut req_ep, fw_req) = pldm::pldm_rx_req(listener)?;
351+
let (fw_req, mut req_ep) = pldm::pldm_rx_req(listener)?;
352352

353353
if fw_req.typ != PLDM_TYPE_FW {
354354
return Err(PldmUpdateError::new_proto(format!(
@@ -452,7 +452,7 @@ where
452452
}
453453

454454
/* Verify results.. */
455-
let (mut req_ep, fw_req) = pldm::pldm_rx_req(listener)?;
455+
let (fw_req, mut req_ep) = pldm::pldm_rx_req(listener)?;
456456
match fw_req.cmd {
457457
0x17 => {
458458
let res = fw_req.data[0];
@@ -474,7 +474,7 @@ where
474474
drop(req_ep);
475475

476476
/* Apply */
477-
let (mut req_ep, fw_req) = pldm::pldm_rx_req(listener)?;
477+
let (fw_req, mut req_ep) = pldm::pldm_rx_req(listener)?;
478478
match fw_req.cmd {
479479
0x18 => {
480480
let res = fw_req.data[0];

pldm/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,13 @@ pub fn pldm_xfer_buf<'buf>(
434434
#[cfg(feature = "alloc")]
435435
pub fn pldm_rx_req<'lis, L>(
436436
listener: &'lis mut L,
437-
) -> Result<(L::RespChannel<'lis>, PldmRequest<'static>)>
437+
) -> Result<(PldmRequest<'static>, L::RespChannel<'lis>)>
438438
where
439439
L: mctp::Listener,
440440
{
441441
let mut rx_buf = [0u8; PLDM_MAX_MSGSIZE]; // todo: set size? peek?
442-
let (ep, req) = pldm_rx_req_borrowed(listener, &mut rx_buf)?;
443-
Ok((ep, req.make_owned()))
442+
let (req, ep) = pldm_rx_req_borrowed(listener, &mut rx_buf)?;
443+
Ok((req.make_owned(), ep))
444444
}
445445

446446
/// Receive an incoming PLDM request in a borrowed buffer.
@@ -454,11 +454,11 @@ where
454454
pub fn pldm_rx_req_borrowed<'lis, 'buf, L>(
455455
listener: &'lis mut L,
456456
rx_buf: &'buf mut [u8],
457-
) -> Result<(L::RespChannel<'lis>, PldmRequest<'buf>)>
457+
) -> Result<(PldmRequest<'buf>, L::RespChannel<'lis>)>
458458
where
459459
L: mctp::Listener,
460460
{
461-
let (rx_buf, ep, _typ, ic) = listener.recv(rx_buf)?;
461+
let (typ, ic, rx_buf, ep) = listener.recv(rx_buf)?;
462462
if ic.0 {
463463
return Err(proto_error!("IC bit set"));
464464
}
@@ -468,15 +468,15 @@ where
468468
}
469469
let req = PldmRequest::from_buf_borrowed(rx_buf)?;
470470

471-
Ok((ep, req))
471+
Ok((req, ep))
472472
}
473473

474474
/// Receive an incoming PLDM response in a borrowed buffer.
475475
pub fn pldm_rx_resp_borrowed<'buf>(
476476
ep: &mut impl mctp::ReqChannel,
477477
rx_buf: &'buf mut [u8],
478478
) -> Result<PldmResponse<'buf>> {
479-
let (rx_buf, _eid, ic) = ep.recv(rx_buf)?;
479+
let (_typ, ic, rx_buf) = ep.recv(rx_buf)?;
480480
if ic.0 {
481481
return Err(proto_error!("IC bit set"));
482482
}

standalone/examples/echo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn main() -> Result<()> {
6666
loop {
6767
let r = l.recv(&mut buf);
6868
match r {
69-
Ok((buf, mut resp, _typ, _ic)) => {
69+
Ok((_typ, _ic, buf, mut resp)) => {
7070
info!("Received OK {buf:02x?}");
7171
let r = resp.send(buf);
7272
if let Err(e) = r {

standalone/examples/req.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn req(
100100
info!("Sent OK");
101101

102102
let mut buf = [0u8; 2000];
103-
let (rep, rep_typ, _ic) = ch.recv(&mut buf)?;
103+
let (rep_typ, _ic, rep) = ch.recv(&mut buf)?;
104104

105105
info!("Reply {rep:02x?}");
106106

standalone/src/serial.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<S: Read + Write> mctp::ReqChannel for MctpSerialReq<S> {
184184
fn recv<'f>(
185185
&mut self,
186186
buf: &'f mut [u8],
187-
) -> Result<(&'f mut [u8], MsgType, MsgIC)> {
187+
) -> Result<(MsgType, MsgIC, &'f mut [u8])> {
188188
let tv = self.sent_tv.ok_or(Error::BadArgument)?;
189189
let match_tag = Tag::Unowned(tv);
190190

@@ -213,7 +213,7 @@ impl<S: Read + Write> mctp::ReqChannel for MctpSerialReq<S> {
213213
buf.get_mut(..msg.payload.len()).ok_or(Error::NoSpace)?;
214214
b.copy_from_slice(msg.payload);
215215
self.inner.mctp.finished_receive(handle);
216-
return Ok((b, typ, ic));
216+
return Ok((typ, ic, b));
217217
} else {
218218
warn!("Dropped unexpected MCTP message {msg:?}");
219219
self.inner.mctp.finished_receive(handle);
@@ -285,7 +285,7 @@ impl<S: Read + Write> mctp::Listener for MctpSerialListener<S> {
285285
fn recv<'f>(
286286
&mut self,
287287
buf: &'f mut [u8],
288-
) -> Result<(&'f mut [u8], Self::RespChannel<'_>, MsgType, MsgIC)> {
288+
) -> Result<(MsgType, MsgIC, &'f mut [u8], Self::RespChannel<'_>)> {
289289
loop {
290290
// Receive a whole message
291291
let (msg, handle) = self.inner.receive(None)?;
@@ -306,7 +306,7 @@ impl<S: Read + Write> mctp::Listener for MctpSerialListener<S> {
306306
inner: &mut self.inner,
307307
typ,
308308
};
309-
return Ok((b, resp, typ, ic));
309+
return Ok((typ, ic, b, resp));
310310
} else {
311311
trace!("Discarding unmatched message {msg:?}");
312312
self.inner.mctp.finished_receive(handle);

0 commit comments

Comments
 (0)