Skip to content

Make inline(never) attributes more idiomatic #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ pub struct NanoSocket {
impl NanoSocket {

// example: let sock = NanoSocket::new(AF_SP, NN_PAIR);
#[inline(never)]
pub fn new(domain: c_int, protocol: c_int) -> Result<NanoSocket, NanoErr> {
#![inline(never)]

let rc: c_int = unsafe { nn_socket(domain, protocol) };
if rc < 0 {
Expand All @@ -219,8 +219,8 @@ impl NanoSocket {
}

// connect
#[inline(never)]
pub fn connect(&self, addr: &str) -> Result<(), NanoErr> {
#![inline(never)]

let addr_c = addr.to_c_str();
let rc: c_int = addr_c.with_ref(|a| unsafe { nn_connect(self.sock, a) });
Expand All @@ -235,8 +235,8 @@ impl NanoSocket {
}

// bind (listen)
#[inline(never)]
pub fn bind(&self, addr: &str) -> Result<(), NanoErr>{
#![inline(never)]

// bind
let addr_c = addr.to_c_str();
Expand All @@ -248,8 +248,8 @@ impl NanoSocket {
}

// subscribe, with prefix-filter
#[inline(never)]
pub fn subscribe(&self, prefix: &[u8]) -> Result<(), NanoErr>{
#![inline(never)]

unsafe {
let rc : c_int = nn_setsockopt(self.sock,
Expand All @@ -269,8 +269,8 @@ impl NanoSocket {
}
*/
// send
#[inline(never)]
pub fn send(&self, buf: &[u8]) -> Result<(), NanoErr> {
#![inline(never)]

let len : i64 = buf.len() as i64;
if 0 == len { return Ok(()); }
Expand All @@ -285,8 +285,8 @@ impl NanoSocket {


// send a string
#[inline(never)]
pub fn sendstr(&self, b: &str) -> Result<(), NanoErr> {
#![inline(never)]

let len : i64 = b.len() as i64;
if 0 == len { return Ok(()); }
Expand All @@ -302,8 +302,8 @@ impl NanoSocket {


// buffer receive
#[inline(never)]
pub fn recv(&self) -> Result<~[u8], NanoErr> {
#![inline(never)]

unsafe {
let mut mem : *mut u8 = ptr::mut_null();
Expand Down Expand Up @@ -347,8 +347,8 @@ struct NanoMsgReader {
}

impl std::io::Reader for NanoSocket {
#[inline(never)]
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
#![inline(never)]

match self.recv() {
Err(e) => {
Expand Down Expand Up @@ -386,8 +386,8 @@ impl std::io::Writer for NanoSocket {

#[unsafe_destructor]
impl Drop for NanoSocket {
#[inline(never)]
fn drop(&mut self) {
#![inline(never)]

// close
let rc = unsafe { nn_close (self.sock) };
Expand Down Expand Up @@ -461,8 +461,8 @@ impl NanoMsg {
}

/// recv_any_size allows nanomsg to do zero-copy optimizations
#[inline(never)]
pub fn recv_any_size(&mut self, sock: c_int, flags: c_int) -> Result<u64, NanoErr>{
#![inline(never)]

match self.cleanup {
DoNothing => (),
Expand All @@ -487,8 +487,8 @@ impl NanoMsg {

/// Use recv_no_more_than_maxlen() if we need our own copy anyway, but don't want to overflow our
/// heap. The function will truncate any part of the message over maxlen. In general, prefer recv_any_size() above.
#[inline(never)]
pub fn recv_no_more_than_maxlen(&mut self, sock: c_int, maxlen: u64, flags: c_int) -> Result<u64, NanoErr> {
#![inline(never)]

match self.cleanup {
DoNothing => (),
Expand Down Expand Up @@ -527,8 +527,8 @@ impl NanoMsg {
unsafe { std::str::raw::from_buf_len(self.buf as *u8, self.bytes_stored_in_buf as uint) }
}

#[inline(never)]
pub fn cleanup(&self) {
#![inline(never)]

if self.buf.is_null() { return; }

Expand Down Expand Up @@ -565,8 +565,8 @@ impl NanoMsg {

#[unsafe_destructor]
impl Drop for NanoMsg {
#[inline(never)]
fn drop(&mut self) {
#![inline(never)]
// println!("starting Drop for NanoMsg, with style: {:?}", self.cleanup);
self.cleanup();
}
Expand Down