forked from zeromq/zmq.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctx.rs
50 lines (43 loc) · 1.48 KB
/
ctx.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use consts::SocketType;
use inproc::InprocManager;
use rep;
use req;
use socket::ZmqSocket;
use socket_base::SocketBase;
/// Before using any ØMQ code you must create a ØMQ *context*.
pub struct Context {
inproc_mgr: InprocManager,
}
impl Context {
/// Create a new ØMQ context.
pub fn new() -> Context {
Context {
inproc_mgr: InprocManager::new(),
}
}
/// This function shall create a ØMQ socket within the specified *context* and return a box of
/// the newly created socket. The *type_* argument specifies the socket type, which determines
/// the semantics of communication over the socket.
///
/// The newly created socket is initially unbound, and not associated with any endpoints.
/// In order to establish a message flow a socket must first be connected to at least one
/// endpoint with [`connect`](trait.ZmqSocket.html#tymethod.connect), or at least one endpoint
/// must be created for accepting incoming connections with
/// [`bind`](trait.ZmqSocket.html#tymethod.bind).
///
pub fn socket(&self, type_: SocketType) -> Box<ZmqSocket + Send> {
let base = SocketBase::new(self.inproc_mgr.chan());
match type_ {
SocketType::REQ => box req::new(base) as Box<ZmqSocket + Send>,
SocketType::REP => box rep::new(base) as Box<ZmqSocket + Send>,
}
}
}
#[cfg(test)]
mod test {
use ctx::Context;
#[test]
fn test_new() {
Context::new();
}
}