[catnap] Bug Fix: Missing push2 Implementation
@@ -228,6 +228,18 @@ impl CatnapLibOS {
}
}
+ // Handles a push operation.
+ fn do_push(&mut self, qd: QDesc, buf: Bytes) -> Result<QToken, Fail> {
+ match self.sockets.get(&qd) {
+ Some(&fd) => {
+ let future: Operation = Operation::from(PushFuture::new(qd, fd, buf));
+ let handle: SchedulerHandle = self.runtime.schedule(future);
+ Ok(handle.into_raw().into())
+ },
+ _ => Err(Fail::new(EBADF, "invalid queue descriptor")),
+ }
+ }
+
/// Pushes a scatter-gather array to a socket.
pub fn push(&mut self, qd: QDesc, sga: &dmtr_sgarray_t) -> Result<QToken, Fail> {
trace!("push() qd={:?}", qd);
@@ -239,19 +251,25 @@ impl CatnapLibOS {
}
// Issue push operation.
- match self.sockets.get(&qd) {
- Some(&fd) => {
- let future: Operation = Operation::from(PushFuture::new(qd, fd, buf));
- let handle: SchedulerHandle = self.runtime.schedule(future);
- Ok(handle.into_raw().into())
- },
- _ => Err(Fail::new(EBADF, "invalid queue descriptor")),
- }
+ self.do_push(qd, buf)
},
Err(e) => Err(e),
}
}
+ // Pushes raw data to a socket.
+ pub fn push2(&mut self, qd: QDesc, data: &[u8]) -> Result<QToken, Fail> {
+ trace!("push2() qd={:?}", qd);
+
+ let buf: Bytes = Bytes::from_slice(data);
+ if buf.len() == 0 {
+ return Err(Fail::new(EINVAL, "zero-length buffer"));
+ }
+
+ // Issue pushto operation.
+ self.do_push(qd, buf)
+ }
+
/// Handles a pushto operation.
fn do_pushto(&mut self, qd: QDesc, buf: Bytes, remote: Ipv4Endpoint) -> Result<QToken, Fail> {
match self.sockets.get(&qd) {
