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
Show 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 (
...
@@ -43,22 +43,22 @@ const (
// A header is sent as a prefix to every transmission. It will be followed by
// 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.
// a request structure, an error structure, or an arbitrary user payload structure.
type
header
struct
{
type
header
struct
{
n
ame
string
N
ame
string
p
ayloadType
int
P
ayloadType
int
s
eqNum
int64
S
eqNum
int64
}
}
// Sent with a header once per channel from importer to exporter to report
// 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
// that it wants to bind to a channel with the specified direction for count
// messages. If count is -1, it means unlimited.
// messages. If count is -1, it means unlimited.
type
request
struct
{
type
request
struct
{
c
ount
int64
C
ount
int64
d
ir
Dir
D
ir
Dir
}
}
// Sent with a header to report an error.
// Sent with a header to report an error.
type
error
struct
{
type
error
struct
{
e
rror
string
E
rror
string
}
}
// Used to unify management of acknowledgements for import and export.
// Used to unify management of acknowledgements for import and export.
...
@@ -111,7 +111,7 @@ func (ed *encDec) decode(value reflect.Value) os.Error {
...
@@ -111,7 +111,7 @@ func (ed *encDec) decode(value reflect.Value) os.Error {
// Encode a header and payload onto the connection.
// Encode a header and payload onto the connection.
func
(
ed
*
encDec
)
encode
(
hdr
*
header
,
payloadType
int
,
payload
interface
{})
os
.
Error
{
func
(
ed
*
encDec
)
encode
(
hdr
*
header
,
payloadType
int
,
payload
interface
{})
os
.
Error
{
ed
.
encLock
.
Lock
()
ed
.
encLock
.
Lock
()
hdr
.
p
ayloadType
=
payloadType
hdr
.
P
ayloadType
=
payloadType
err
:=
ed
.
enc
.
Encode
(
hdr
)
err
:=
ed
.
enc
.
Encode
(
hdr
)
if
err
==
nil
{
if
err
==
nil
{
if
payload
!=
nil
{
if
payload
!=
nil
{
...
...
src/pkg/netchan/export.go
View file @
feb8d0b2
...
@@ -67,7 +67,7 @@ func newClient(exp *Exporter, conn net.Conn) *expClient {
...
@@ -67,7 +67,7 @@ func newClient(exp *Exporter, conn net.Conn) *expClient {
func
(
client
*
expClient
)
sendError
(
hdr
*
header
,
err
string
)
{
func
(
client
*
expClient
)
sendError
(
hdr
*
header
,
err
string
)
{
error
:=
&
error
{
err
}
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
.
encode
(
hdr
,
payError
,
error
)
// ignore any encode error, hope client gets it
client
.
mu
.
Lock
()
client
.
mu
.
Lock
()
client
.
errored
=
true
client
.
errored
=
true
...
@@ -77,14 +77,14 @@ func (client *expClient) sendError(hdr *header, err string) {
...
@@ -77,14 +77,14 @@ func (client *expClient) sendError(hdr *header, err string) {
func
(
client
*
expClient
)
getChan
(
hdr
*
header
,
dir
Dir
)
*
chanDir
{
func
(
client
*
expClient
)
getChan
(
hdr
*
header
,
dir
Dir
)
*
chanDir
{
exp
:=
client
.
exp
exp
:=
client
.
exp
exp
.
mu
.
Lock
()
exp
.
mu
.
Lock
()
ech
,
ok
:=
exp
.
chans
[
hdr
.
n
ame
]
ech
,
ok
:=
exp
.
chans
[
hdr
.
N
ame
]
exp
.
mu
.
Unlock
()
exp
.
mu
.
Unlock
()
if
!
ok
{
if
!
ok
{
client
.
sendError
(
hdr
,
"no such channel: "
+
hdr
.
n
ame
)
client
.
sendError
(
hdr
,
"no such channel: "
+
hdr
.
N
ame
)
return
nil
return
nil
}
}
if
ech
.
dir
!=
dir
{
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
nil
}
}
return
ech
return
ech
...
@@ -106,24 +106,24 @@ func (client *expClient) run() {
...
@@ -106,24 +106,24 @@ func (client *expClient) run() {
expLog
(
"error decoding client header:"
,
err
)
expLog
(
"error decoding client header:"
,
err
)
break
break
}
}
switch
hdr
.
p
ayloadType
{
switch
hdr
.
P
ayloadType
{
case
payRequest
:
case
payRequest
:
*
req
=
request
{}
*
req
=
request
{}
if
err
:=
client
.
decode
(
reqValue
);
err
!=
nil
{
if
err
:=
client
.
decode
(
reqValue
);
err
!=
nil
{
expLog
(
"error decoding client request:"
,
err
)
expLog
(
"error decoding client request:"
,
err
)
break
break
}
}
switch
req
.
d
ir
{
switch
req
.
D
ir
{
case
Recv
:
case
Recv
:
go
client
.
serveRecv
(
*
hdr
,
req
.
c
ount
)
go
client
.
serveRecv
(
*
hdr
,
req
.
C
ount
)
case
Send
:
case
Send
:
// Request to send is clear as a matter of protocol
// Request to send is clear as a matter of protocol
// but not actually used by the implementation.
// but not actually used by the implementation.
// The actual sends will have payload type payData.
// The actual sends will have payload type payData.
// TODO: manage the count?
// TODO: manage the count?
default
:
default
:
error
.
e
rror
=
"request: can't handle channel direction"
error
.
E
rror
=
"request: can't handle channel direction"
expLog
(
error
.
error
,
req
.
d
ir
)
expLog
(
error
.
Error
,
req
.
D
ir
)
client
.
encode
(
hdr
,
payError
,
error
)
client
.
encode
(
hdr
,
payError
,
error
)
}
}
case
payData
:
case
payData
:
...
@@ -132,19 +132,19 @@ func (client *expClient) run() {
...
@@ -132,19 +132,19 @@ func (client *expClient) run() {
client
.
serveClosed
(
*
hdr
)
client
.
serveClosed
(
*
hdr
)
case
payAck
:
case
payAck
:
client
.
mu
.
Lock
()
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
// Since the sequence number is incremented and the message is sent
// in a single instance of locking client.mu, the messages are guaranteed
// in a single instance of locking client.mu, the messages are guaranteed
// to be sent in order. Therefore receipt of acknowledgement N means
// to be sent in order. Therefore receipt of acknowledgement N means
// all messages <=N have been seen by the recipient. We check anyway.
// 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.
if
client
.
ackNum
<
hdr
.
S
eqNum
{
// If there has been an error, don't back up the count.
client
.
ackNum
=
hdr
.
s
eqNum
client
.
ackNum
=
hdr
.
S
eqNum
}
}
client
.
mu
.
Unlock
()
client
.
mu
.
Unlock
()
default
:
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
)
client
.
exp
.
delClient
(
client
)
...
@@ -171,7 +171,7 @@ func (client *expClient) serveRecv(hdr header, count int64) {
...
@@ -171,7 +171,7 @@ func (client *expClient) serveRecv(hdr header, count int64) {
// number, not one beyond.
// number, not one beyond.
client
.
mu
.
Lock
()
client
.
mu
.
Lock
()
client
.
seqNum
++
client
.
seqNum
++
hdr
.
s
eqNum
=
client
.
seqNum
hdr
.
S
eqNum
=
client
.
seqNum
client
.
seqLock
.
Lock
()
// guarantee ordering of messages
client
.
seqLock
.
Lock
()
// guarantee ordering of messages
client
.
mu
.
Unlock
()
client
.
mu
.
Unlock
()
err
:=
client
.
encode
(
&
hdr
,
payData
,
val
.
Interface
())
err
:=
client
.
encode
(
&
hdr
,
payData
,
val
.
Interface
())
...
...
src/pkg/netchan/import.go
View file @
feb8d0b2
...
@@ -78,7 +78,7 @@ func (imp *Importer) run() {
...
@@ -78,7 +78,7 @@ func (imp *Importer) run() {
imp
.
shutdown
()
imp
.
shutdown
()
return
return
}
}
switch
hdr
.
p
ayloadType
{
switch
hdr
.
P
ayloadType
{
case
payData
:
case
payData
:
// done lower in loop
// done lower in loop
case
payError
:
case
payError
:
...
@@ -86,25 +86,25 @@ func (imp *Importer) run() {
...
@@ -86,25 +86,25 @@ func (imp *Importer) run() {
impLog
(
"error:"
,
e
)
impLog
(
"error:"
,
e
)
return
return
}
}
if
err
.
e
rror
!=
""
{
if
err
.
E
rror
!=
""
{
impLog
(
"response error:"
,
err
.
e
rror
)
impLog
(
"response error:"
,
err
.
E
rror
)
if
sent
:=
imp
.
errors
<-
os
.
ErrorString
(
err
.
e
rror
);
!
sent
{
if
sent
:=
imp
.
errors
<-
os
.
ErrorString
(
err
.
E
rror
);
!
sent
{
imp
.
shutdown
()
imp
.
shutdown
()
return
return
}
}
continue
// errors are not acknowledged.
continue
// errors are not acknowledged.
}
}
case
payClosed
:
case
payClosed
:
ich
:=
imp
.
getChan
(
hdr
.
n
ame
)
ich
:=
imp
.
getChan
(
hdr
.
N
ame
)
if
ich
!=
nil
{
if
ich
!=
nil
{
ich
.
ch
.
Close
()
ich
.
ch
.
Close
()
}
}
continue
// closes are not acknowledged.
continue
// closes are not acknowledged.
default
:
default
:
impLog
(
"unexpected payload type:"
,
hdr
.
p
ayloadType
)
impLog
(
"unexpected payload type:"
,
hdr
.
P
ayloadType
)
return
return
}
}
ich
:=
imp
.
getChan
(
hdr
.
n
ame
)
ich
:=
imp
.
getChan
(
hdr
.
N
ame
)
if
ich
==
nil
{
if
ich
==
nil
{
continue
continue
}
}
...
@@ -113,8 +113,8 @@ func (imp *Importer) run() {
...
@@ -113,8 +113,8 @@ func (imp *Importer) run() {
return
return
}
}
// Acknowledge receipt
// Acknowledge receipt
ackHdr
.
name
=
hdr
.
n
ame
ackHdr
.
Name
=
hdr
.
N
ame
ackHdr
.
seqNum
=
hdr
.
s
eqNum
ackHdr
.
SeqNum
=
hdr
.
S
eqNum
imp
.
encode
(
ackHdr
,
payAck
,
nil
)
imp
.
encode
(
ackHdr
,
payAck
,
nil
)
// Create a new value for each received item.
// Create a new value for each received item.
value
:=
reflect
.
MakeZero
(
ich
.
ch
.
Type
()
.
(
*
reflect
.
ChanType
)
.
Elem
())
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)
...
@@ -178,8 +178,8 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, n int)
}
}
imp
.
chans
[
name
]
=
&
chanDir
{
ch
,
dir
}
imp
.
chans
[
name
]
=
&
chanDir
{
ch
,
dir
}
// Tell the other side about this channel.
// Tell the other side about this channel.
hdr
:=
&
header
{
n
ame
:
name
}
hdr
:=
&
header
{
N
ame
:
name
}
req
:=
&
request
{
count
:
int64
(
n
),
d
ir
:
dir
}
req
:=
&
request
{
Count
:
int64
(
n
),
D
ir
:
dir
}
if
err
=
imp
.
encode
(
hdr
,
payRequest
,
req
);
err
!=
nil
{
if
err
=
imp
.
encode
(
hdr
,
payRequest
,
req
);
err
!=
nil
{
impLog
(
"request encode:"
,
err
)
impLog
(
"request encode:"
,
err
)
return
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