ソースを参照

Use enum for socket type

Alice Wang 2 年 前
コミット
3baf2581fd
2 ファイル変更14 行追加3 行削除
  1. 13 2
      src/device/socket/protocol.rs
  2. 1 1
      src/device/socket/vsock.rs

+ 13 - 2
src/device/socket/protocol.rs

@@ -12,7 +12,18 @@ use zerocopy::{
     AsBytes, FromBytes,
 };
 
-pub const TYPE_STREAM_SOCKET: u16 = 1;
+/// Currently only stream sockets are supported. type is 1 for stream socket types.
+/// Stream sockets provide in-order, guaranteed, connection-oriented delivery without message boundaries.
+#[derive(Copy, Clone, Debug)]
+pub enum SocketType {
+    Stream,
+}
+
+impl Into<U16<LittleEndian>> for SocketType {
+    fn into(self) -> U16<LittleEndian> {
+        (self as u16).into()
+    }
+}
 
 /// VirtioVsockConfig is the vsock device configuration space.
 #[repr(C)]
@@ -49,7 +60,7 @@ impl Default for VirtioVsockHdr {
             src_port: 0.into(),
             dst_port: 0.into(),
             len: 0.into(),
-            socket_type: TYPE_STREAM_SOCKET.into(),
+            socket_type: SocketType::Stream.into(),
             op: 0.into(),
             flags: 0.into(),
             buf_alloc: 0.into(),

+ 1 - 1
src/device/socket/vsock.rs

@@ -8,7 +8,7 @@ use crate::queue::VirtQueue;
 use crate::transport::Transport;
 use crate::volatile::volread;
 use crate::Result;
-use log::{trace, info};
+use log::{info, trace};
 use zerocopy::AsBytes;
 
 const RX_QUEUE_IDX: u16 = 0;