Skip to content

Commit 982eb48

Browse files
committed
refactor: remove redundant methods and ctor args
1 parent 0f26a47 commit 982eb48

File tree

3 files changed

+19
-20
lines changed

3 files changed

+19
-20
lines changed

compio-driver/src/iour/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl Driver {
247247
let mut op = unsafe { Key::<dyn crate::sys::OpCode>::new_unchecked(user_data) };
248248
let op_pin = op.as_op_pin();
249249
let res = op_pin.call_blocking();
250-
completed.push(Entry::new(user_data, res, todo!("how to get flags?")));
250+
completed.push(Entry::new(user_data, res));
251251
handle.notify().ok();
252252
})
253253
.is_ok();
@@ -282,8 +282,8 @@ impl AsRawFd for Driver {
282282
}
283283
}
284284

285-
fn create_entry(entry: CEntry) -> Entry {
286-
let result = entry.result();
285+
fn create_entry(cq_entry: CEntry) -> Entry {
286+
let result = cq_entry.result();
287287
let result = if result < 0 {
288288
let result = if result == -libc::ECANCELED {
289289
libc::ETIMEDOUT
@@ -294,7 +294,10 @@ fn create_entry(entry: CEntry) -> Entry {
294294
} else {
295295
Ok(result as _)
296296
};
297-
Entry::new(entry.user_data() as _, result, entry.flags())
297+
let mut entry = Entry::new(cq_entry.user_data() as _, result);
298+
entry.set_flags(entry.flags());
299+
300+
entry
298301
}
299302

300303
fn timespec(duration: std::time::Duration) -> Timespec {

compio-driver/src/key.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ impl<T: ?Sized> Key<T> {
160160
self.as_opaque_mut().flags = flags;
161161
}
162162

163+
pub(crate) fn flags(&self) -> u32 {
164+
self.as_opaque().flags
165+
}
166+
163167
/// Whether the op is completed.
164168
pub(crate) fn has_result(&self) -> bool {
165169
self.as_opaque().result.is_ready()
@@ -195,19 +199,6 @@ impl<T> Key<T> {
195199
let op = unsafe { Box::from_raw(self.user_data as *mut RawOp<T>) };
196200
BufResult(op.result.take_ready().unwrap_unchecked(), op.op)
197201
}
198-
199-
/// Get the inner result and flags if it is completed.
200-
///
201-
/// # Safety
202-
///
203-
/// Call it only when the op is completed, otherwise it is UB.
204-
pub(crate) unsafe fn into_inner_flags(self) -> (BufResult<usize, T>, u32) {
205-
let op = unsafe { Box::from_raw(self.user_data as *mut RawOp<T>) };
206-
(
207-
BufResult(op.result.take_ready().unwrap_unchecked(), op.op),
208-
op.flags,
209-
)
210-
}
211202
}
212203

213204
impl<T: OpCode + ?Sized> Key<T> {

compio-driver/src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,9 @@ impl Proactor {
308308
pub fn pop_flags<T>(&mut self, op: Key<T>) -> PushEntry<Key<T>, (BufResult<usize, T>, u32)> {
309309
instrument!(compio_log::Level::DEBUG, "pop_flags", ?op);
310310
if op.has_result() {
311+
let flags = op.flags();
311312
// SAFETY: completed.
312-
PushEntry::Ready(unsafe { op.into_inner_flags() })
313+
PushEntry::Ready((unsafe { op.into_inner() }, flags))
313314
} else {
314315
PushEntry::Pending(op)
315316
}
@@ -341,14 +342,18 @@ pub(crate) struct Entry {
341342
}
342343

343344
impl Entry {
344-
pub(crate) fn new(user_data: usize, result: io::Result<usize>, flags: u32) -> Self {
345+
pub(crate) fn new(user_data: usize, result: io::Result<usize>) -> Self {
345346
Self {
346347
user_data,
347348
result,
348-
flags,
349+
flags: 0,
349350
}
350351
}
351352

353+
pub(crate) fn set_flags(&mut self, flags: u32) {
354+
self.flags = flags;
355+
}
356+
352357
/// The user-defined data returned by [`Proactor::push`].
353358
pub fn user_data(&self) -> usize {
354359
self.user_data

0 commit comments

Comments
 (0)