This repository has been archived by the owner on Nov 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.cs
98 lines (90 loc) · 2.06 KB
/
socket.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
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
// Private: Create a new RedisClientSocket instance. The instance will use
// attributes from the given RedisClient.
//
// client - An instance of a RedisClient.
//
// Returns the new instance.
function RedisClientSocket(%client)
{
return new TCPObject(RedisClientSocket)
{
client = %client;
};
}
// Internal: Initialize a new RedisClientSocket.
//
// Returns nothing.
function RedisClientSocket::onAdd(%this)
{
%this.connected = 0;
%this.pendingDisconnect = 0;
}
// Public: Start connecting to the server indicated by the client properties.
// Nothing will happen if the client is already connected.
//
// Returns nothing.
function RedisClientSocket::connect(%this)
{
if (!%this.connected)
{
%this.pendingDisconnect = 0;
Parent::connect(%this, %this.client.host @ ":" @ %this.client.port);
}
}
// Public: Request a disconnect from the Redis server. An actual disconnect
// will be done once the callback queue is empty. No more commands can be
// issued after requesting a disconnect.
//
// Returns nothing.
function RedisClientSocket::disconnect(%this)
{
if (%this.client.callbacks.empty())
{
Parent::disconnect(%this);
%this.onDisconnect();
}
else
%this.pendingDisconnect = 1;
}
// Internal: Sends arbitrary data to the server or queues it if not connected.
//
// data - The data to send.
//
// Returns nothing.
function RedisClientSocket::send(%this, %data)
{
if (%this.connected)
Parent::send(%this, %data);
else
%this.queue = %this.queue @ %data;
}
// Internal: Handle a connection being established.
//
// Returns nothing.
function RedisClientSocket::onConnected(%this)
{
%this.connected = 1;
%this.pendingDisconnect = 0;
if (%this.queue !$= "")
{
%this.send(%this.queue);
%this.queue = "";
}
}
// Internal: Handle a disconnect.
//
// Returns nothing.
function RedisClientSocket::onDisconnect(%this)
{
%this.connected = 0;
%this.pendingDisconnect = 0;
}
// Internal: Send the incoming line to the RedisReplyParser.
//
// line - The received line.
//
// Returns nothing.
function RedisClientSocket::onLine(%this, %line)
{
%this.client.parser.onLine(%line);
}