Pipe
struct Pipe
A synchronous in-memory pipe.
Implementions
Methods
[src]
pub fn read(self, buf: Bytes): int throws IoError {
while (self.buffers.is_empty()) {
do {
try self.wch.recv();
} catch(e: RecvError) {
return 0;
}
}
let is_full = self.buffer_size == self.max_buffer_size;
let filled = 0;
while (let b = self.buffers.first()) {
let unfilled = buf.len() - filled;
if (unfilled == 0) {
break;
}
buf.copy_from(b, offset: filled);
if (unfilled >= b.len()) {
filled += b.len();
self.buffers.pop_front();
} else {
filled += unfilled;
self.buffers[0] = b.slice(unfilled, b.len());
}
}
self.buffer_size -= filled;
if (is_full) {
do {
try self.rch.send(filled);
}
}
return filled;
}
[src]
pub fn read(self, buf: Bytes): int throws IoError {
while (self.buffers.is_empty()) {
do {
try self.wch.recv();
} catch(e: RecvError) {
return 0;
}
}
let is_full = self.buffer_size == self.max_buffer_size;
let filled = 0;
while (let b = self.buffers.first()) {
let unfilled = buf.len() - filled;
if (unfilled == 0) {
break;
}
buf.copy_from(b, offset: filled);
if (unfilled >= b.len()) {
filled += b.len();
self.buffers.pop_front();
} else {
filled += unfilled;
self.buffers[0] = b.slice(unfilled, b.len());
}
}
self.buffer_size -= filled;
if (is_full) {
do {
try self.rch.send(filled);
}
}
return filled;
}
[src]
pub fn write(self, buf: Bytes): int throws IoError {
if (self.wch.is_closed()) {
throw IoError.other("pipe is closed");
}
while (self.buffer_size >= self.max_buffer_size) {
do {
try self.rch.recv();
} catch(e: RecvError) {
throw IoError.other("pipe is closed");
}
}
let sz = buf.len().min(self.max_buffer_size - self.buffer_size);
let is_empty = self.buffers.is_empty();
self.buffers.push(buf.slice(0, sz));
self.buffer_size += sz;
if (is_empty) {
do {
try self.wch.send(sz);
} catch(e: SendError) {
throw IoError.other("pipe is closed");
}
}
return sz;
}
[src]
pub fn write(self, buf: Bytes): int throws IoError {
if (self.wch.is_closed()) {
throw IoError.other("pipe is closed");
}
while (self.buffer_size >= self.max_buffer_size) {
do {
try self.rch.recv();
} catch(e: RecvError) {
throw IoError.other("pipe is closed");
}
}
let sz = buf.len().min(self.max_buffer_size - self.buffer_size);
let is_empty = self.buffers.is_empty();
self.buffers.push(buf.slice(0, sz));
self.buffer_size += sz;
if (is_empty) {
do {
try self.wch.send(sz);
} catch(e: SendError) {
throw IoError.other("pipe is closed");
}
}
return sz;
}