Convert pipes::Buffer into a struct
This commit is contained in:
parent
feab095d65
commit
5085eb3c28
@ -140,10 +140,19 @@ pub fn BufferHeader() -> BufferHeader{
|
||||
|
||||
// This is for protocols to associate extra data to thread around.
|
||||
#[doc(hidden)]
|
||||
#[cfg(stage0)]
|
||||
type Buffer<T: Owned> = {
|
||||
header: BufferHeader,
|
||||
data: T,
|
||||
};
|
||||
#[doc(hidden)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
pub struct Buffer<T: Owned> {
|
||||
header: BufferHeader,
|
||||
data: T,
|
||||
}
|
||||
|
||||
struct PacketHeader {
|
||||
mut state: State,
|
||||
@ -230,6 +239,7 @@ pub fn mk_packet<T: Owned>() -> Packet<T> {
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[cfg(stage0)]
|
||||
fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
|
||||
let b = ~{
|
||||
header: BufferHeader(),
|
||||
@ -245,6 +255,25 @@ fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
|
||||
move b
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn unibuffer<T: Owned>() -> ~Buffer<Packet<T>> {
|
||||
let b = ~Buffer {
|
||||
header: BufferHeader(),
|
||||
data: Packet {
|
||||
header: PacketHeader(),
|
||||
payload: None,
|
||||
}
|
||||
};
|
||||
|
||||
unsafe {
|
||||
b.data.header.buffer = reinterpret_cast(&b);
|
||||
}
|
||||
move b
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub fn packet<T: Owned>() -> *Packet<T> {
|
||||
let b = unibuffer();
|
||||
|
@ -357,10 +357,10 @@ fn gen_buffer_init(ext_cx: ext_ctxt) -> @ast::expr {
|
||||
fn gen_init_bounded(ext_cx: ext_ctxt) -> @ast::expr {
|
||||
debug!("gen_init_bounded");
|
||||
let buffer_fields = self.gen_buffer_init(ext_cx);
|
||||
let buffer = quote_expr!(
|
||||
~{header: ::pipes::BufferHeader(),
|
||||
data: $buffer_fields}
|
||||
);
|
||||
let buffer = quote_expr!(~::pipes::Buffer {
|
||||
header: ::pipes::BufferHeader(),
|
||||
data: $buffer_fields,
|
||||
});
|
||||
|
||||
let entangle_body = ext_cx.block_expr(
|
||||
ext_cx.block(
|
||||
|
@ -27,7 +27,7 @@ mod pingpong {
|
||||
};
|
||||
|
||||
pub fn init() -> (client::ping, server::ping) {
|
||||
let buffer = ~{
|
||||
let buffer = ~Buffer {
|
||||
header: BufferHeader(),
|
||||
data: {
|
||||
ping: mk_packet::<ping>(),
|
||||
|
Loading…
Reference in New Issue
Block a user