Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
1e98227e
Commit
1e98227e
authored
Jun 14, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
341b2124
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
29 deletions
+34
-29
go/xcommon/xnet/pipenet/pipenet.go
go/xcommon/xnet/pipenet/pipenet.go
+4
-1
go/xcommon/xnet/pipenet/pipenet_test.go
go/xcommon/xnet/pipenet/pipenet_test.go
+30
-28
No files found.
go/xcommon/xnet/pipenet/pipenet.go
View file @
1e98227e
...
...
@@ -40,10 +40,11 @@ package pipenet
import
(
"context"
"errors"
//"fmt"
"net"
"strconv"
"sync"
"../../../xcommon/xnet"
)
const
NetPrefix
=
"pipe"
// pipenet package creates only "pipe*" networks
...
...
@@ -85,6 +86,8 @@ type Host struct {
socketv
[]
*
socket
// port -> listener | conn
}
var
_
xnet
.
Networker
=
(
*
Host
)(
nil
)
// socket represents one endpoint entry on Network
// it can be either already connected or listening
type
socket
struct
{
...
...
go/xcommon/xnet/pipenet/pipenet_test.go
View file @
1e98227e
...
...
@@ -22,6 +22,7 @@ import (
"fmt"
"io"
"net"
"strconv"
"reflect"
"testing"
...
...
@@ -86,63 +87,64 @@ func assertEq(t *testing.T, a, b interface{}) {
func
TestPipeNet
(
t
*
testing
.
T
)
{
pnet
:=
New
(
"α"
)
addrtestv
:=
[]
struct
{
port
,
endpoint
int
;
want
string
}
{
{
0
,
-
1
,
"0"
},
{
1
,
0
,
"1c"
},
{
2
,
1
,
"2s"
},
}
for
_
,
tt
:=
range
addrtestv
{
addr
:=
&
Addr
{
Net
:
"pipeβ"
,
Port
:
tt
.
port
,
Endpoint
:
tt
.
endpoint
}
have
:=
addr
.
String
()
if
have
!=
tt
.
want
{
t
.
Errorf
(
"%#v -> %q ; want %q"
,
addr
,
have
,
tt
.
want
)
pnet
:=
New
(
"t"
)
addr
:=
func
(
hostport
string
)
*
Addr
{
// XXX -> Network.ParseAddr ?
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
hostport
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
port
,
err
:=
strconv
.
Atoi
(
portstr
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
&
Addr
{
Net
:
pnet
.
Network
(),
Host
:
host
,
Port
:
port
}
}
_
,
err
:=
pnet
.
Dial
(
context
.
Background
(),
"0"
)
assertEq
(
t
,
err
,
&
net
.
OpError
{
Op
:
"dial"
,
Net
:
"pipeα"
,
Addr
:
&
Addr
{
"pipeα"
,
0
,
-
1
},
Err
:
errConnRefused
})
hα
:=
pnet
.
Host
(
"α"
)
hβ
:=
pnet
.
Host
(
"β"
)
_
,
err
:=
hα
.
Dial
(
context
.
Background
(),
":0"
)
assertEq
(
t
,
err
,
&
net
.
OpError
{
Op
:
"dial"
,
Net
:
"pipet"
,
Addr
:
addr
(
"α:0"
),
Err
:
errConnRefused
})
l1
:=
xlisten
(
pnet
,
""
)
assertEq
(
t
,
l1
.
Addr
(),
&
Addr
{
"pipeα"
,
0
,
-
1
}
)
l1
:=
xlisten
(
hα
,
""
)
assertEq
(
t
,
l1
.
Addr
(),
addr
(
"α:0"
)
)
// XXX -> use workGroup (in connection_test.go)
wg
:=
&
errgroup
.
Group
{}
wg
.
Go
(
func
()
error
{
return
exc
.
Runx
(
func
()
{
c1s
:=
xaccept
(
l1
)
assertEq
(
t
,
c1s
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
1
,
1
}
)
assertEq
(
t
,
c1s
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
1
,
0
}
)
assertEq
(
t
,
c1s
.
LocalAddr
(),
addr
(
"α:1"
)
)
assertEq
(
t
,
c1s
.
RemoteAddr
(),
addr
(
"β:0"
)
)
assertEq
(
t
,
xread
(
c1s
),
"ping"
)
xwrite
(
c1s
,
"pong"
)
c2s
:=
xaccept
(
l1
)
assertEq
(
t
,
c2s
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
2
,
1
}
)
assertEq
(
t
,
c2s
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
2
,
0
}
)
assertEq
(
t
,
c2s
.
LocalAddr
(),
addr
(
"α:2"
)
)
assertEq
(
t
,
c2s
.
RemoteAddr
(),
addr
(
"β:1"
)
)
assertEq
(
t
,
xread
(
c2s
),
"hello"
)
xwrite
(
c2s
,
"world"
)
})
})
c1c
:=
xdial
(
pnet
,
"
0"
)
assertEq
(
t
,
c1c
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
1
,
0
}
)
assertEq
(
t
,
c1c
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
1
,
1
}
)
c1c
:=
xdial
(
hβ
,
"α:
0"
)
assertEq
(
t
,
c1c
.
LocalAddr
(),
addr
(
"β:0"
)
)
assertEq
(
t
,
c1c
.
RemoteAddr
(),
addr
(
"α:1"
)
)
xwrite
(
c1c
,
"ping"
)
assertEq
(
t
,
xread
(
c1c
),
"pong"
)
c2c
:=
xdial
(
pnet
,
"
0"
)
assertEq
(
t
,
c2c
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
2
,
0
}
)
assertEq
(
t
,
c2c
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
2
,
1
}
)
c2c
:=
xdial
(
hβ
,
"α:
0"
)
assertEq
(
t
,
c2c
.
LocalAddr
(),
addr
(
"β:1"
)
)
assertEq
(
t
,
c2c
.
RemoteAddr
(),
addr
(
"α:2"
)
)
xwrite
(
c2c
,
"hello"
)
assertEq
(
t
,
xread
(
c2c
),
"world"
)
xwait
(
wg
)
l2
:=
xlisten
(
pnet
,
""
)
assertEq
(
t
,
l2
.
Addr
(),
&
Addr
{
"pipeα"
,
3
,
-
1
}
)
l2
:=
xlisten
(
hα
,
""
)
assertEq
(
t
,
l2
.
Addr
(),
addr
(
"α:3"
)
)
}
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