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
...
@@ -151,7 +151,7 @@ public static async Task<BuildRequest> ReadAsync(Stream inStream, CancellationTo
/// <summary>
/// <summary>
/// Write a Request to the stream.
/// Write a Request to the stream.
/// </summary>
/// </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
memoryStream
=
new
MemoryStream
())
using
(
var
writer
=
new
BinaryWriter
(
memoryStream
,
Encoding
.
Unicode
))
using
(
var
writer
=
new
BinaryWriter
(
memoryStream
,
Encoding
.
Unicode
))
...
@@ -305,7 +305,7 @@ public enum ResponseType
...
@@ -305,7 +305,7 @@ public enum ResponseType
/// <param name="stream"></param>
/// <param name="stream"></param>
/// <param name="cancellationToken"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <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"
);
Log
(
"Reading response length"
);
// Read the response length
// Read the response length
...
...
src/Compilers/Server/ServerShared/Connection.cs
浏览文件 @
78cdde3b
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
using
Roslyn.Utilities
;
using
Roslyn.Utilities
;
using
System
;
using
System
;
using
System.Diagnostics
;
using
System.Globalization
;
using
System.Globalization
;
using
System.IO
;
using
System.IO
;
using
System.Threading
;
using
System.Threading
;
...
@@ -45,6 +46,11 @@ internal enum CompletionReason
...
@@ -45,6 +46,11 @@ internal enum CompletionReason
/// There was an unhandled exception processing the result.
/// There was an unhandled exception processing the result.
/// </summary>
/// </summary>
ClientException
,
ClientException
,
/// <summary>
/// There was a request from the client to shutdown the server.
/// </summary>
ClientShutdownRequest
,
}
}
/// <summary>
/// <summary>
...
@@ -100,6 +106,23 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
...
@@ -100,6 +106,23 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
return
new
ConnectionData
(
CompletionReason
.
CompilationNotStarted
);
return
new
ConnectionData
(
CompletionReason
.
CompilationNotStarted
);
}
}
if
(
IsShutdownRequest
(
request
))
{
return
await
HandleShutdownRequest
(
cancellationToken
).
ConfigureAwait
(
false
);
}
else
{
return
await
HandleCompilationRequest
(
request
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
finally
{
Close
();
}
}
private
async
Task
<
ConnectionData
>
HandleCompilationRequest
(
BuildRequest
request
,
CancellationToken
cancellationToken
)
{
var
keepAlive
=
CheckForNewKeepAlive
(
request
);
var
keepAlive
=
CheckForNewKeepAlive
(
request
);
// Kick off both the compilation and a task to monitor the pipe for closing.
// Kick off both the compilation and a task to monitor the pipe for closing.
...
@@ -137,10 +160,13 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
...
@@ -137,10 +160,13 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
buildCts
.
Cancel
();
buildCts
.
Cancel
();
return
new
ConnectionData
(
reason
,
keepAlive
);
return
new
ConnectionData
(
reason
,
keepAlive
);
}
}
finally
private
async
Task
<
ConnectionData
>
HandleShutdownRequest
(
CancellationToken
cancellationToken
)
{
{
Close
();
var
id
=
Process
.
GetCurrentProcess
().
Id
;
}
var
response
=
new
ShutdownBuildResponse
(
id
);
await
response
.
WriteAsync
(
_stream
,
cancellationToken
).
ConfigureAwait
(
false
);
return
new
ConnectionData
(
CompletionReason
.
ClientShutdownRequest
);
}
}
/// <summary>
/// <summary>
...
@@ -169,6 +195,11 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
...
@@ -169,6 +195,11 @@ public async Task<ConnectionData> HandleConnection(CancellationToken cancellatio
return
timeout
;
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
)
protected
virtual
Task
<
BuildResponse
>
ServeBuildRequest
(
BuildRequest
request
,
CancellationToken
cancellationToken
)
{
{
return
Task
.
Run
(()
=>
return
Task
.
Run
(()
=>
...
...
src/Compilers/Server/ServerShared/ServerDispatcher.cs
浏览文件 @
78cdde3b
...
@@ -169,10 +169,10 @@ private void WaitForAnyCompletion(IEnumerable<Task<ConnectionData>> e, Task[] ot
...
@@ -169,10 +169,10 @@ private void WaitForAnyCompletion(IEnumerable<Task<ConnectionData>> e, Task[] ot
/// <summary>
/// <summary>
/// Checks the completed connection objects.
/// Checks the completed connection objects.
/// </summary>
/// </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
)
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
processedCount
=
0
;
var
i
=
0
;
var
i
=
0
;
while
(
i
<
connectionList
.
Count
)
while
(
i
<
connectionList
.
Count
)
...
@@ -189,9 +189,24 @@ private bool CheckConnectionTask(List<Task<ConnectionData>> connectionList, ref
...
@@ -189,9 +189,24 @@ private bool CheckConnectionTask(List<Task<ConnectionData>> connectionList, ref
var
connectionData
=
current
.
Result
;
var
connectionData
=
current
.
Result
;
ChangeKeepAlive
(
connectionData
.
KeepAlive
,
ref
keepAlive
,
ref
isKeepAliveDefault
);
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
...
@@ -200,7 +215,7 @@ private bool CheckConnectionTask(List<Task<ConnectionData>> connectionList, ref
_diagnosticListener
.
ConnectionCompleted
(
processedCount
);
_diagnosticListener
.
ConnectionCompleted
(
processedCount
);
}
}
return
allFine
;
return
!
shutdown
;
}
}
private
void
ChangeKeepAlive
(
TimeSpan
?
value
,
ref
TimeSpan
?
keepAlive
,
ref
bool
isKeepAliveDefault
)
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()
...
@@ -249,7 +249,6 @@ public async Task KeepAliveAfterSimultaneousConnection()
dispatcher
.
ListenAndDispatchConnections
(
keepAlive
);
dispatcher
.
ListenAndDispatchConnections
(
keepAlive
);
});
});
await
readySource
.
Task
.
ConfigureAwait
(
true
);
await
readySource
.
Task
.
ConfigureAwait
(
true
);
foreach
(
var
source
in
list
)
foreach
(
var
source
in
list
)
{
{
...
...
src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
浏览文件 @
78cdde3b
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.IO
;
using
System.IO
;
using
System.IO.Pipes
;
using
System.Linq
;
using
System.Linq
;
using
System.Reflection
;
using
System.Reflection
;
using
System.Runtime.InteropServices
;
using
System.Runtime.InteropServices
;
...
@@ -1359,7 +1360,7 @@ public async Task ServerRespectsAppConfig()
...
@@ -1359,7 +1360,7 @@ public async Task ServerRespectsAppConfig()
var
exited
=
proc
.
HasExited
;
var
exited
=
proc
.
HasExited
;
if
(!
exited
)
if
(!
exited
)
{
{
proc
.
Kill
(
);
Kill
(
proc
);
Assert
.
True
(
false
,
"Compiler server did not exit in time"
);
Assert
.
True
(
false
,
"Compiler server did not exit in time"
);
}
}
}
}
...
@@ -1408,7 +1409,28 @@ public void BadKeepAlive4()
...
@@ -1408,7 +1409,28 @@ public void BadKeepAlive4()
Assert
.
Equal
(
""
,
result
.
Errors
);
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
()
public
async
Task
Bug1024619_01
()
{
{
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
...
@@ -1440,7 +1462,8 @@ public async Task Bug1024619_01()
...
@@ -1440,7 +1462,8 @@ public async Task Bug1024619_01()
}
}
}
}
[
Fact
,
WorkItem
(
1024619
,
"DevDiv"
)]
[
Fact
]
[
WorkItem
(
1024619
,
"DevDiv"
)]
public
async
Task
Bug1024619_02
()
public
async
Task
Bug1024619_02
()
{
{
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
using
(
var
serverData
=
ServerUtil
.
CreateServer
())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录