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
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
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
...
@@ -40,10 +40,11 @@ package pipenet
import
(
import
(
"context"
"context"
"errors"
"errors"
//"fmt"
"net"
"net"
"strconv"
"strconv"
"sync"
"sync"
"../../../xcommon/xnet"
)
)
const
NetPrefix
=
"pipe"
// pipenet package creates only "pipe*" networks
const
NetPrefix
=
"pipe"
// pipenet package creates only "pipe*" networks
...
@@ -85,6 +86,8 @@ type Host struct {
...
@@ -85,6 +86,8 @@ type Host struct {
socketv
[]
*
socket
// port -> listener | conn
socketv
[]
*
socket
// port -> listener | conn
}
}
var
_
xnet
.
Networker
=
(
*
Host
)(
nil
)
// socket represents one endpoint entry on Network
// socket represents one endpoint entry on Network
// it can be either already connected or listening
// it can be either already connected or listening
type
socket
struct
{
type
socket
struct
{
...
...
go/xcommon/xnet/pipenet/pipenet_test.go
View file @
1e98227e
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"net"
"net"
"strconv"
"reflect"
"reflect"
"testing"
"testing"
...
@@ -86,63 +87,64 @@ func assertEq(t *testing.T, a, b interface{}) {
...
@@ -86,63 +87,64 @@ func assertEq(t *testing.T, a, b interface{}) {
func
TestPipeNet
(
t
*
testing
.
T
)
{
func
TestPipeNet
(
t
*
testing
.
T
)
{
pnet
:=
New
(
"α"
)
pnet
:=
New
(
"t"
)
addr
:=
func
(
hostport
string
)
*
Addr
{
// XXX -> Network.ParseAddr ?
addrtestv
:=
[]
struct
{
port
,
endpoint
int
;
want
string
}
{
host
,
portstr
,
err
:=
net
.
SplitHostPort
(
hostport
)
{
0
,
-
1
,
"0"
},
if
err
!=
nil
{
{
1
,
0
,
"1c"
},
t
.
Fatal
(
err
)
{
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
)
}
}
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"
)
hα
:=
pnet
.
Host
(
"α"
)
assertEq
(
t
,
err
,
&
net
.
OpError
{
Op
:
"dial"
,
Net
:
"pipeα"
,
Addr
:
&
Addr
{
"pipeα"
,
0
,
-
1
},
Err
:
errConnRefused
})
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
,
""
)
l1
:=
xlisten
(
hα
,
""
)
assertEq
(
t
,
l1
.
Addr
(),
&
Addr
{
"pipeα"
,
0
,
-
1
}
)
assertEq
(
t
,
l1
.
Addr
(),
addr
(
"α:0"
)
)
// XXX -> use workGroup (in connection_test.go)
// XXX -> use workGroup (in connection_test.go)
wg
:=
&
errgroup
.
Group
{}
wg
:=
&
errgroup
.
Group
{}
wg
.
Go
(
func
()
error
{
wg
.
Go
(
func
()
error
{
return
exc
.
Runx
(
func
()
{
return
exc
.
Runx
(
func
()
{
c1s
:=
xaccept
(
l1
)
c1s
:=
xaccept
(
l1
)
assertEq
(
t
,
c1s
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
1
,
1
}
)
assertEq
(
t
,
c1s
.
LocalAddr
(),
addr
(
"α:1"
)
)
assertEq
(
t
,
c1s
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
1
,
0
}
)
assertEq
(
t
,
c1s
.
RemoteAddr
(),
addr
(
"β:0"
)
)
assertEq
(
t
,
xread
(
c1s
),
"ping"
)
assertEq
(
t
,
xread
(
c1s
),
"ping"
)
xwrite
(
c1s
,
"pong"
)
xwrite
(
c1s
,
"pong"
)
c2s
:=
xaccept
(
l1
)
c2s
:=
xaccept
(
l1
)
assertEq
(
t
,
c2s
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
2
,
1
}
)
assertEq
(
t
,
c2s
.
LocalAddr
(),
addr
(
"α:2"
)
)
assertEq
(
t
,
c2s
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
2
,
0
}
)
assertEq
(
t
,
c2s
.
RemoteAddr
(),
addr
(
"β:1"
)
)
assertEq
(
t
,
xread
(
c2s
),
"hello"
)
assertEq
(
t
,
xread
(
c2s
),
"hello"
)
xwrite
(
c2s
,
"world"
)
xwrite
(
c2s
,
"world"
)
})
})
})
})
c1c
:=
xdial
(
pnet
,
"
0"
)
c1c
:=
xdial
(
hβ
,
"α:
0"
)
assertEq
(
t
,
c1c
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
1
,
0
}
)
assertEq
(
t
,
c1c
.
LocalAddr
(),
addr
(
"β:0"
)
)
assertEq
(
t
,
c1c
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
1
,
1
}
)
assertEq
(
t
,
c1c
.
RemoteAddr
(),
addr
(
"α:1"
)
)
xwrite
(
c1c
,
"ping"
)
xwrite
(
c1c
,
"ping"
)
assertEq
(
t
,
xread
(
c1c
),
"pong"
)
assertEq
(
t
,
xread
(
c1c
),
"pong"
)
c2c
:=
xdial
(
pnet
,
"
0"
)
c2c
:=
xdial
(
hβ
,
"α:
0"
)
assertEq
(
t
,
c2c
.
LocalAddr
(),
&
Addr
{
"pipeα"
,
2
,
0
}
)
assertEq
(
t
,
c2c
.
LocalAddr
(),
addr
(
"β:1"
)
)
assertEq
(
t
,
c2c
.
RemoteAddr
(),
&
Addr
{
"pipeα"
,
2
,
1
}
)
assertEq
(
t
,
c2c
.
RemoteAddr
(),
addr
(
"α:2"
)
)
xwrite
(
c2c
,
"hello"
)
xwrite
(
c2c
,
"hello"
)
assertEq
(
t
,
xread
(
c2c
),
"world"
)
assertEq
(
t
,
xread
(
c2c
),
"world"
)
xwait
(
wg
)
xwait
(
wg
)
l2
:=
xlisten
(
pnet
,
""
)
l2
:=
xlisten
(
hα
,
""
)
assertEq
(
t
,
l2
.
Addr
(),
&
Addr
{
"pipeα"
,
3
,
-
1
}
)
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