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
96777ea2
Commit
96777ea2
authored
Jan 30, 2009
by
Rob Pike
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up server code in tutorial
R=rsc DELTA=15 (1 added, 0 deleted, 14 changed) OCL=23889 CL=23889
parent
391425ae
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
14 deletions
+15
-14
doc/go_tutorial.txt
doc/go_tutorial.txt
+1
-1
doc/progs/run
doc/progs/run
+2
-1
doc/progs/server.go
doc/progs/server.go
+9
-9
doc/progs/server1.go
doc/progs/server1.go
+3
-3
No files found.
doc/go_tutorial.txt
View file @
96777ea2
...
...
@@ -755,7 +755,7 @@ With channels, it's possible to serve multiple independent client goroutines wit
writing an actual multiplexer. The trick is to send the server a channel in the message,
which it will then use to reply to the original sender.
A realistic client-server program is a lot of code, so here is a very simple substitute
to illustrate the idea. It starts by defining a "
R
equest" type, which embeds a channel
to illustrate the idea. It starts by defining a "
r
equest" type, which embeds a channel
that will be used for the reply.
--PROG progs/server.go /type.request/ /^}/
...
...
doc/progs/run
View file @
96777ea2
...
...
@@ -68,7 +68,8 @@ testit print_string "" "77 Sunset Strip"
testitpipe sieve
"sed 10q"
"2 3 5 7 11 13 17 19 23 29"
testitpipe sieve
"sed 10q"
"2 3 5 7 11 13 17 19 23 29"
# server hangs; don't run it
# server hangs; don't run it, just compile it
6g server.go
testit server1
""
""
rm
-f
6.out
*
.6
doc/progs/server.go
View file @
96777ea2
...
...
@@ -11,21 +11,21 @@ type request struct {
type
binOp
(
a
,
b
int
)
int
;
func
run
(
op
*
BinOp
,
request
*
R
equest
)
{
result
:=
op
(
req
uest
.
a
,
request
.
b
);
req
uest
.
replyc
<-
result
;
func
run
(
op
*
binOp
,
req
*
r
equest
)
{
result
:=
op
(
req
.
a
,
req
.
b
);
req
.
replyc
<-
result
;
}
func
server
(
op
*
BinOp
,
service
chan
*
R
equest
)
{
func
server
(
op
*
binOp
,
service
chan
*
r
equest
)
{
for
{
req
uest
:=
<-
service
;
go
run
(
op
,
req
uest
);
// don't wait for it
req
:=
<-
service
;
go
run
(
op
,
req
);
// don't wait for it
}
}
func
startServer
(
op
*
BinOp
)
chan
*
R
equest
{
req
:=
make
(
chan
*
R
equest
);
go
S
erver
(
op
,
req
);
func
startServer
(
op
*
binOp
)
chan
*
r
equest
{
req
:=
make
(
chan
*
r
equest
);
go
s
erver
(
op
,
req
);
return
req
;
}
...
...
doc/progs/server1.go
View file @
96777ea2
...
...
@@ -11,9 +11,9 @@ type request struct {
type
binOp
(
a
,
b
int
)
int
;
func
run
(
op
*
binOp
,
req
uest
*
request
)
{
result
:=
op
(
req
uest
.
a
,
request
.
b
);
req
uest
.
replyc
<-
result
;
func
run
(
op
*
binOp
,
req
*
request
)
{
result
:=
op
(
req
.
a
,
req
.
b
);
req
.
replyc
<-
result
;
}
func
server
(
op
*
binOp
,
service
chan
*
request
,
quit
chan
bool
)
{
...
...
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