File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
src/vmm/src/devices/virtio/net Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,20 @@ impl Tap {
185
185
Ok ( ( ) )
186
186
}
187
187
188
+ /// Read into slice of iovec from the tap
189
+ pub ( crate ) fn read_iovec ( & mut self , buffers : & [ libc:: iovec ] ) -> Result < usize , IoError > {
190
+ let iovcnt = i32:: try_from ( buffers. len ( ) ) . unwrap ( ) ;
191
+ let iov = buffers. as_ptr ( ) ;
192
+
193
+ // SAFETY: `writev` is safe. Called with a valid tap fd, the iovec pointer and length
194
+ // is provide by the `IoVecBuffer` implementation and we check the return value.
195
+ let ret = unsafe { libc:: readv ( self . tap_file . as_raw_fd ( ) , iov, iovcnt) } ;
196
+ if ret == -1 {
197
+ return Err ( IoError :: last_os_error ( ) ) ;
198
+ }
199
+ Ok ( usize:: try_from ( ret) . unwrap ( ) )
200
+ }
201
+
188
202
/// Write an `IoVecBuffer` to tap
189
203
pub ( crate ) fn write_iovec ( & mut self , buffer : & IoVecBuffer ) -> Result < usize , IoError > {
190
204
let iovcnt = i32:: try_from ( buffer. iovec_count ( ) ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments