Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
634ebecb
V
vscode
项目概览
xxadev
/
vscode
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vscode
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
634ebecb
编写于
1月 14, 2021
作者:
A
Alexandru Dima
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor code to use `await`
上级
d6f27b92
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
76 addition
and
59 deletion
+76
-59
src/vs/platform/remote/common/remoteAgentConnection.ts
src/vs/platform/remote/common/remoteAgentConnection.ts
+76
-59
未找到文件。
src/vs/platform/remote/common/remoteAgentConnection.ts
浏览文件 @
634ebecb
...
...
@@ -8,7 +8,7 @@ import { generateUuid } from 'vs/base/common/uuid';
import
{
RemoteAgentConnectionContext
}
from
'
vs/platform/remote/common/remoteAgentEnvironment
'
;
import
{
Disposable
}
from
'
vs/base/common/lifecycle
'
;
import
{
VSBuffer
}
from
'
vs/base/common/buffer
'
;
import
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
Emitter
,
Event
}
from
'
vs/base/common/event
'
;
import
{
RemoteAuthorityResolverError
}
from
'
vs/platform/remote/common/remoteAuthorityResolver
'
;
import
{
isPromiseCanceledError
,
onUnexpectedError
}
from
'
vs/base/common/errors
'
;
import
{
ISignService
}
from
'
vs/platform/sign/common/sign
'
;
...
...
@@ -86,6 +86,38 @@ export interface ISocketFactory {
connect
(
host
:
string
,
port
:
number
,
query
:
string
,
callback
:
IConnectCallback
):
void
;
}
async
function
readOneControlMessage
<
T
>
(
protocol
:
PersistentProtocol
):
Promise
<
T
>
{
const
raw
=
await
Event
.
toPromise
(
protocol
.
onControlMessage
);
const
msg
=
JSON
.
parse
(
raw
.
toString
());
const
error
=
getErrorFromMessage
(
msg
);
if
(
error
)
{
throw
error
;
}
return
msg
;
}
function
waitWithTimeout
<
T
>
(
promise
:
Promise
<
T
>
,
timeout
:
number
):
Promise
<
T
>
{
return
new
Promise
<
T
>
((
resolve
,
reject
)
=>
{
const
timeoutToken
=
setTimeout
(()
=>
{
const
error
:
any
=
new
Error
(
'
Timeout
'
);
error
.
code
=
'
ETIMEDOUT
'
;
error
.
syscall
=
'
connect
'
;
reject
(
error
);
},
timeout
);
promise
.
then
(
(
result
)
=>
{
clearTimeout
(
timeoutToken
);
resolve
(
result
);
},
(
error
)
=>
{
clearTimeout
(
timeoutToken
);
reject
(
error
);
}
);
});
}
async
function
connectToRemoteExtensionHostAgent
(
options
:
ISimpleConnectionOptions
,
connectionType
:
ConnectionType
,
args
:
any
|
undefined
):
Promise
<
{
protocol
:
PersistentProtocol
;
ownsProtocol
:
boolean
;
}
>
{
const
logPrefix
=
connectLogPrefix
(
options
,
connectionType
);
const
{
protocol
,
ownsProtocol
}
=
await
new
Promise
<
{
protocol
:
PersistentProtocol
;
ownsProtocol
:
boolean
;
}
>
((
c
,
e
)
=>
{
...
...
@@ -113,69 +145,54 @@ async function connectToRemoteExtensionHostAgent(options: ISimpleConnectionOptio
);
});
return
new
Promise
<
{
protocol
:
PersistentProtocol
;
ownsProtocol
:
boolean
;
}
>
((
c
,
e
)
=>
{
const
errorTimeoutToken
=
setTimeout
(()
=>
{
const
error
:
any
=
new
Error
(
'
handshake timeout
'
);
error
.
code
=
'
ETIMEDOUT
'
;
error
.
syscall
=
'
connect
'
;
options
.
logService
.
error
(
`
${
logPrefix
}
the handshake took longer than 10 seconds. Error:`
);
options
.
logService
.
error
(
error
);
if
(
ownsProtocol
)
{
safeDisposeProtocolAndSocket
(
protocol
);
}
e
(
error
);
},
10000
);
options
.
logService
.
trace
(
`
${
logPrefix
}
3/6. sending AuthRequest control message.`
);
const
authRequest
:
AuthRequest
=
{
type
:
'
auth
'
,
auth
:
options
.
connectionToken
||
'
00000000000000000000
'
};
protocol
.
sendControl
(
VSBuffer
.
fromString
(
JSON
.
stringify
(
authRequest
)));
const
messageRegistration
=
protocol
.
onControlMessage
(
async
raw
=>
{
const
msg
=
<
HandshakeMessage
>
JSON
.
parse
(
raw
.
toString
());
// Stop listening for further events
messageRegistration
.
dispose
();
try
{
const
msg
=
await
waitWithTimeout
(
readOneControlMessage
<
HandshakeMessage
>
(
protocol
),
10000
);
const
error
=
getErrorFromMessage
(
msg
);
if
(
error
)
{
options
.
logService
.
error
(
`
${
logPrefix
}
received error control message when negotiating connection. Error:`
);
options
.
logService
.
error
(
error
);
if
(
ownsProtocol
)
{
safeDisposeProtocolAndSocket
(
protocol
);
}
return
e
(
error
);
}
if
(
msg
.
type
!==
'
sign
'
||
typeof
msg
.
data
!==
'
string
'
)
{
const
error
:
any
=
new
Error
(
'
Unexpected handshake message
'
);
error
.
code
=
'
VSCODE_CONNECTION_ERROR
'
;
throw
error
;
}
if
(
msg
.
type
===
'
sign
'
)
{
options
.
logService
.
trace
(
`
${
logPrefix
}
4/6. received SignRequest control message.`
);
const
signed
=
await
options
.
signService
.
sign
(
msg
.
data
);
const
connTypeRequest
:
ConnectionTypeRequest
=
{
type
:
'
connectionType
'
,
commit
:
options
.
commit
,
signedData
:
signed
,
desiredConnectionType
:
connectionType
};
if
(
args
)
{
connTypeRequest
.
args
=
args
;
}
options
.
logService
.
trace
(
`
${
logPrefix
}
5/6. sending ConnectionTypeRequest control message.`
);
protocol
.
sendControl
(
VSBuffer
.
fromString
(
JSON
.
stringify
(
connTypeRequest
)));
clearTimeout
(
errorTimeoutToken
);
c
({
protocol
,
ownsProtocol
});
}
else
{
const
error
=
new
Error
(
'
handshake error
'
);
options
.
logService
.
error
(
`
${
logPrefix
}
received unexpected control message. Error:`
);
options
.
logService
.
error
(
error
);
if
(
ownsProtocol
)
{
safeDisposeProtocolAndSocket
(
protocol
);
}
e
(
error
);
}
});
options
.
logService
.
trace
(
`
${
logPrefix
}
4/6. received SignRequest control message.`
);
options
.
logService
.
trace
(
`
${
logPrefix
}
3/6. sending AuthRequest control message.`
);
const
authRequest
:
AuthRequest
=
{
type
:
'
auth
'
,
auth
:
options
.
connectionToken
||
'
00000000000000000000
'
const
signed
=
await
options
.
signService
.
sign
(
msg
.
data
);
const
connTypeRequest
:
ConnectionTypeRequest
=
{
type
:
'
connectionType
'
,
commit
:
options
.
commit
,
signedData
:
signed
,
desiredConnectionType
:
connectionType
};
protocol
.
sendControl
(
VSBuffer
.
fromString
(
JSON
.
stringify
(
authRequest
)));
});
if
(
args
)
{
connTypeRequest
.
args
=
args
;
}
options
.
logService
.
trace
(
`
${
logPrefix
}
5/6. sending ConnectionTypeRequest control message.`
);
protocol
.
sendControl
(
VSBuffer
.
fromString
(
JSON
.
stringify
(
connTypeRequest
)));
return
{
protocol
,
ownsProtocol
};
}
catch
(
error
)
{
if
(
error
&&
error
.
code
===
'
ETIMEDOUT
'
)
{
options
.
logService
.
error
(
`
${
logPrefix
}
the handshake took longer than 10 seconds. Error:`
);
options
.
logService
.
error
(
error
);
}
if
(
error
&&
error
.
code
===
'
VSCODE_CONNECTION_ERROR
'
)
{
options
.
logService
.
error
(
`
${
logPrefix
}
received error control message when negotiating connection. Error:`
);
options
.
logService
.
error
(
error
);
}
if
(
ownsProtocol
)
{
safeDisposeProtocolAndSocket
(
protocol
);
}
throw
error
;
}
}
interface
IManagementConnectionResult
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录