Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
eb20ba6d
Commit
eb20ba6d
authored
Jun 28, 2010
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
netchan: allow chan of basic types now that gob can handle such
R=rsc CC=golang-dev
https://golang.org/cl/1741041
parent
5245ea77
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
24 deletions
+16
-24
export.go
src/pkg/netchan/export.go
+1
-1
import.go
src/pkg/netchan/import.go
+1
-4
netchan_test.go
src/pkg/netchan/netchan_test.go
+14
-19
No files found.
src/pkg/netchan/export.go
View file @
eb20ba6d
...
...
@@ -225,7 +225,7 @@ func checkChan(chT interface{}, dir Dir) (*reflect.ChanValue, os.Error) {
// Despite the literal signature, the effective signature is
// Export(name string, chT chan T, dir Dir)
// where T must be a struct, pointer to struct, etc.
// TODO: fix
gob interface so we can eliminate the need for pT, and for structs
.
// TODO: fix
reflection so we can eliminate the need for pT
.
func
(
exp
*
Exporter
)
Export
(
name
string
,
chT
interface
{},
dir
Dir
,
pT
interface
{})
os
.
Error
{
ch
,
err
:=
checkChan
(
chT
,
dir
)
if
err
!=
nil
{
...
...
src/pkg/netchan/import.go
View file @
eb20ba6d
...
...
@@ -136,7 +136,7 @@ func (imp *Importer) Import(name string, chT interface{}, dir Dir, pT interface{
// err := imp.ImportNValues("name", ch, Recv, new(myType), 1)
// if err != nil { log.Exit(err) }
// fmt.Printf("%+v\n", <-ch)
// TODO: fix
gob interface so we can eliminate the need for pT, and for structs
.
// TODO: fix
reflection so we can eliminate the need for pT
.
func
(
imp
*
Importer
)
ImportNValues
(
name
string
,
chT
interface
{},
dir
Dir
,
pT
interface
{},
n
int
)
os
.
Error
{
ch
,
err
:=
checkChan
(
chT
,
dir
)
if
err
!=
nil
{
...
...
@@ -147,9 +147,6 @@ func (imp *Importer) ImportNValues(name string, chT interface{}, dir Dir, pT int
if
_
,
ok
:=
rt
.
(
*
reflect
.
PtrType
);
!
ok
{
return
os
.
ErrorString
(
"not a pointer:"
+
rt
.
String
())
}
if
_
,
ok
:=
reflect
.
Indirect
(
reflect
.
NewValue
(
pT
))
.
(
*
reflect
.
StructValue
);
!
ok
{
return
os
.
ErrorString
(
"not a pointer to a struct:"
+
rt
.
String
())
}
imp
.
chanLock
.
Lock
()
defer
imp
.
chanLock
.
Unlock
()
_
,
present
:=
imp
.
chans
[
name
]
...
...
src/pkg/netchan/netchan_test.go
View file @
eb20ba6d
...
...
@@ -6,43 +6,38 @@ package netchan
import
"testing"
type
value
struct
{
i
int
s
string
}
const
count
=
10
// number of items in most tests
const
closeCount
=
5
// number of items when sender closes early
func
exportSend
(
exp
*
Exporter
,
n
int
,
t
*
testing
.
T
)
{
ch
:=
make
(
chan
value
)
err
:=
exp
.
Export
(
"exportedSend"
,
ch
,
Send
,
new
(
value
))
ch
:=
make
(
chan
int
)
err
:=
exp
.
Export
(
"exportedSend"
,
ch
,
Send
,
new
(
int
))
if
err
!=
nil
{
t
.
Fatal
(
"exportSend:"
,
err
)
}
for
i
:=
0
;
i
<
n
;
i
++
{
ch
<-
value
{
23
+
i
,
"hello"
}
ch
<-
23
+
i
}
close
(
ch
)
}
func
exportReceive
(
exp
*
Exporter
,
t
*
testing
.
T
)
{
ch
:=
make
(
chan
value
)
err
:=
exp
.
Export
(
"exportedRecv"
,
ch
,
Recv
,
new
(
value
))
ch
:=
make
(
chan
int
)
err
:=
exp
.
Export
(
"exportedRecv"
,
ch
,
Recv
,
new
(
int
))
if
err
!=
nil
{
t
.
Fatal
(
"exportReceive:"
,
err
)
}
for
i
:=
0
;
i
<
count
;
i
++
{
v
:=
<-
ch
if
v
.
i
!=
45
+
i
||
v
.
s
!=
"hello"
{
t
.
Errorf
(
"export Receive: bad value: expected 4%d
, hello; got %+v
"
,
45
+
i
,
v
)
if
v
!=
45
+
i
{
t
.
Errorf
(
"export Receive: bad value: expected 4%d
; got %d
"
,
45
+
i
,
v
)
}
}
}
func
importReceive
(
imp
*
Importer
,
t
*
testing
.
T
)
{
ch
:=
make
(
chan
value
)
err
:=
imp
.
ImportNValues
(
"exportedSend"
,
ch
,
Recv
,
new
(
value
),
count
)
ch
:=
make
(
chan
int
)
err
:=
imp
.
ImportNValues
(
"exportedSend"
,
ch
,
Recv
,
new
(
int
),
count
)
if
err
!=
nil
{
t
.
Fatal
(
"importReceive:"
,
err
)
}
...
...
@@ -54,20 +49,20 @@ func importReceive(imp *Importer, t *testing.T) {
}
break
}
if
v
.
i
!=
23
+
i
||
v
.
s
!=
"hello"
{
t
.
Errorf
(
"importReceive: bad value: expected %d
, hello; got %+v
"
,
23
+
i
,
v
)
if
v
!=
23
+
i
{
t
.
Errorf
(
"importReceive: bad value: expected %d
; got %+d
"
,
23
+
i
,
v
)
}
}
}
func
importSend
(
imp
*
Importer
,
t
*
testing
.
T
)
{
ch
:=
make
(
chan
value
)
err
:=
imp
.
ImportNValues
(
"exportedRecv"
,
ch
,
Send
,
new
(
value
),
count
)
ch
:=
make
(
chan
int
)
err
:=
imp
.
ImportNValues
(
"exportedRecv"
,
ch
,
Send
,
new
(
int
),
count
)
if
err
!=
nil
{
t
.
Fatal
(
"importSend:"
,
err
)
}
for
i
:=
0
;
i
<
count
;
i
++
{
ch
<-
value
{
45
+
i
,
"hello"
}
ch
<-
45
+
i
}
}
...
...
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