Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
78cdde3b
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
78cdde3b
编写于
12月 25, 2015
作者:
J
Jared Parsons
提交者:
Jared Parsons
1月 18, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Server supports shutdown request
上级
9fece4e2
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
110 addition
and
42 deletion
+110
-42
src/Compilers/Core/CommandLine/BuildProtocol.cs
src/Compilers/Core/CommandLine/BuildProtocol.cs
+2
-2
src/Compilers/Server/ServerShared/Connection.cs
src/Compilers/Server/ServerShared/Connection.cs
+62
-31
src/Compilers/Server/ServerShared/ServerDispatcher.cs
src/Compilers/Server/ServerShared/ServerDispatcher.cs
+20
-5
src/Compilers/Server/VBCSCompilerTests/CompilerServerApiTest.cs
...mpilers/Server/VBCSCompilerTests/CompilerServerApiTest.cs
+0
-1
src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
...Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
+26
-3
未找到文件。
src/Compilers/Core/CommandLine/BuildProtocol.cs
浏览文件 @
78cdde3b
...
...
@@ -151,7 +151,7 @@ public static async Task<BuildRequest> ReadAsync(Stream inStream, CancellationTo
/// <summary>
/// Write a Request to the stream.
/// </summary>
public
async
Task
WriteAsync
(
Stream
outStream
,
CancellationToken
cancellationToken
)
public
async
Task
WriteAsync
(
Stream
outStream
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
)
)
{
using
(
var
memoryStream
=
new
MemoryStream
())
using
(
var
writer
=
new
BinaryWriter
(
memoryStream
,
Encoding
.
Unicode
))
...
...
@@ -305,7 +305,7 @@ public enum ResponseType
/// <param name="stream"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public
static
async
Task
<
BuildResponse
>
ReadAsync
(
Stream
stream
,
CancellationToken
cancellationToken
)
public
static
async
Task
<
BuildResponse
>
ReadAsync
(
Stream
stream
,
CancellationToken
cancellationToken
=
default
(
CancellationToken
)
)
{
Log
(
"Reading response length"
);
// Read the response length
...
...
src/Compilers/Server/ServerShared/Connection.cs
浏览文件 @
78cdde3b
...
...
@@ -2,6 +2,7 @@
using
Roslyn.Utilities
;
using
System
;
using
System.Diagnostics
;
using
System.Globalization
;
using
System.IO
;
using
System.Threading
;
...
...
@@ -45,6 +46,11 @@ internal enum CompletionReason
/// There was an unhandled exception processing the result.
/// </summary>
ClientException
,
/// <summary>
/// There was a request from the client to shutdown the server.
/// </summary>
ClientShutdownRequest
,
}
/// <summary>
...
...
@@ -100,42 +106,14 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
return
new
ConnectionData
(
CompletionReason
.
CompilationNotStarted
);
}
var
keepAlive
=
CheckForNewKeepAlive
(
request
);
// Kick off both the compilation and a task to monitor the pipe for closing.
var
buildCts
=
CancellationTokenSource
.
CreateLinkedTokenSource
(
cancellationToken
);
var
compilationTask
=
ServeBuildRequest
(
request
,
buildCts
.
Token
);
var
monitorTask
=
CreateMonitorDisconnectTask
(
buildCts
.
Token
);
await
Task
.
WhenAny
(
compilationTask
,
monitorTask
).
ConfigureAwait
(
false
);
// Do an 'await' on the completed task, preference being compilation, to force
// any exceptions to be realized in this method for logging.
CompletionReason
reason
;
if
(
compilationTask
.
IsCompleted
)
if
(
IsShutdownRequest
(
request
))
{
var
response
=
await
compilationTask
.
ConfigureAwait
(
false
);
try
{
Log
(
"Begin writing response."
);
await
response
.
WriteAsync
(
_stream
,
cancellationToken
).
ConfigureAwait
(
false
);
reason
=
CompletionReason
.
CompilationCompleted
;
Log
(
"End writing response."
);
}
catch
{
reason
=
CompletionReason
.
ClientDisconnect
;
}
return
await
HandleShutdownRequest
(
cancellationToken
).
ConfigureAwait
(
false
);
}
else
{
await
monitorTask
.
ConfigureAwait
(
false
);
reason
=
CompletionReason
.
ClientDisconnect
;
return
await
HandleCompilationRequest
(
request
,
cancellationToken
).
ConfigureAwait
(
false
);
}
// Begin the tear down of the Task which didn't complete.
buildCts
.
Cancel
();
return
new
ConnectionData
(
reason
,
keepAlive
);
}
finally
{
...
...
@@ -143,6 +121,54 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
}
}
private
async
Task
<
ConnectionData
>
HandleCompilationRequest
(
BuildRequest
request
,
CancellationToken
cancellationToken
)
{
var
keepAlive
=
CheckForNewKeepAlive
(
request
);
// Kick off both the compilation and a task to monitor the pipe for closing.
var
buildCts
=
CancellationTokenSource
.
CreateLinkedTokenSource
(
cancellationToken
);
var
compilationTask
=
ServeBuildRequest
(
request
,
buildCts
.
Token
);
var
monitorTask
=
CreateMonitorDisconnectTask
(
buildCts
.
Token
);
await
Task
.
WhenAny
(
compilationTask
,
monitorTask
).
ConfigureAwait
(
false
);
// Do an 'await' on the completed task, preference being compilation, to force
// any exceptions to be realized in this method for logging.
CompletionReason
reason
;
if
(
compilationTask
.
IsCompleted
)
{
var
response
=
await
compilationTask
.
ConfigureAwait
(
false
);
try
{
Log
(
"Begin writing response."
);
await
response
.
WriteAsync
(
_stream
,
cancellationToken
).
ConfigureAwait
(
false
);
reason
=
CompletionReason
.
CompilationCompleted
;
Log
(
"End writing response."
);
}
catch
{
reason
=
CompletionReason
.
ClientDisconnect
;
}
}
else
{
await
monitorTask
.
ConfigureAwait
(
false
);
reason
=
CompletionReason
.
ClientDisconnect
;
}
// Begin the tear down of the Task which didn't complete.
buildCts
.
Cancel
();
return
new
ConnectionData
(
reason
,
keepAlive
);
}
private
async
Task
<
ConnectionData
>
HandleShutdownRequest
(
CancellationToken
cancellationToken
)
{
var
id
=
Process
.
GetCurrentProcess
().
Id
;
var
response
=
new
ShutdownBuildResponse
(
id
);
await
response
.
WriteAsync
(
_stream
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
ConnectionData
(
CompletionReason
.
ClientShutdownRequest
);
}
/// <summary>
/// Check the request arguments for a new keep alive time. If one is present,
/// set the server timer to the new time.
...
...
@@ -169,6 +195,11 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
return
timeout
;
}
private
bool
IsShutdownRequest
(
BuildRequest
request
)
{
return
request
.
Arguments
.
Length
==
1
&&
request
.
Arguments
[
0
].
ArgumentId
==
BuildProtocolConstants
.
ArgumentId
.
Shutdown
;
}
protected
virtual
Task
<
BuildResponse
>
ServeBuildRequest
(
BuildRequest
request
,
CancellationToken
cancellationToken
)
{
return
Task
.
Run
(()
=>
...
...
src/Compilers/Server/ServerShared/ServerDispatcher.cs
浏览文件 @
78cdde3b
...
...
@@ -169,10 +169,10 @@ private void WaitForAnyCompletion(IEnumerable<Task<ConnectionData>> e, Task[] ot
/// <summary>
/// Checks the completed connection objects.
/// </summary>
/// <returns>
True if everything completed normally and false if there were any client disconnections.
</returns>
/// <returns>
False if the server needs to begin shutting down
</returns>
private
bool
CheckConnectionTask
(
List
<
Task
<
ConnectionData
>>
connectionList
,
ref
TimeSpan
?
keepAlive
,
ref
bool
isKeepAliveDefault
)
{
var
allFine
=
tru
e
;
var
shutdown
=
fals
e
;
var
processedCount
=
0
;
var
i
=
0
;
while
(
i
<
connectionList
.
Count
)
...
...
@@ -189,9 +189,24 @@ private bool CheckConnectionTask(List<Task<ConnectionData>> connectionList, ref
var
connectionData
=
current
.
Result
;
ChangeKeepAlive
(
connectionData
.
KeepAlive
,
ref
keepAlive
,
ref
isKeepAliveDefault
);
if
(
connectionData
.
CompletionReason
==
CompletionReason
.
ClientDisconnect
||
connectionData
.
CompletionReason
==
CompletionReason
.
ClientException
)
switch
(
connectionData
.
CompletionReason
)
{
allFine
=
false
;
case
CompletionReason
.
CompilationCompleted
:
case
CompletionReason
.
CompilationNotStarted
:
// These are all normal shutdown states. Nothing to do here.
break
;
case
CompletionReason
.
ClientDisconnect
:
// Have to assume the worst here which is user pressing Ctrl+C at the command line and
// hence wanting all compilation to end.
shutdown
=
true
;
break
;
case
CompletionReason
.
ClientException
:
case
CompletionReason
.
ClientShutdownRequest
:
shutdown
=
true
;
break
;
default
:
throw
new
InvalidOperationException
(
$"Unexpected enum value
{
connectionData
.
CompletionReason
}
"
);
}
}
...
...
@@ -200,7 +215,7 @@ private bool CheckConnectionTask(List<Task<ConnectionData>> connectionList, ref
_diagnosticListener
.
ConnectionCompleted
(
processedCount
);
}
return
allFine
;
return
!
shutdown
;
}
private
void
ChangeKeepAlive
(
TimeSpan
?
value
,
ref
TimeSpan
?
keepAlive
,
ref
bool
isKeepAliveDefault
)
...
...
src/Compilers/Server/VBCSCompilerTests/CompilerServerApiTest.cs
浏览文件 @
78cdde3b
...
...
@@ -249,7 +249,6 @@ public async Task KeepAliveAfterSimultaneousConnection()
dispatcher
.
ListenAndDispatchConnections
(
keepAlive
);
});
await
readySource
.
Task
.
ConfigureAwait
(
true
);
foreach
(
var
source
in
list
)
{
...
...
src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
浏览文件 @
78cdde3b
...
...
@@ -6,6 +6,7 @@
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO.Pipes
;
using
System.Linq
;
using
System.Reflection
;
using
System.Runtime.InteropServices
;
...
...
@@ -1359,7 +1360,7 @@ public async Task ServerRespectsAppConfig()
var
exited
=
proc
.
HasExited
;
if
(!
exited
)
{
proc
.
Kill
(
);
Kill
(
proc
);
Assert
.
True
(
false
,
"Compiler server did not exit in time"
);
}
}
...
...
@@ -1408,7 +1409,28 @@ public void BadKeepAlive4()
Assert
.
Equal
(
""
,
result
.
Errors
);
}
[
Fact
,
WorkItem
(
1024619
,
"DevDiv"
)]
[
Fact
]
public
async
Task
ShutdownRequestDirect
()
{
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
using
(
var
client
=
new
NamedPipeClientStream
(
serverData
.
PipeName
))
{
await
client
.
ConnectAsync
();
var
memoryStream
=
new
MemoryStream
();
await
BuildRequest
.
CreateShutdown
().
WriteAsync
(
memoryStream
);
memoryStream
.
Position
=
0
;
await
memoryStream
.
CopyToAsync
(
client
);
var
response
=
await
BuildResponse
.
ReadAsync
(
client
);
Assert
.
Equal
(
BuildResponse
.
ResponseType
.
Shutdown
,
response
.
Type
);
Assert
.
Equal
(
Process
.
GetCurrentProcess
().
Id
,
((
ShutdownBuildResponse
)
response
).
ServerProcessId
);
await
Verify
(
serverData
,
connections
:
1
,
completed
:
1
);
}
}
[
Fact
]
[
WorkItem
(
1024619
,
"DevDiv"
)]
public
async
Task
Bug1024619_01
()
{
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
...
...
@@ -1440,7 +1462,8 @@ public async Task Bug1024619_01()
}
}
[
Fact
,
WorkItem
(
1024619
,
"DevDiv"
)]
[
Fact
]
[
WorkItem
(
1024619
,
"DevDiv"
)]
public
async
Task
Bug1024619_02
()
{
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录