@@ -28,11 +28,9 @@ pub struct MemoryPool {
2828// Associate Functions
2929//======================================================================================================================
3030
31- /// Associated functions for memory pool.
3231impl MemoryPool {
33- /// Creates a new memory pool.
3432 pub fn new ( name : CString , data_room_size : usize , pool_size : usize , cache_size : usize ) -> Result < Self , Fail > {
35- let pool: * mut rte_mempool = unsafe {
33+ let pool = unsafe {
3634 rte_pktmbuf_pool_create (
3735 name. as_ptr ( ) ,
3836 pool_size as u32 ,
@@ -45,8 +43,8 @@ impl MemoryPool {
4543
4644 // Failed to create memory pool.
4745 if pool. is_null ( ) {
48- let rte_errno: libc :: c_int = unsafe { rte_errno ( ) } ;
49- let cause: String = format ! ( "failed to create memory pool: {:?}" , rte_errno) ;
46+ let rte_errno = unsafe { rte_errno ( ) } ;
47+ let cause = format ! ( "failed to create memory pool: {:?}" , rte_errno) ;
5048 error ! ( "new(): {}" , cause) ;
5149 return Err ( Fail :: new ( libc:: EAGAIN , & cause) ) ;
5250 }
@@ -59,24 +57,22 @@ impl MemoryPool {
5957 self . pool
6058 }
6159
62- /// Allocates a mbuf in the target memory pool.
6360 pub fn alloc_mbuf ( & self , size : Option < usize > ) -> Result < * mut rte_mbuf , Fail > {
6461 // TODO: Drop the following warning once DPDK memory management is more stable.
6562 warn ! ( "allocating mbuf from DPDK pool" ) ;
6663
67- // Allocate mbuf.
68- let mbuf_ptr : * mut rte_mbuf = unsafe { rte_pktmbuf_alloc ( self . pool ) } ;
64+ let mbuf_ptr = unsafe { rte_pktmbuf_alloc ( self . pool ) } ;
65+
6966 if mbuf_ptr. is_null ( ) {
70- let rte_errno: libc :: c_int = unsafe { rte_errno ( ) } ;
71- let cause: String = format ! ( "cannot allocate an mbuf at this time: {:?}" , rte_errno) ;
67+ let rte_errno = unsafe { rte_errno ( ) } ;
68+ let cause = format ! ( "cannot allocate an mbuf at this time: {:?}" , rte_errno) ;
7269 warn ! ( "alloc_mbuf(): {}" , cause) ;
73-
7470 return Err ( Fail :: new ( libc:: ENOMEM , & cause) ) ;
7571 }
7672
7773 // Fill out some fields of the underlying mbuf.
7874 unsafe {
79- let mut num_bytes: u16 = ( * mbuf_ptr) . buf_len - ( * mbuf_ptr) . data_off ;
75+ let mut num_bytes = ( * mbuf_ptr) . buf_len - ( * mbuf_ptr) . data_off ;
8076
8177 if let Some ( size) = size {
8278 // Check if allocated buffer is big enough.
0 commit comments