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
55756877
Commit
55756877
authored
Apr 28, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
98ff316b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
20 deletions
+16
-20
go/neo/connection.go
go/neo/connection.go
+16
-20
No files found.
go/neo/connection.go
View file @
55756877
...
...
@@ -62,16 +62,14 @@ type NodeLink struct {
// (rx packets are routed to Conn.rxq)
down
chan
struct
{}
// ready when NodeLink is marked as no longer operational
downOnce
sync
.
Once
// shutdown may be due both Close and IO error
downOnce
sync
.
Once
// shutdown may be due
to
both Close and IO error
downWg
sync
.
WaitGroup
// for activities at shutdown
errClose
error
// error got from peerLink.Close
on shutdown
errClose
error
// error got from peerLink.Close
errMu
sync
.
Mutex
errRecv
error
// error got from recvPkt on shutdown
closeCalled
uint32
// whether Close was called
closed
uint32
// whether Close was called
}
// Conn is a connection established over NodeLink
...
...
@@ -84,19 +82,17 @@ type Conn struct {
nodeLink
*
NodeLink
connId
uint32
rxq
chan
*
PktBuf
// received packets for this Conn go here
txerr
chan
error
// transmit
error
s for this Conn go back here
txerr
chan
error
// transmit
result
s for this Conn go back here
down
chan
struct
{}
// ready when Conn is marked as no longer operational
downOnce
sync
.
Once
// shutdown may be called by both Close and nodelink.shutdown
closeCalled
uint32
// whether Close was called; ^^^ can be from IO error on node link
rxerrOnce
sync
.
Once
// XXX whether actual RX error was already reported to caller
rxerrOnce
sync
.
Once
// IO error is reported only once - then it is link down or closed
closed
uint32
// whether Close was called
}
// ErrLinkClosed is the error indicated for operations on closed NodeLink
var
ErrLinkClosed
=
errors
.
New
(
"node link is closed"
)
// XXX -> read/write but also Accept ?
var
ErrLinkDown
=
errors
.
New
(
"node link is down"
)
// XXX due to IO errors?
var
ErrLinkClosed
=
errors
.
New
(
"node link is closed"
)
// operations on closed NodeLink
var
ErrLinkDown
=
errors
.
New
(
"node link is down"
)
// e.g. due to IO error
var
ErrLinkNoListen
=
errors
.
New
(
"node link is not listening for incoming connections"
)
var
ErrClosedConn
=
errors
.
New
(
"read/write on closed connection"
)
...
...
@@ -173,7 +169,7 @@ func (nl *NodeLink) NewConn() (*Conn, error) {
nl
.
connMu
.
Lock
()
defer
nl
.
connMu
.
Unlock
()
if
nl
.
connTab
==
nil
{
if
atomic
.
LoadUint32
(
&
nl
.
close
Calle
d
)
!=
0
{
if
atomic
.
LoadUint32
(
&
nl
.
closed
)
!=
0
{
return
nil
,
ErrLinkClosed
}
return
nil
,
ErrLinkDown
...
...
@@ -218,7 +214,7 @@ func (nl *NodeLink) shutdown() {
// Close closes node-node link.
// IO on connections established over it is automatically interrupted with an error.
func
(
nl
*
NodeLink
)
Close
()
error
{
atomic
.
StoreUint32
(
&
nl
.
close
Calle
d
,
1
)
atomic
.
StoreUint32
(
&
nl
.
closed
,
1
)
nl
.
shutdown
()
nl
.
downWg
.
Wait
()
return
nl
.
errClose
...
...
@@ -242,7 +238,7 @@ func (c *Conn) Close() error {
delete
(
c
.
nodeLink
.
connTab
,
c
.
connId
)
c
.
nodeLink
.
connMu
.
Unlock
()
atomic
.
StoreUint32
(
&
c
.
close
Calle
d
,
1
)
atomic
.
StoreUint32
(
&
c
.
closed
,
1
)
c
.
shutdown
()
return
nil
}
...
...
@@ -256,7 +252,7 @@ func (nl *NodeLink) Accept() (*Conn, error) {
select
{
case
<-
nl
.
down
:
if
atomic
.
LoadUint32
(
&
nl
.
close
Calle
d
)
!=
0
{
if
atomic
.
LoadUint32
(
&
nl
.
closed
)
!=
0
{
return
nil
,
ErrLinkClosed
// XXX + op = Accept ?
}
return
nil
,
ErrLinkDown
// XXX test
...
...
@@ -269,10 +265,10 @@ func (nl *NodeLink) Accept() (*Conn, error) {
// errRecvShutdown returns appropriate error when c.down is found ready in Recv
func
(
c
*
Conn
)
errRecvShutdown
()
error
{
switch
{
case
atomic
.
LoadUint32
(
&
c
.
close
Calle
d
)
!=
0
:
case
atomic
.
LoadUint32
(
&
c
.
closed
)
!=
0
:
return
ErrClosedConn
case
atomic
.
LoadUint32
(
&
c
.
nodeLink
.
close
Calle
d
)
!=
0
:
case
atomic
.
LoadUint32
(
&
c
.
nodeLink
.
closed
)
!=
0
:
return
ErrLinkClosed
default
:
...
...
@@ -367,14 +363,14 @@ type txReq struct {
// errSendShutdown returns approproate error when c.down is found ready in Send
func
(
c
*
Conn
)
errSendShutdown
()
error
{
switch
{
case
atomic
.
LoadUint32
(
&
c
.
close
Calle
d
)
!=
0
:
case
atomic
.
LoadUint32
(
&
c
.
closed
)
!=
0
:
return
ErrClosedConn
// the only other error possible besides Conn being .Close()'ed is that
// NodeLink was closed/shutdowned itself - on actual IO problems corresponding
// error is delivered to particular Send that caused it.
case
atomic
.
LoadUint32
(
&
c
.
nodeLink
.
close
Calle
d
)
!=
0
:
case
atomic
.
LoadUint32
(
&
c
.
nodeLink
.
closed
)
!=
0
:
return
ErrLinkClosed
default
:
...
...
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