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
eb41c45f
Commit
eb41c45f
authored
Dec 20, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
edfc431e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
+20
-20
t/neo/connection.go
t/neo/connection.go
+12
-2
t/neo/connection_test.go
t/neo/connection_test.go
+8
-18
No files found.
t/neo/connection.go
View file @
eb41c45f
...
...
@@ -21,8 +21,10 @@ import (
"sync"
"unsafe"
//
"fmt"
"fmt"
)
// XXX temp
var
_
=
fmt
.
Println
// NodeLink is a node-node link in NEO
//
...
...
@@ -182,10 +184,13 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
// first read to read pkt header and hopefully up to page of data in 1 syscall
pkt
:=
&
PktBuf
{
make
([]
byte
,
4096
)}
n
,
err
:=
io
.
ReadAtLeast
(
nl
.
peerLink
,
pkt
.
Data
,
PktHeadLen
)
// TODO reenable, but NOTE next packet can be also prefetched here
//n, err := io.ReadAtLeast(nl.peerLink, pkt.Data, PktHeadLen)
n
,
err
:=
io
.
ReadFull
(
nl
.
peerLink
,
pkt
.
Data
[
:
PktHeadLen
])
if
err
!=
nil
{
return
nil
,
err
// XXX err adjust ?
}
//println("read head:", n)
pkth
:=
pkt
.
Header
()
...
...
@@ -212,6 +217,7 @@ func (nl *NodeLink) recvPkt() (*PktBuf, error) {
if
err
!=
nil
{
return
nil
,
err
// XXX err adjust ?
}
//println("read data:", len(pkt.Data)-n)
}
return
pkt
,
nil
...
...
@@ -264,6 +270,7 @@ func (nl *NodeLink) serveRecv() {
// pkt.ConnId -> Conn
connId
:=
ntoh32
(
pkt
.
Header
()
.
ConnId
)
//fmt.Printf("%p\t (recv) -> connId: %v\n", nl, connId)
var
handleNewConn
func
(
conn
*
Conn
)
nl
.
connMu
.
Lock
()
...
...
@@ -273,6 +280,8 @@ func (nl *NodeLink) serveRecv() {
if
handleNewConn
!=
nil
{
conn
=
nl
.
newConn
(
connId
)
}
// FIXME update connTab with born conn
}
nl
.
connMu
.
Unlock
()
...
...
@@ -287,6 +296,7 @@ func (nl *NodeLink) serveRecv() {
if
handleNewConn
!=
nil
{
// TODO avoid spawning goroutine for each new Ask request -
// - by keeping pool of read inactive goroutine / conn pool ?
//println("+ handle", connId)
go
handleNewConn
(
conn
)
}
...
...
t/neo/connection_test.go
View file @
eb41c45f
...
...
@@ -93,7 +93,7 @@ func _mkpkt(connid uint32, msgcode uint16, payload []byte) *PktBuf {
h
:=
pkt
.
Header
()
h
.
ConnId
=
hton32
(
connid
)
h
.
MsgCode
=
hton16
(
msgcode
)
h
.
Len
=
hton32
(
PktHeadLen
+
4
)
h
.
Len
=
hton32
(
PktHeadLen
+
uint32
(
len
(
payload
))
)
copy
(
pkt
.
Payload
(),
payload
)
return
pkt
}
...
...
@@ -263,7 +263,6 @@ func TestNodeLink(t *testing.T) {
xclose
(
nl2
)
// for completeness
// Conn accept + exchange
println
(
"000"
)
nl1
,
nl2
=
nodeLinkPipe
()
nl2
.
HandleNewConn
(
func
(
c
*
Conn
)
{
// TODO raised err -> errch
...
...
@@ -281,7 +280,7 @@ func TestNodeLink(t *testing.T) {
xverifyPkt
(
pkt2
,
c1
.
connId
,
34
,
[]
byte
(
"pong"
))
// test 2 channels with replies comming in reversed time order
println
(
"111"
)
nl1
,
nl2
=
nodeLinkPipe
(
)
order
:=
map
[
uint16
]
struct
{
// "order" in which to process requests
start
chan
int
// processing starts when start chan is ready
next
uint16
// after processing this switch to next
...
...
@@ -292,7 +291,7 @@ func TestNodeLink(t *testing.T) {
go
func
()
{
order
[
2
]
.
start
<-
0
}()
println
(
"aaa"
)
c1
=
nl1
.
NewConn
()
// XXX temp?
c2
:=
nl1
.
NewConn
()
nl2
.
HandleNewConn
(
func
(
c
*
Conn
)
{
pkt
:=
xrecv
(
c
)
...
...
@@ -311,26 +310,17 @@ func TestNodeLink(t *testing.T) {
xsend
(
c1
,
mkpkt
(
1
,
[]
byte
(
""
)))
xsend
(
c2
,
mkpkt
(
2
,
[]
byte
(
""
)))
println
(
"bbb"
)
wg
=
WorkGroup
()
echo
Tes
t
:=
func
(
c
*
Conn
,
msgCode
uint16
)
func
()
{
echo
Wai
t
:=
func
(
c
*
Conn
,
msgCode
uint16
)
func
()
{
return
func
()
{
/*
pkt := mkpkt(msgCode, []byte(""))
xsend(c, pkt)
*/
pkt2
:=
xrecv
(
c
)
println
(
"recv"
,
msgCode
)
xverifyPkt
(
pkt2
,
c
.
connId
,
msgCode
,
[]
byte
(
""
))
pkt
:=
xrecv
(
c
)
xverifyPkt
(
pkt
,
c
.
connId
,
msgCode
,
[]
byte
(
""
))
}
}
wg
.
Gox
(
echoTest
(
c1
,
1
))
wg
.
Gox
(
echoTest
(
c2
,
2
))
println
(
"ccc"
)
wg
.
Gox
(
echoWait
(
c1
,
1
))
wg
.
Gox
(
echoWait
(
c2
,
2
))
xwait
(
wg
)
println
(
"ddd"
)
xclose
(
c1
)
xclose
(
c2
)
...
...
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