Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
xxadev
vscode
提交
5e6580aa
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,发现更多精彩内容 >>
提交
5e6580aa
编写于
9月 21, 2016
作者:
J
Joao Moreno
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
💄
ipc
上级
787b9c64
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
63 addition
and
63 deletion
+63
-63
src/vs/base/parts/ipc/common/ipc.electron.ts
src/vs/base/parts/ipc/common/ipc.electron.ts
+3
-3
src/vs/base/parts/ipc/common/ipc.ts
src/vs/base/parts/ipc/common/ipc.ts
+12
-4
src/vs/base/parts/ipc/node/ipc.cp.ts
src/vs/base/parts/ipc/node/ipc.cp.ts
+2
-2
src/vs/base/parts/ipc/node/ipc.net.ts
src/vs/base/parts/ipc/node/ipc.net.ts
+46
-54
未找到文件。
src/vs/base/parts/ipc/common/ipc.electron.ts
浏览文件 @
5e6580aa
...
...
@@ -7,7 +7,7 @@ import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import
{
IMessagePassingProtocol
}
from
'
vs/base/parts/ipc/common/ipc
'
;
import
Event
,
{
chain
}
from
'
vs/base/common/event
'
;
import
{
fromEventEmitter
}
from
'
vs/base/node/event
'
;
import
{
Server
as
IPCServer
,
Client
as
IPCClient
,
IServer
,
I
Client
,
IChannel
}
from
'
vs/base/parts/ipc/common/ipc
'
;
import
{
ChannelServer
as
IPCServer
,
ChannelClient
as
IPCClient
,
IChannelServer
,
IChannel
Client
,
IChannel
}
from
'
vs/base/parts/ipc/common/ipc
'
;
const
Hello
=
'
ipc:hello
'
;
const
Goodbye
=
'
ipc:goodbye
'
;
...
...
@@ -43,7 +43,7 @@ interface IIPCEvent {
message
:
string
;
}
export
class
Server
implements
IServer
,
IDisposable
{
export
class
Server
implements
I
Channel
Server
,
IDisposable
{
private
channels
:
{
[
name
:
string
]:
IChannel
}
=
Object
.
create
(
null
);
...
...
@@ -84,7 +84,7 @@ export class Server implements IServer, IDisposable {
}
}
export
class
Client
implements
IClient
,
IDisposable
{
export
class
Client
implements
IC
hannelC
lient
,
IDisposable
{
private
protocol
:
Protocol
;
private
ipcClient
:
IPCClient
;
...
...
src/vs/base/parts/ipc/common/ipc.ts
浏览文件 @
5e6580aa
...
...
@@ -62,15 +62,23 @@ export interface IChannel {
call
(
command
:
string
,
arg
:
any
):
TPromise
<
any
>
;
}
export
interface
IServer
{
export
interface
I
Channel
Server
{
registerChannel
(
channelName
:
string
,
channel
:
IChannel
):
void
;
}
export
interface
IClient
{
export
interface
IC
hannelC
lient
{
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
):
T
;
}
export
class
Server
{
export
interface
IClientRouter
{
routeCall
(
command
:
string
,
arg
:
any
):
string
;
}
export
interface
IMultiChannelClient
{
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
,
router
:
IClientRouter
):
T
;
}
export
class
ChannelServer
{
private
channels
:
{
[
name
:
string
]:
IChannel
};
private
activeRequests
:
{
[
id
:
number
]:
IDisposable
;
};
...
...
@@ -150,7 +158,7 @@ export class Server {
}
}
export
class
C
lient
implements
I
Client
,
IDisposable
{
export
class
C
hannelClient
implements
IChannel
Client
,
IDisposable
{
private
state
:
State
;
private
activeRequests
:
Promise
[];
...
...
src/vs/base/parts/ipc/node/ipc.cp.ts
浏览文件 @
5e6580aa
...
...
@@ -8,7 +8,7 @@ import { IDisposable } from 'vs/base/common/lifecycle';
import
{
Promise
}
from
'
vs/base/common/winjs.base
'
;
import
{
Delayer
}
from
'
vs/base/common/async
'
;
import
{
clone
,
assign
}
from
'
vs/base/common/objects
'
;
import
{
Server
as
IPCServer
,
Client
as
IPCClient
,
I
Client
,
IChannel
}
from
'
vs/base/parts/ipc/common/ipc
'
;
import
{
ChannelServer
as
IPCServer
,
ChannelClient
as
IPCClient
,
IChannel
Client
,
IChannel
}
from
'
vs/base/parts/ipc/common/ipc
'
;
export
class
Server
extends
IPCServer
{
constructor
()
{
...
...
@@ -54,7 +54,7 @@ export interface IIPCOptions {
debugBrk
?:
number
;
}
export
class
Client
implements
IClient
,
IDisposable
{
export
class
Client
implements
IC
hannelC
lient
,
IDisposable
{
private
disposeDelayer
:
Delayer
<
void
>
;
private
activeRequests
:
Promise
[];
...
...
src/vs/base/parts/ipc/node/ipc.net.ts
浏览文件 @
5e6580aa
...
...
@@ -10,7 +10,7 @@ import { TPromise } from 'vs/base/common/winjs.base';
import
{
IDisposable
}
from
'
vs/base/common/lifecycle
'
;
import
Event
,
{
Emitter
}
from
'
vs/base/common/event
'
;
import
{
fromEventEmitter
}
from
'
vs/base/node/event
'
;
import
{
Server
as
IPCServer
,
Client
as
IPCClient
,
IMessagePassingProtocol
,
IServer
,
IClient
,
IChannel
}
from
'
vs/base/parts/ipc/common/ipc
'
;
import
{
ChannelServer
,
ChannelClient
,
IMessagePassingProtocol
,
IChannelServer
,
IChannelClient
,
IMultiChannelClient
,
IClientRouter
,
IChannel
}
from
'
vs/base/parts/ipc/common/ipc
'
;
function
bufferIndexOf
(
buffer
:
Buffer
,
value
:
number
,
start
=
0
)
{
while
(
start
<
buffer
.
length
&&
buffer
[
start
]
!==
value
)
{
...
...
@@ -75,21 +75,15 @@ class Protocol implements IMessagePassingProtocol {
}
}
// TODO: NAME IT BETTER
export
interface
IClientPicker
{
getClientId
():
string
;
}
// TODO: NAME IT BETTER
class
ClientMultiplexer
implements
IClient
{
class
RoutingChannelClient
implements
IMultiChannelClient
{
private
ipcClients
:
{
[
id
:
string
]:
IPC
Client
;
};
private
ipcClients
:
{
[
id
:
string
]:
Channel
Client
;
};
constructor
(
private
clientPicker
:
IClientPicker
)
{
constructor
()
{
this
.
ipcClients
=
Object
.
create
(
null
);
}
add
(
id
:
string
,
client
:
IPC
Client
):
void
{
add
(
id
:
string
,
client
:
Channel
Client
):
void
{
this
.
ipcClients
[
id
]
=
client
;
}
...
...
@@ -97,31 +91,32 @@ class ClientMultiplexer implements IClient {
delete
this
.
ipcClients
[
id
];
}
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
):
T
{
return
{
call
:
(
command
:
string
,
arg
:
any
)
=>
{
const
id
=
this
.
clientPicker
.
getClientId
();
const
client
=
this
.
ipcClients
[
id
];
if
(
!
client
)
{
return
TPromise
.
wrapError
(
'
Client unknown
'
);
}
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
,
router
:
IClientRouter
):
T
{
const
call
=
(
command
:
string
,
arg
:
any
)
=>
{
const
id
=
router
.
routeCall
(
command
,
arg
);
const
client
=
this
.
ipcClients
[
id
];
return
client
.
getChannel
(
channelName
).
call
(
command
,
arg
);
if
(
!
client
)
{
return
TPromise
.
wrapError
(
'
Unknown client
'
);
}
}
as
T
;
return
client
.
getChannel
(
channelName
)
.
call
(
command
,
arg
);
};
return
{
call
}
as
T
;
}
}
// TODO
: name it better!
export
class
Server
implements
I
Server
,
I
Client
,
IDisposable
{
// TODO
@joao: move multi channel implementation down to ipc
export
class
Server
implements
I
ChannelServer
,
IMultiChannel
Client
,
IDisposable
{
private
channels
:
{
[
name
:
string
]:
IChannel
};
private
clientMultiplexer
:
ClientMultiplexer
;
private
router
:
RoutingChannelClient
;
constructor
(
private
server
:
NetServer
,
private
clientPicker
:
IClientPicker
)
{
constructor
(
private
server
:
NetServer
)
{
this
.
channels
=
Object
.
create
(
null
);
this
.
clientMultiplexer
=
new
ClientMultiplexer
(
clientPicker
);
this
.
router
=
new
RoutingChannelClient
(
);
this
.
server
.
on
(
'
connection
'
,
(
socket
:
Socket
)
=>
{
const
protocol
=
new
Protocol
(
socket
);
...
...
@@ -134,25 +129,25 @@ export class Server implements IServer, IClient, IDisposable {
didGetId
=
true
;
const
ipcServer
=
new
IPC
Server
(
protocol
);
const
channelServer
=
new
Channel
Server
(
protocol
);
Object
.
keys
(
this
.
channels
)
.
forEach
(
name
=>
ipc
Server
.
registerChannel
(
name
,
this
.
channels
[
name
]));
.
forEach
(
name
=>
channel
Server
.
registerChannel
(
name
,
this
.
channels
[
name
]));
const
ipcClient
=
new
IPC
Client
(
protocol
);
this
.
clientMultiplexer
.
add
(
id
,
ipc
Client
);
const
channelClient
=
new
Channel
Client
(
protocol
);
this
.
router
.
add
(
id
,
channel
Client
);
socket
.
once
(
'
close
'
,
()
=>
{
ipc
Client
.
dispose
();
this
.
clientMultiplex
er
.
remove
(
id
);
ipc
Server
.
dispose
();
channel
Client
.
dispose
();
this
.
rout
er
.
remove
(
id
);
channel
Server
.
dispose
();
});
});
});
}
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
):
T
{
return
this
.
clientMultiplexer
.
getChannel
<
T
>
(
channelName
);
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
,
router
:
IClientRouter
):
T
{
return
this
.
router
.
getChannel
<
T
>
(
channelName
,
router
);
}
registerChannel
(
channelName
:
string
,
channel
:
IChannel
):
void
{
...
...
@@ -166,11 +161,10 @@ export class Server implements IServer, IClient, IDisposable {
}
}
// TODO: name it!
export
class
Client
implements
IClient
,
IServer
,
IDisposable
{
export
class
Client
implements
IChannelClient
,
IChannelServer
,
IDisposable
{
private
ipcClient
:
IPC
Client
;
private
ipcServer
:
IPC
Server
;
private
channelClient
:
Channel
Client
;
private
channelServer
:
Channel
Server
;
private
_onClose
=
new
Emitter
<
void
>
();
get
onClose
():
Event
<
void
>
{
return
this
.
_onClose
.
event
;
}
...
...
@@ -179,25 +173,25 @@ export class Client implements IClient, IServer, IDisposable {
const
protocol
=
new
Protocol
(
socket
);
protocol
.
send
(
id
);
this
.
ipcClient
=
new
IPC
Client
(
protocol
);
this
.
ipcServer
=
new
IPC
Server
(
protocol
);
this
.
channelClient
=
new
Channel
Client
(
protocol
);
this
.
channelServer
=
new
Channel
Server
(
protocol
);
socket
.
once
(
'
close
'
,
()
=>
this
.
_onClose
.
fire
());
}
getChannel
<
T
extends
IChannel
>
(
channelName
:
string
):
T
{
return
this
.
ipc
Client
.
getChannel
(
channelName
)
as
T
;
return
this
.
channel
Client
.
getChannel
(
channelName
)
as
T
;
}
registerChannel
(
channelName
:
string
,
channel
:
IChannel
):
void
{
this
.
ipc
Server
.
registerChannel
(
channelName
,
channel
);
this
.
channel
Server
.
registerChannel
(
channelName
,
channel
);
}
dispose
():
void
{
this
.
socket
.
end
();
this
.
socket
=
null
;
this
.
ipc
Client
=
null
;
this
.
ipc
Server
.
dispose
();
this
.
ipc
Server
=
null
;
this
.
channel
Client
=
null
;
this
.
channel
Server
.
dispose
();
this
.
channel
Server
=
null
;
}
}
...
...
@@ -210,20 +204,18 @@ export function serve(hook: any): TPromise<Server> {
server
.
on
(
'
error
'
,
e
);
server
.
listen
(
hook
,
()
=>
{
server
.
removeListener
(
'
error
'
,
e
);
c
(
new
Server
(
server
,
{
getClientId
:
()
=>
''
}));
c
(
new
Server
(
server
));
});
});
}
export
function
connect
(
port
:
number
):
TPromise
<
Client
>
;
export
function
connect
(
namedPipe
:
string
):
TPromise
<
Client
>
;
export
function
connect
(
hook
:
any
):
TPromise
<
Client
>
{
export
function
connect
(
port
:
number
,
clientId
?:
string
):
TPromise
<
Client
>
;
export
function
connect
(
namedPipe
:
string
,
clientId
?:
string
):
TPromise
<
Client
>
;
export
function
connect
(
hook
:
any
,
clientId
:
string
=
''
):
TPromise
<
Client
>
{
return
new
TPromise
<
Client
>
((
c
,
e
)
=>
{
const
socket
=
createConnection
(
hook
,
()
=>
{
socket
.
removeListener
(
'
error
'
,
e
);
c
(
new
Client
(
socket
,
''
));
c
(
new
Client
(
socket
,
clientId
));
});
socket
.
once
(
'
error
'
,
e
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录