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
b81cba51
Commit
b81cba51
authored
Jul 10, 2018
by
Marc Gravell
Committed by
Nick Craver
Jul 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
somehow this didn't upload :/
parent
15ebc8ab
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
45 deletions
+37
-45
StackExchange.Redis.csproj
StackExchange.Redis/StackExchange.Redis.csproj
+1
-1
PhysicalConnection.cs
...kExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
+2
-1
SocketManager.cs
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
+33
-42
TestConsole.csproj
TestConsole/TestConsole.csproj
+1
-1
No files found.
StackExchange.Redis/StackExchange.Redis.csproj
View file @
b81cba51
...
...
@@ -23,7 +23,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.
58
" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.
62
" />
<PackageReference Include="System.Threading.Channels" Version="4.5.0" />
</ItemGroup>
</Project>
\ No newline at end of file
StackExchange.Redis/StackExchange/Redis/PhysicalConnection.cs
View file @
b81cba51
...
...
@@ -94,7 +94,8 @@ public void BeginConnect(TextWriter log)
var
endpoint
=
Bridge
.
ServerEndPoint
.
EndPoint
;
Multiplexer
.
Trace
(
"Connecting..."
,
physicalName
);
_socket
=
Multiplexer
.
SocketManager
.
BeginConnect
(
endpoint
,
this
,
Multiplexer
,
log
);
_socket
=
SocketManager
.
CreateSocket
(
endpoint
);
Multiplexer
.
SocketManager
.
BeginConnectAsync
(
endpoint
,
_socket
,
this
,
Multiplexer
,
log
);
}
private
enum
ReadMode
:
byte
...
...
StackExchange.Redis/StackExchange/Redis/SocketManager.cs
View file @
b81cba51
...
...
@@ -4,6 +4,7 @@
using
System.Net
;
using
System.Net.Sockets
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Pipelines.Sockets.Unofficial
;
namespace
StackExchange.Redis
...
...
@@ -127,58 +128,49 @@ private void Dispose(bool disposing)
/// </summary>
~
SocketManager
()
=>
Dispose
(
false
);
internal
Socket
BeginConnect
(
EndPoint
endpoint
,
PhysicalConnection
callback
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
)
internal
static
Socket
CreateSocket
(
EndPoint
endpoint
)
{
void
RunWithCompletionType
(
Func
<
AsyncCallback
,
IAsyncResult
>
beginAsync
,
AsyncCallback
asyncCallback
)
{
void
proxyCallback
(
IAsyncResult
ar
)
{
if
(!
ar
.
CompletedSynchronously
)
{
asyncCallback
(
ar
);
}
}
var
result
=
beginAsync
(
proxyCallback
);
if
(
result
.
CompletedSynchronously
)
{
result
.
AsyncWaitHandle
.
WaitOne
();
asyncCallback
(
result
);
}
}
var
addressFamily
=
endpoint
.
AddressFamily
==
AddressFamily
.
Unspecified
?
AddressFamily
.
InterNetwork
:
endpoint
.
AddressFamily
;
var
protocolType
=
addressFamily
==
AddressFamily
.
Unix
?
ProtocolType
.
Unspecified
:
ProtocolType
.
Tcp
;
var
socket
=
new
Socket
(
addressFamily
,
SocketType
.
Stream
,
protocolType
);
SocketConnection
.
SetRecommendedClientOptions
(
socket
);
return
socket
;
}
static
void
ConfigureTimeout
(
SocketAsyncEventArgs
args
,
int
timeoutMilliseconds
)
{
var
timeout
=
Task
.
Delay
(
timeoutMilliseconds
);
timeout
.
ContinueWith
((
t
,
state
)
=>
{
var
a
=
(
SocketAsyncEventArgs
)
state
;
try
{
Socket
.
CancelConnectAsync
(
a
);
}
catch
{
}
try
{
((
SocketAwaitable
)
a
.
UserToken
).
Complete
(
0
,
SocketError
.
TimedOut
);
}
catch
{
}
},
args
);
}
internal
void
BeginConnectAsync
(
EndPoint
endpoint
,
Socket
socket
,
PhysicalConnection
physicalConnection
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
)
{
var
formattedEndpoint
=
Format
.
ToString
(
endpoint
);
multiplexer
.
LogLocked
(
log
,
"BeginConnect: {0}"
,
formattedEndpoint
);
var
awaitable
=
new
SocketAwaitable
();
var
args
=
new
SocketAsyncEventArgs
();
args
.
UserToken
=
awaitable
;
args
.
RemoteEndPoint
=
endpoint
;
args
.
Completed
+=
SocketAwaitable
.
Callback
;
try
{
var
formattedEndpoint
=
Format
.
ToString
(
endpoint
);
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
)
if
(
socket
.
ConnectAsync
(
args
))
{
RunWithCompletionType
(
cb
=>
socket
.
BeginConnect
(
dnsEndpoint
.
Host
,
dnsEndpoint
.
Port
,
cb
,
null
),
ar
=>
{
multiplexer
.
LogLocked
(
log
,
"EndConnect: {0}"
,
formattedEndpoint
);
EndConnectImpl
(
ar
,
multiplexer
,
log
,
socket
,
callback
);
multiplexer
.
LogLocked
(
log
,
"Connect complete: {0}"
,
formattedEndpoint
);
});
ConfigureTimeout
(
args
,
multiplexer
.
RawConfig
.
ConnectTimeout
);
}
else
{
RunWithCompletionType
(
cb
=>
socket
.
BeginConnect
(
endpoint
,
cb
,
null
),
ar
=>
{
multiplexer
.
LogLocked
(
log
,
"EndConnect: {0}"
,
formattedEndpoint
);
EndConnectImpl
(
ar
,
multiplexer
,
log
,
socket
,
callback
);
multiplexer
.
LogLocked
(
log
,
"Connect complete: {0}"
,
formattedEndpoint
);
});
SocketAwaitable
.
OnCompleted
(
args
);
}
EndConnectAsync
(
awaitable
,
multiplexer
,
log
,
socket
,
physicalConnection
);
}
catch
(
NotImplementedException
ex
)
{
...
...
@@ -188,16 +180,15 @@ void proxyCallback(IAsyncResult ar)
}
throw
;
}
return
socket
;
}
private
async
void
EndConnect
Impl
(
IAsyncResult
ar
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
,
Socket
socket
,
PhysicalConnection
connection
)
private
async
void
EndConnect
Async
(
SocketAwaitable
awaitable
,
ConnectionMultiplexer
multiplexer
,
TextWriter
log
,
Socket
socket
,
PhysicalConnection
connection
)
{
try
{
bool
ignoreConnect
=
false
;
ShouldIgnoreConnect
(
connection
,
ref
ignoreConnect
);
if
(
ignoreConnect
)
return
;
socket
.
EndConnect
(
ar
)
;
await
awaitable
;
var
socketMode
=
connection
==
null
?
SocketMode
.
Abort
:
await
connection
.
ConnectedAsync
(
socket
,
log
,
this
).
ForAwait
();
switch
(
socketMode
)
...
...
TestConsole/TestConsole.csproj
View file @
b81cba51
...
...
@@ -14,7 +14,7 @@
<ProjectReference Include="..\StackExchange.Redis\StackExchange.Redis.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.
58
" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="0.2.1-alpha.
62
" />
</ItemGroup>
</Project>
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