summaryrefslogtreecommitdiff
path: root/core/examples/http_bench.rs
diff options
context:
space:
mode:
Diffstat (limited to 'core/examples/http_bench.rs')
-rw-r--r--core/examples/http_bench.rs47
1 files changed, 23 insertions, 24 deletions
diff --git a/core/examples/http_bench.rs b/core/examples/http_bench.rs
index 73a4720c2..3c077562d 100644
--- a/core/examples/http_bench.rs
+++ b/core/examples/http_bench.rs
@@ -36,25 +36,23 @@ impl log::Log for Logger {
fn flush(&self) {}
}
-const OP_LISTEN: i32 = 1;
-const OP_ACCEPT: i32 = 2;
-const OP_READ: i32 = 3;
-const OP_WRITE: i32 = 4;
-const OP_CLOSE: i32 = 5;
+const OP_LISTEN: OpId = 1;
+const OP_ACCEPT: OpId = 2;
+const OP_READ: OpId = 3;
+const OP_WRITE: OpId = 4;
+const OP_CLOSE: OpId = 5;
#[derive(Clone, Debug, PartialEq)]
pub struct Record {
pub promise_id: i32,
- pub op_id: i32,
pub arg: i32,
pub result: i32,
}
impl Into<Buf> for Record {
fn into(self) -> Buf {
- let buf32 = vec![self.promise_id, self.op_id, self.arg, self.result]
- .into_boxed_slice();
- let ptr = Box::into_raw(buf32) as *mut [u8; 16];
+ let buf32 = vec![self.promise_id, self.arg, self.result].into_boxed_slice();
+ let ptr = Box::into_raw(buf32) as *mut [u8; 3 * 4];
unsafe { Box::from_raw(ptr) }
}
}
@@ -63,28 +61,26 @@ impl From<&[u8]> for Record {
fn from(s: &[u8]) -> Record {
#[allow(clippy::cast_ptr_alignment)]
let ptr = s.as_ptr() as *const i32;
- let ints = unsafe { std::slice::from_raw_parts(ptr, 4) };
+ let ints = unsafe { std::slice::from_raw_parts(ptr, 3) };
Record {
promise_id: ints[0],
- op_id: ints[1],
- arg: ints[2],
- result: ints[3],
+ arg: ints[1],
+ result: ints[2],
}
}
}
impl From<Buf> for Record {
fn from(buf: Buf) -> Record {
- assert_eq!(buf.len(), 4 * 4);
+ assert_eq!(buf.len(), 3 * 4);
#[allow(clippy::cast_ptr_alignment)]
- let ptr = Box::into_raw(buf) as *mut [i32; 4];
+ let ptr = Box::into_raw(buf) as *mut [i32; 3];
let ints: Box<[i32]> = unsafe { Box::from_raw(ptr) };
- assert_eq!(ints.len(), 4);
+ assert_eq!(ints.len(), 3);
Record {
promise_id: ints[0],
- op_id: ints[1],
- arg: ints[2],
- result: ints[3],
+ arg: ints[1],
+ result: ints[2],
}
}
}
@@ -93,7 +89,6 @@ impl From<Buf> for Record {
fn test_record_from() {
let r = Record {
promise_id: 1,
- op_id: 2,
arg: 3,
result: 4,
};
@@ -102,7 +97,7 @@ fn test_record_from() {
#[cfg(target_endian = "little")]
assert_eq!(
buf,
- vec![1u8, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0].into_boxed_slice()
+ vec![1u8, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0].into_boxed_slice()
);
let actual = Record::from(buf);
assert_eq!(actual, expected);
@@ -111,10 +106,14 @@ fn test_record_from() {
pub type HttpBenchOp = dyn Future<Item = i32, Error = std::io::Error> + Send;
-fn dispatch(control: &[u8], zero_copy_buf: Option<PinnedBuf>) -> CoreOp {
+fn dispatch(
+ op_id: OpId,
+ control: &[u8],
+ zero_copy_buf: Option<PinnedBuf>,
+) -> CoreOp {
let record = Record::from(control);
let is_sync = record.promise_id == 0;
- let http_bench_op = match record.op_id {
+ let http_bench_op = match op_id {
OP_LISTEN => {
assert!(is_sync);
op_listen()
@@ -139,7 +138,7 @@ fn dispatch(control: &[u8], zero_copy_buf: Option<PinnedBuf>) -> CoreOp {
let rid = record.arg;
op_write(rid, zero_copy_buf)
}
- _ => panic!("bad op {}", record.op_id),
+ _ => panic!("bad op {}", op_id),
};
let mut record_a = record.clone();
let mut record_b = record.clone();