Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
71418c9f
Commit
71418c9f
authored
Jul 09, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove ISocketCallback interface
This simplifies internal logistics and our profiling a bit
parent
18d14db3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
58 deletions
+23
-58
PhysicalBridge.cs
StackExchange.Redis/StackExchange/Redis/PhysicalBridge.cs
+1
-1
PhysicalConnection.cs
...kExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
+6
-6
SocketManager.cs
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
+16
-51
No files found.
StackExchange.Redis/StackExchange/Redis/PhysicalBridge.cs
View file @
71418c9f
...
...
@@ -401,7 +401,7 @@ internal void OnHeartbeat(bool ifConnectedOnly)
Interlocked
.
Exchange
(
ref
connectTimeoutRetryCount
,
0
);
tmp
.
Bridge
.
ServerEndPoint
.
ClearUnselectable
(
UnselectableFlags
.
DidNotRespond
);
}
tmp
.
OnHeartbeat
();
tmp
.
On
Bridge
Heartbeat
();
int
writeEverySeconds
=
ServerEndPoint
.
WriteEverySeconds
,
checkConfigSeconds
=
Multiplexer
.
RawConfig
.
ConfigCheckSeconds
;
...
...
StackExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
View file @
71418c9f
...
...
@@ -20,7 +20,7 @@
namespace
StackExchange.Redis
{
internal
sealed
partial
class
PhysicalConnection
:
IDisposable
,
ISocketCallback
internal
sealed
partial
class
PhysicalConnection
:
IDisposable
{
internal
readonly
byte
[]
ChannelPrefix
;
...
...
@@ -390,7 +390,7 @@ internal void GetStormLog(StringBuilder sb)
}
}
internal
void
OnHeartbeat
()
internal
void
On
Bridge
Heartbeat
()
{
Interlocked
.
Exchange
(
ref
lastBeatTickCount
,
Environment
.
TickCount
);
}
...
...
@@ -871,7 +871,7 @@ private static LocalCertificateSelectionCallback GetAmbientCertificateCallback()
return
null
;
}
async
ValueTask
<
SocketMode
>
ISocketCallback
.
ConnectedAsync
(
Socket
socket
,
TextWriter
log
,
SocketManager
manager
)
internal
async
ValueTask
<
SocketMode
>
ConnectedAsync
(
Socket
socket
,
TextWriter
log
,
SocketManager
manager
)
{
try
{
...
...
@@ -937,7 +937,7 @@ async ValueTask<SocketMode> ISocketCallback.ConnectedAsync(Socket socket, TextWr
}
}
void
ISocketCallback
.
Error
()
internal
void
Error
()
{
RecordConnectionFailed
(
ConnectionFailureType
.
SocketFailure
);
}
...
...
@@ -1016,7 +1016,7 @@ private void MatchResult(RawResult result)
partial
void
OnCreateEcho
();
partial
void
OnDebugAbort
();
void
ISocketCallback
.
OnHeartbeat
()
internal
void
OnHeartbeat
()
{
try
{
...
...
@@ -1202,7 +1202,7 @@ private RawResult ReadLineTerminatedString(ResultType type, in ReadOnlySequence<
return
new
RawResult
(
type
,
payload
,
false
);
}
void
ISocketCallback
.
StartReading
()
=>
ReadFromPipe
();
internal
void
StartReading
()
=>
ReadFromPipe
();
private
RawResult
TryParseResult
(
in
ReadOnlySequence
<
byte
>
buffer
,
ref
BufferReader
reader
)
{
...
...
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
View file @
71418c9f
...
...
@@ -15,40 +15,6 @@ internal enum SocketMode
Async
,
}
/// <summary>
/// Allows callbacks from SocketManager as work is discovered
/// </summary>
internal
partial
interface
ISocketCallback
{
/// <summary>
/// Indicates that a socket has connected
/// </summary>
/// <param name="socket">The socket.</param>
/// <param name="log">A text logger to write to.</param>
/// <param name="manager">The manager that will be owning this socket.</param>
ValueTask
<
SocketMode
>
ConnectedAsync
(
Socket
socket
,
TextWriter
log
,
SocketManager
manager
);
/// <summary>
/// Indicates that the socket has signalled an error condition
/// </summary>
void
Error
();
void
OnHeartbeat
();
///// <summary>
///// Indicates that data is available on the socket, and that the consumer should read synchronously from the socket while there is data
///// </summary>
//void Read();
/// <summary>
/// Indicates that we cannot know whether data is available, and that the consume should commence reading asynchronously
/// </summary>
void
StartReading
();
// check for write-read timeout
void
CheckForStaleConnection
(
ref
SocketManager
.
ManagerState
state
);
}
/// <summary>
/// A SocketManager monitors multiple sockets for availability of data; this is done using
/// the Socket.Select API and a dedicated reader-thread, which allows for fast responses
...
...
@@ -197,7 +163,7 @@ private void Dispose(bool disposing)
/// </summary>
~
SocketManager
()
=>
Dispose
(
false
);
internal
Socket
BeginConnect
(
EndPoint
endpoint
,
ISocketCallback
callback
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
)
internal
Socket
BeginConnect
(
EndPoint
endpoint
,
PhysicalConnection
callback
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
)
{
void
RunWithCompletionType
(
Func
<
AsyncCallback
,
IAsyncResult
>
beginAsync
,
AsyncCallback
asyncCallback
)
{
...
...
@@ -225,28 +191,27 @@ void proxyCallback(IAsyncResult ar)
try
{
var
formattedEndpoint
=
Format
.
ToString
(
endpoint
);
var
tuple
=
Tuple
.
Create
(
socket
,
callback
);
multiplexer
.
LogLocked
(
log
,
"BeginConnect: {0}"
,
formattedEndpoint
);
// A work-around for a Mono bug in BeginConnect(EndPoint endpoint, AsyncCallback callback, object state)
if
(
endpoint
is
DnsEndPoint
dnsEndpoint
)
{
RunWithCompletionType
(
cb
=>
socket
.
BeginConnect
(
dnsEndpoint
.
Host
,
dnsEndpoint
.
Port
,
cb
,
tuple
),
cb
=>
socket
.
BeginConnect
(
dnsEndpoint
.
Host
,
dnsEndpoint
.
Port
,
cb
,
null
),
ar
=>
{
multiplexer
.
LogLocked
(
log
,
"EndConnect: {0}"
,
formattedEndpoint
);
EndConnectImpl
(
ar
,
multiplexer
,
log
,
tuple
);
EndConnectImpl
(
ar
,
multiplexer
,
log
,
socket
,
callback
);
multiplexer
.
LogLocked
(
log
,
"Connect complete: {0}"
,
formattedEndpoint
);
});
}
else
{
RunWithCompletionType
(
cb
=>
socket
.
BeginConnect
(
endpoint
,
cb
,
tuple
),
cb
=>
socket
.
BeginConnect
(
endpoint
,
cb
,
null
),
ar
=>
{
multiplexer
.
LogLocked
(
log
,
"EndConnect: {0}"
,
formattedEndpoint
);
EndConnectImpl
(
ar
,
multiplexer
,
log
,
tuple
);
EndConnectImpl
(
ar
,
multiplexer
,
log
,
socket
,
callback
);
multiplexer
.
LogLocked
(
log
,
"Connect complete: {0}"
,
formattedEndpoint
);
});
}
...
...
@@ -261,24 +226,24 @@ void proxyCallback(IAsyncResult ar)
}
return
socket
;
}
private
async
void
EndConnectImpl
(
IAsyncResult
ar
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
,
Tuple
<
Socket
,
ISocketCallback
>
tuple
)
private
async
void
EndConnectImpl
(
IAsyncResult
ar
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
,
Socket
socket
,
PhysicalConnection
connection
)
{
var
socket
=
tuple
.
Item1
;
var
callback
=
tuple
.
Item2
;
try
{
bool
ignoreConnect
=
false
;
ShouldIgnoreConnect
(
tuple
.
Item2
,
ref
ignoreConnect
);
ShouldIgnoreConnect
(
connection
,
ref
ignoreConnect
);
if
(
ignoreConnect
)
return
;
socket
.
EndConnect
(
ar
);
var
socketMode
=
c
allback
==
null
?
SocketMode
.
Abort
:
await
callback
.
ConnectedAsync
(
socket
,
log
,
this
);
var
socketMode
=
c
onnection
==
null
?
SocketMode
.
Abort
:
await
connection
.
ConnectedAsync
(
socket
,
log
,
this
).
ForAwait
(
);
switch
(
socketMode
)
{
case
SocketMode
.
Async
:
multiplexer
.
LogLocked
(
log
,
"Starting read"
);
try
{
callback
.
StartReading
();
}
{
connection
.
StartReading
();
}
catch
(
Exception
ex
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
ex
.
Message
);
...
...
@@ -294,9 +259,9 @@ private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multipl
catch
(
ObjectDisposedException
)
{
multiplexer
.
LogLocked
(
log
,
"(socket shutdown)"
);
if
(
c
allback
!=
null
)
if
(
c
onnection
!=
null
)
{
try
{
c
allback
.
Error
();
}
try
{
c
onnection
.
Error
();
}
catch
(
Exception
inner
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
inner
.
Message
);
...
...
@@ -306,9 +271,9 @@ private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multipl
catch
(
Exception
outer
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
outer
.
Message
);
if
(
c
allback
!=
null
)
if
(
c
onnection
!=
null
)
{
try
{
c
allback
.
Error
();
}
try
{
c
onnection
.
Error
();
}
catch
(
Exception
inner
)
{
ConnectionMultiplexer
.
TraceWithoutContext
(
inner
.
Message
);
...
...
@@ -320,7 +285,7 @@ private async void EndConnectImpl(IAsyncResult ar, ConnectionMultiplexer multipl
partial
void
OnDispose
();
partial
void
OnShutdown
(
Socket
socket
);
partial
void
ShouldIgnoreConnect
(
ISocketCallback
callback
,
ref
bool
ignore
);
partial
void
ShouldIgnoreConnect
(
PhysicalConnection
callback
,
ref
bool
ignore
);
[
System
.
Diagnostics
.
CodeAnalysis
.
SuppressMessage
(
"Microsoft.Usage"
,
"CA2202:Do not dispose objects multiple times"
)]
internal
void
Shutdown
(
Socket
socket
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment