Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
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
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
feb8d0b2
Commit
feb8d0b2
authored
Jan 11, 2011
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
netchan: make fields public for pending gob change
R=rsc CC=golang-dev
https://golang.org/cl/3882042
parent
fee3aca2
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
33 deletions
+33
-33
src/pkg/netchan/common.go
src/pkg/netchan/common.go
+7
-7
src/pkg/netchan/export.go
src/pkg/netchan/export.go
+15
-15
src/pkg/netchan/import.go
src/pkg/netchan/import.go
+11
-11
No files found.
src/pkg/netchan/common.go
View file @
feb8d0b2
...
...
@@ -43,22 +43,22 @@ const (
// A header is sent as a prefix to every transmission. It will be followed by
// a request structure, an error structure, or an arbitrary user payload structure.
type
header
struct
{
n
ame
string
p
ayloadType
int
s
eqNum
int64
N
ame
string
P
ayloadType
int
S
eqNum
int64
}
// Sent with a header once per channel from importer to exporter to report
// that it wants to bind to a channel with the specified direction for count
// messages. If count is -1, it means unlimited.
type
request
struct
{
c
ount
int64
d
ir
Dir
C
ount
int64
D
ir
Dir
}
// Sent with a header to report an error.
type
error
struct
{
e
rror
string
E
rror
string
}
// Used to unify management of acknowledgements for import and export.
...
...
@@ -111,7 +111,7 @@ func (ed *encDec) decode(value reflect.Value) os.Error {
// Encode a header and payload onto the connection.
func
(
ed
*
encDec
)
encode
(
hdr
*
header
,
payloadType
int
,
payload
interface
{})
os
.
Error
{
ed
.
encLock
.
Lock
()
hdr
.
p
ayloadType
=
payloadType
hdr
.
P
ayloadType
=
payloadType
err
:=
ed
.
enc
.
Encode
(
hdr
)
if
err
==
nil
{
if
payload
!=
nil
{
...
...
src/pkg/netchan/export.go
View file @
feb8d0b2
...
...
@@ -67,7 +67,7 @@ func newClient(exp *Exporter, conn net.Conn) *expClient {
func
(
client
*
expClient
)
sendError
(
hdr
*
header
,
err
string
)
{
error
:=
&
error
{
err
}
expLog
(
"sending error to client:"
,
error
.
e
rror
)
expLog
(
"sending error to client:"
,
error
.
E
rror
)
client
.
encode
(
hdr
,
payError
,
error
)
// ignore any encode error, hope client gets it
client
.
mu
.
Lock
()
client
.
errored
=
true
...
...
@@ -77,14 +77,14 @@ func (client *expClient) sendError(hdr *header, err string) {
func
(
client
*
expClient
)
getChan
(
hdr
*
header
,
dir
Dir
)
*
chanDir
{
exp
:=
client
.
exp
exp
.
mu
.
Lock
()
ech
,
ok
:=
exp
.
chans
[
hdr
.
n
ame
]
ech
,
ok
:=
exp
.
chans
[
hdr
.
N
ame
]
exp
.
mu
.
Unlock
()
if
!
ok
{
client
.
sendError
(
hdr
,
"no such channel: "
+
hdr
.
n
ame
)
client
.
sendError
(
hdr
,
"no such channel: "
+
hdr
.
N
ame
)
return
nil
}
if
ech
.
dir
!=
dir
{
client
.
sendError
(
hdr
,
"wrong direction for channel: "
+
hdr
.
n
ame
)
client
.
sendError
(
hdr
,
"wrong direction for channel: "
+
hdr
.
N
ame
)
return
nil
}
return
ech
...
...
@@ -106,24 +106,24 @@ func (client *expClient) run() {
expLog
(
"error decoding client header:"
,
err
)
break
}
switch
hdr
.
p
ayloadType
{
switch
hdr
.
P
ayloadType
{
case
payRequest
:
*
req
=
request
{}
if
err
:=
client
.
decode
(
reqValue
);
err
!=
nil
{
expLog
(
"error decoding client request:"
,
err
)
break
}
switch
req
.
d
ir
{
switch
req
.
D
ir
{
case
Recv
:
go
client
.
serveRecv
(
*
hdr
,
req
.
c
ount
)
go
client
.
serveRecv
(
*
hdr
,
req
.
C
ount
)
case
Send
:
// Request to send is clear as a matter of protocol
// but not actually used by the implementation.
// The actual sends will have payload type payData.
// TODO: manage the count?
default
:
error
.
e
rror
=
"request: can't handle channel direction"
expLog
(
error
.
error
,
req
.
d
ir
)
error
.
E
rror
=
"request: can't handle channel direction"
expLog
(
error
.
Error
,
req
.
D
ir
)
client
.
encode
(
hdr
,
payError
,
error
)
}
case
payData
:
...
...
@@ -132,19 +132,19 @@ func (client *expClient) run() {
client
.
serveClosed
(
*
hdr
)
case
payAck
:
client
.
mu
.
Lock
()
if
client
.
ackNum
!=
hdr
.
s
eqNum
-
1
{
if
client
.
ackNum
!=
hdr
.
S
eqNum
-
1
{
// Since the sequence number is incremented and the message is sent
// in a single instance of locking client.mu, the messages are guaranteed
// to be sent in order. Therefore receipt of acknowledgement N means
// all messages <=N have been seen by the recipient. We check anyway.
expLog
(
"sequence out of order:"
,
client
.
ackNum
,
hdr
.
s
eqNum
)
expLog
(
"sequence out of order:"
,
client
.
ackNum
,
hdr
.
S
eqNum
)
}
if
client
.
ackNum
<
hdr
.
s
eqNum
{
// If there has been an error, don't back up the count.
client
.
ackNum
=
hdr
.
s
eqNum
if
client
.
ackNum
<
hdr
.
S
eqNum
{
// If there has been an error, don't back up the count.
client
.
ackNum
=
hdr
.
S
eqNum
}
client
.
mu
.
Unlock
()
default
:
log
.
Exit
(
"netchan export: unknown payload type"
,
hdr
.
p
ayloadType
)
log
.
Exit
(
"netchan export: unknown payload type"
,
hdr
.
P
ayloadType
)
}
}
client
.
exp
.
delClient
(
client
)
...
...
@@ -171,7 +171,7 @@ func (client *expClient) serveRecv(hdr header, count int64) {
// number, not one beyond.
client
.
mu
.
Lock
()
client
.
seqNum
++
hdr
.
s
eqNum
=
client
.
seqNum
hdr
.
S
eqNum
=
client
.
seqNum
client
.
seqLock
.
Lock
()
// guarantee ordering of messages
client
.
mu
.
Unlock
()
err
:=
client
.
encode
(
&
hdr
,
payData
,
val
.
Interface
())
...
...
src/pkg/netchan/import.go
View file @
feb8d0b2
...
...
@@ -78,7 +78,7 @@ func (imp *Importer) run() {
imp
.
shutdown
()
return
}
switch
hdr
.
p
ayloadType
{
switch
hdr
.
P
ayloadType
{
case
payData
:
// done lower in loop
case
payError
:
...
...
@@ -86,25 +86,25 @@ func (imp *Importer) run() {
impLog
(
"error:"
,
e
)
return
}
if
err
.
e
rror
!=
""
{
impLog
(
"response error:"
,
err
.
e
rror
)
if
sent
:=
imp
.
errors
<-
os
.
ErrorString
(
err
.
e
rror
);
!
sent
{
if
err
.
E
rror
!=
""
{
impLog
(
"response error:"
,
err
.
E
rror
)
if
sent
:=
imp
.
errors
<-
os
.
ErrorString
(
err
.
E
rror
);
!
sent
{
imp
.
shutdown
()
return
}
continue
// errors are not acknowledged.
}
case
payClosed
:
ich
:=
imp
.
getChan
(
hdr
.
n
ame
)
ich
:=
imp
.
getChan
(
hdr
.
N
ame
)
if
ich
!=
nil
{
ich
.
ch
.
Close
()
}
continue
// closes are not acknowledged.
default
:
impLog
(
"unexpected payload type:"
,
hdr
.
p
ayloadType
)
impLog
(
"unexpected payload type:"
,
hdr
.
P
ayloadType
)
return
}
ich
:=
imp
.
getChan
(
hdr
.
n
ame
)
ich
:=
imp
.
getChan
(
hdr
.
N
ame
)
if
ich
==
nil
{
continue
}
...
...
@@ -113,8 +113,8 @@ func (imp *Importer) run() {
return
}
// Acknowledge receipt
ackHdr
.
name
=
hdr
.
n
ame
ackHdr
.
seqNum
=
hdr
.
s
eqNum
ackHdr
.
Name
=
hdr
.
N
ame
ackHdr
.
SeqNum
=
hdr
.
S
eqNum
imp
.
encode
(
ackHdr
,
payAck
,
nil
)
// Create a new value for each received item.
value
:=
reflect
.
MakeZero
(
ich
.
ch
.
Type
()
.
(
*
reflect
.
ChanType
)
.
Elem
())
...
...
@@ -178,8 +178,8 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, n int)
}
imp
.
chans
[
name
]
=
&
chanDir
{
ch
,
dir
}
// Tell the other side about this channel.
hdr
:=
&
header
{
n
ame
:
name
}
req
:=
&
request
{
count
:
int64
(
n
),
d
ir
:
dir
}
hdr
:=
&
header
{
N
ame
:
name
}
req
:=
&
request
{
Count
:
int64
(
n
),
D
ir
:
dir
}
if
err
=
imp
.
encode
(
hdr
,
payRequest
,
req
);
err
!=
nil
{
impLog
(
"request encode:"
,
err
)
return
err
...
...
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