@@ -205,8 +205,8 @@ macro_rules! mop {
205205
206206 fn take_buffer( self ) -> Option <$inner> {
207207 match self . inner {
208- [ < $name Inner >] :: IoUring ( op) => op. take_buffer( ) ,
209- [ < $name Inner >] :: Poll ( op) => op. take_buffer( ) ,
208+ [ < $name Inner >] :: IoUring ( op) => op. take_buffer( ) . map ( Into :: into ) ,
209+ [ < $name Inner >] :: Poll ( op) => op. take_buffer( ) . map ( Into :: into ) ,
210210 }
211211 }
212212 }
@@ -272,6 +272,157 @@ mop!(<S: AsFd> ReadManagedAt(fd: S, offset: u64, pool: &BufferPool, len: usize)
272272mop ! ( <S : AsFd > ReadManaged ( fd: S , pool: & BufferPool , len: usize ) with pool) ;
273273mop ! ( <S : AsFd > RecvManaged ( fd: S , pool: & BufferPool , len: usize , flags: i32 ) with pool) ;
274274mop ! ( <S : AsFd > RecvFromManaged ( fd: S , pool: & BufferPool , len: usize , flags: i32 ) with pool; ( BufferRef , Option <SockAddr >) ) ;
275+ mop ! ( <C : IoBufMut , S : AsFd > RecvMsgManaged ( fd: S , pool: & BufferPool , len: usize , control: C , flags: i32 ) with pool; ( ( BufferRef , C ) , Option <SockAddr >, usize ) ) ;
275276mop ! ( <S : AsFd > ReadMultiAt ( fd: S , offset: u64 , pool: & BufferPool , len: usize ) with pool) ;
276277mop ! ( <S : AsFd > ReadMulti ( fd: S , pool: & BufferPool , len: usize ) with pool) ;
277278mop ! ( <S : AsFd > RecvMulti ( fd: S , pool: & BufferPool , len: usize , flags: i32 ) with pool) ;
279+ mop ! ( <S : AsFd > RecvFromMulti ( fd: S , pool: & BufferPool , flags: i32 ) with pool; RecvFromMultiResult ) ;
280+ mop ! ( <S : AsFd > RecvMsgMulti ( fd: S , pool: & BufferPool , control_len: usize , flags: i32 ) with pool; RecvMsgMultiResult ) ;
281+
282+ enum RecvFromMultiResultInner {
283+ Poll ( crate :: op:: managed:: RecvFromMultiResult ) ,
284+ IoUring ( iour:: RecvFromMultiResult ) ,
285+ }
286+
287+ /// Result of [`RecvFromMulti`].
288+ pub struct RecvFromMultiResult {
289+ inner : RecvFromMultiResultInner ,
290+ }
291+
292+ impl From < crate :: op:: managed:: RecvFromMultiResult > for RecvFromMultiResult {
293+ fn from ( result : crate :: op:: managed:: RecvFromMultiResult ) -> Self {
294+ Self {
295+ inner : RecvFromMultiResultInner :: Poll ( result) ,
296+ }
297+ }
298+ }
299+
300+ impl From < iour:: RecvFromMultiResult > for RecvFromMultiResult {
301+ fn from ( result : iour:: RecvFromMultiResult ) -> Self {
302+ Self {
303+ inner : RecvFromMultiResultInner :: IoUring ( result) ,
304+ }
305+ }
306+ }
307+
308+ impl RecvFromMultiResult {
309+ /// Create [`RecvFromMultiResult`] from a buffer received from
310+ /// [`RecvFromMulti`]. It should be used for io-uring only.
311+ ///
312+ /// # Safety
313+ ///
314+ /// The buffer must be received from [`RecvFromMulti`] or have the same
315+ /// format as the buffer received from [`RecvFromMulti`].
316+ pub unsafe fn new ( buffer : BufferRef ) -> Self {
317+ Self {
318+ inner : RecvFromMultiResultInner :: IoUring ( unsafe {
319+ iour:: RecvFromMultiResult :: new ( buffer)
320+ } ) ,
321+ }
322+ }
323+
324+ /// Get the payload data.
325+ pub fn data ( & self ) -> & [ u8 ] {
326+ match & self . inner {
327+ RecvFromMultiResultInner :: Poll ( result) => result. data ( ) ,
328+ RecvFromMultiResultInner :: IoUring ( result) => result. data ( ) ,
329+ }
330+ }
331+
332+ /// Get the source address if applicable.
333+ pub fn addr ( & self ) -> Option < SockAddr > {
334+ match & self . inner {
335+ RecvFromMultiResultInner :: Poll ( result) => result. addr ( ) ,
336+ RecvFromMultiResultInner :: IoUring ( result) => result. addr ( ) ,
337+ }
338+ }
339+ }
340+
341+ impl IntoInner for RecvFromMultiResult {
342+ type Inner = BufferRef ;
343+
344+ fn into_inner ( self ) -> Self :: Inner {
345+ match self . inner {
346+ RecvFromMultiResultInner :: Poll ( result) => result. into_inner ( ) ,
347+ RecvFromMultiResultInner :: IoUring ( result) => result. into_inner ( ) ,
348+ }
349+ }
350+ }
351+
352+ enum RecvMsgMultiResultInner {
353+ Poll ( crate :: op:: managed:: RecvMsgMultiResult ) ,
354+ IoUring ( iour:: RecvMsgMultiResult ) ,
355+ }
356+
357+ /// Result of [`RecvMsgMulti`].
358+ pub struct RecvMsgMultiResult {
359+ inner : RecvMsgMultiResultInner ,
360+ }
361+
362+ impl From < crate :: op:: managed:: RecvMsgMultiResult > for RecvMsgMultiResult {
363+ fn from ( result : crate :: op:: managed:: RecvMsgMultiResult ) -> Self {
364+ Self {
365+ inner : RecvMsgMultiResultInner :: Poll ( result) ,
366+ }
367+ }
368+ }
369+
370+ impl From < iour:: RecvMsgMultiResult > for RecvMsgMultiResult {
371+ fn from ( result : iour:: RecvMsgMultiResult ) -> Self {
372+ Self {
373+ inner : RecvMsgMultiResultInner :: IoUring ( result) ,
374+ }
375+ }
376+ }
377+
378+ impl RecvMsgMultiResult {
379+ /// Create [`RecvMsgMultiResult`] from a buffer received from
380+ /// [`RecvMsgMulti`]. It should be used for io-uring only.
381+ ///
382+ /// # Safety
383+ ///
384+ /// The buffer must be received from [`RecvMsgMulti`] or have the same
385+ /// format as the buffer received from [`RecvMsgMulti`].
386+ pub unsafe fn new ( buffer : BufferRef , clen : usize ) -> Self {
387+ Self {
388+ inner : RecvMsgMultiResultInner :: IoUring ( unsafe {
389+ iour:: RecvMsgMultiResult :: new ( buffer, clen)
390+ } ) ,
391+ }
392+ }
393+
394+ /// Get the payload data.
395+ pub fn data ( & self ) -> & [ u8 ] {
396+ match & self . inner {
397+ RecvMsgMultiResultInner :: Poll ( result) => result. data ( ) ,
398+ RecvMsgMultiResultInner :: IoUring ( result) => result. data ( ) ,
399+ }
400+ }
401+
402+ /// Get the ancillary data.
403+ pub fn ancillary ( & self ) -> & [ u8 ] {
404+ match & self . inner {
405+ RecvMsgMultiResultInner :: Poll ( result) => result. ancillary ( ) ,
406+ RecvMsgMultiResultInner :: IoUring ( result) => result. ancillary ( ) ,
407+ }
408+ }
409+
410+ /// Get the source address if applicable.
411+ pub fn addr ( & self ) -> Option < SockAddr > {
412+ match & self . inner {
413+ RecvMsgMultiResultInner :: Poll ( result) => result. addr ( ) ,
414+ RecvMsgMultiResultInner :: IoUring ( result) => result. addr ( ) ,
415+ }
416+ }
417+ }
418+
419+ impl IntoInner for RecvMsgMultiResult {
420+ type Inner = BufferRef ;
421+
422+ fn into_inner ( self ) -> Self :: Inner {
423+ match self . inner {
424+ RecvMsgMultiResultInner :: Poll ( result) => result. into_inner ( ) ,
425+ RecvMsgMultiResultInner :: IoUring ( result) => result. into_inner ( ) ,
426+ }
427+ }
428+ }
0 commit comments