Created
April 13, 2014 17:57
-
-
Save SiegeLord/10594804 to your computer and use it in GitHub Desktop.
Connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct Connection | |
| { | |
| active: *mut bool, | |
| payload: *mut c_void, | |
| callback: fn(*mut c_void), | |
| } | |
| impl Connection | |
| { | |
| pub fn new(payload: *mut c_void, callback: fn(*mut c_void)) -> (Connection, Connection) | |
| { | |
| let active = unsafe | |
| { | |
| cast::transmute(~true) | |
| }; | |
| (Connection{ active: active, payload: payload, callback: callback }, | |
| Connection{ active: active, payload: payload, callback: callback }) | |
| } | |
| } | |
| impl Drop for Connection | |
| { | |
| fn drop(&mut self) | |
| { | |
| if unsafe{ *self.active } | |
| { | |
| unsafe | |
| { | |
| *self.active = false; | |
| } | |
| (self.callback)(self.payload); | |
| } | |
| else | |
| { | |
| let _active: ~bool = unsafe { cast::transmute(self.active) }; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment