Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
neoppod
Commits
f52053c4
Commit
f52053c4
authored
Jun 02, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
b370f152
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
17 deletions
+45
-17
go/xcommon/pipenet/pipenet.go
go/xcommon/pipenet/pipenet.go
+45
-17
No files found.
go/xcommon/pipenet/pipenet.go
View file @
f52053c4
...
...
@@ -34,12 +34,14 @@ import (
const
NetPrefix
=
"pipe"
// pipenet package works only with "pipe*" networks
var
errBadNetwork
=
errors
.
New
(
"pipenet: invalid network"
)
var
errBadAddress
=
errors
.
New
(
"pipenet: invalid address"
)
var
errNetNotFound
=
errors
.
New
(
"no such network"
)
var
errNetClosed
=
errors
.
New
(
"network connection closed"
)
var
errAddrAlreadyUsed
=
errors
.
New
(
"address already in use"
)
var
errConnRefused
=
errors
.
New
(
"connection refused"
)
var
(
errBadNetwork
=
errors
.
New
(
"pipenet: invalid network"
)
errBadAddress
=
errors
.
New
(
"pipenet: invalid address"
)
errNetNotFound
=
errors
.
New
(
"no such network"
)
errNetClosed
=
errors
.
New
(
"network connection closed"
)
errAddrAlreadyUsed
=
errors
.
New
(
"address already in use"
)
errConnRefused
=
errors
.
New
(
"connection refused"
)
)
// Network represents network of in-memory pipes
...
...
@@ -47,7 +49,7 @@ var errConnRefused = errors.New("connection refused")
//
// Network must be created with New
type
Network
struct
{
// name
(suffix) of this network,
e.g. ""
// name
of this network under "pipe" namespace ->
e.g. ""
// full network name will be reported as "pipe"+Name
Name
string
...
...
@@ -62,7 +64,7 @@ type pipe struct {
listener
*
listener
// listener is waiting here if != nil
}
// Addr represents address of a pipe endpoint
// Addr represents address of a pipe
net
endpoint
type
Addr
struct
{
network
string
// full network name, e.g. "pipe"
addr
string
// XXX -> port ? + including c/s ?
...
...
@@ -117,11 +119,12 @@ func (n *Network) Listen(laddr string) (net.Listener, error) {
l
:=
&
listener
{
network
:
n
,
port
:
port
,
dialq
:
make
(
chan
chan
connected
),
acceptq
:
make
(
chan
chan
connected
),
dialq
:
make
(
chan
chan
net
.
Conn
),
//
acceptq: make(chan chan connected),
down
:
make
(
chan
struct
{}),
}
n
.
pipev
[
port
]
=
&
pipe
{
listener
:
l
}
// go l.listen()
return
l
,
nil
}
...
...
@@ -131,8 +134,8 @@ type listener struct {
network
*
Network
// XXX needed ?
port
int
// port we are listening on XXX needed ?
dialq
chan
chan
connected
// Dial requests to our port go here
acceptq
chan
chan
connected
// Accept requests go here
dialq
chan
chan
net
.
Conn
// Dial requests to our port go here
//
acceptq chan chan connected // Accept requests go here
down
chan
struct
{}
// Close -> down=ready
downOnce
sync
.
Once
// so Close several times is ok
}
...
...
@@ -150,21 +153,47 @@ func (l *listener) Close() error {
return
nil
}
/*
// listen implements listener service process - connecting Accept and Dial calls with each other
func (l *listener) listen() {
for {
select {
case <-l.down:
return
case resp := <-l.dialq:
// TODO
case resp := <-l.acceptq:
// TODO
}
}
}
// connected is response from listener to Dial and Accept
type connected struct {
conn net.Conn
err error
}
*/
func
(
l
*
listener
)
Accept
()
(
net
.
Conn
,
error
)
{
ch
:=
make
(
chan
connected
)
//
ch := make(chan connected)
select
{
case
<-
l
.
down
:
return
nil
,
&
net
.
OpError
{
Op
:
"accept"
,
Net
:
l
.
network
.
netname
(),
Addr
:
l
.
Addr
(),
Err
:
errNetClosed
}
/*
case l.acceptq <- ch:
resp := <-ch
return resp.conn, resp.err
*/
case
resp
:=
<-
l
.
dialq
:
// someone dialed us - let's connect
pc
,
ps
:=
net
.
Pipe
()
resp
<-
pc
return
ps
,
nil
}
}
...
...
@@ -192,14 +221,13 @@ func (n *Network) Dial(addr string) (net.Conn, error) {
l
:=
p
.
listener
// NOTE listener is not locking n.mu -> it is ok to send/receive under mu
ch
:=
make
(
chan
connected
)
resp
:=
make
(
chan
net
.
Conn
)
select
{
case
<-
l
.
down
:
return
nil
,
derr
(
errConnRefused
)
case
l
.
dialq
<-
ch
:
resp
:=
<-
ch
return
resp
.
conn
,
resp
.
err
case
l
.
dialq
<-
resp
:
return
<-
resp
,
nil
}
}
...
...
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