forked from zeromq/clrzmq4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZPollItem.cs
69 lines (54 loc) · 1.63 KB
/
ZPollItem.cs
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
namespace ZeroMQ
{
using System;
using System.Threading;
public class ZPollItem
{
public ZPoll Events;
public ZPoll ReadyEvents;
public delegate bool ReceiveDelegate(ZSocket socket, out ZMessage message, out ZError error);
public ReceiveDelegate ReceiveMessage;
public static bool DefaultReceiveMessage(ZSocket socket, out ZMessage message, out ZError error)
{
message = null;
return socket.ReceiveMessage(ref message, out error);
}
public delegate bool SendDelegate(ZSocket socket, ZMessage message, out ZError error);
public SendDelegate SendMessage;
public static bool DefaultSendMessage(ZSocket socket, ZMessage message, out ZError error)
{
return socket.Send(message, out error);
}
protected ZPollItem(ZPoll events)
{
Events = events;
}
public static ZPollItem Create(ReceiveDelegate receiveMessage)
{
return Create(receiveMessage, null);
}
public static ZPollItem CreateSender(SendDelegate sendMessage)
{
return Create(null, sendMessage);
}
public static ZPollItem Create(ReceiveDelegate receiveMessage, SendDelegate sendMessage)
{
var pollItem = new ZPollItem((receiveMessage != null ? ZPoll.In : ZPoll.None) | (sendMessage != null ? ZPoll.Out : ZPoll.None));
pollItem.ReceiveMessage = receiveMessage;
pollItem.SendMessage = sendMessage;
return pollItem;
}
public static ZPollItem CreateReceiver()
{
return Create(DefaultReceiveMessage, null);
}
public static ZPollItem CreateSender()
{
return Create(null, DefaultSendMessage);
}
public static ZPollItem CreateReceiverSender()
{
return Create(DefaultReceiveMessage, DefaultSendMessage);
}
}
}