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
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 * This file is part of Futures ZMQ.
 *
 * Copyright © 2018 Riley Trautman
 *
 * Futures ZMQ is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Futures ZMQ is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Futures ZMQ.  If not, see <http://www.gnu.org/licenses/>.
 */

//! This module defines all the socket wrapper types that can be used with futures.

use async_zmq_derive::SocketWrapper;
use zmq::SocketType::{self, DEALER, PAIR, PUB, PULL, PUSH, REP, REQ, ROUTER, SUB, XPUB, XSUB};

use crate::{
    polling::{LocalSession, SockId},
    socket::Socket,
};

// needed for derive
type RawSocket = (SockId, LocalSession);

/* -------------------------------------------------------------------------- */

/// The DEALER `SocketType` wrapper type.
///
/// Dealer implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Dealer {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The PAIR `SocketType` wrapper type.
///
/// Pair implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Pair {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The PUB `SocketType` wrapper type
///
/// Pub implements `SinkSocket`.
#[derive(Debug, SocketWrapper)]
#[sink]
pub struct Pub {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The PULL `SocketType` wrapper type
///
/// Pull implements `StreamSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
pub struct Pull {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The PUSH `SocketType` wrapper type
///
/// Push implements `SinkSocket`.
#[derive(Debug, SocketWrapper)]
#[sink]
pub struct Push {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The REP `SocketType` wrapper type
///
/// Rep implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Rep {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The REQ `SocketType` wrapper type
///
/// Req implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Req {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The ROUTER `SocketType` wrapper type
///
/// Router implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Router {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The SUB `SocketType` wrapper type
///
/// Sub implements `StreamSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
pub struct Sub {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The XPUB `SocketType` wrapper type
///
/// Xpub implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Xpub {
    pub(crate) inner: Socket,
}

/* -------------------------------------------------------------------------- */

/// The XSUB `SocketType` wrapper type
///
/// Xsub implements `StreamSocket` and `SinkSocket`, and has an associated controlled variant.
#[derive(Debug, SocketWrapper)]
#[stream]
#[sink]
pub struct Xsub {
    pub(crate) inner: Socket,
}