Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(689)

Delta Between Two Patch Sets: src/pkg/netchan/export.go

Issue 4301043: update tree for reflect changes (Closed)
Left Patch Set: Created 13 years ago
Right Patch Set: diff -r f692a5e90f6f https://go.googlecode.com/hg/ Created 13 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/dnsmsg.go ('k') | src/pkg/netchan/import.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2010 The Go Authors. All rights reserved. 1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 /* 5 /*
6 The netchan package implements type-safe networked channels: 6 The netchan package implements type-safe networked channels:
7 it allows the two ends of a channel to appear on different 7 it allows the two ends of a channel to appear on different
8 computers connected by a network. It does this by transporting 8 computers connected by a network. It does this by transporting
9 data sent to a channel on one machine so it can be recovered 9 data sent to a channel on one machine so it can be recovered
10 by a receive of a channel of the same type on the other. 10 by a receive of a channel of the same type on the other.
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 } 214 }
215 215
216 // Receive and deliver locally one item from a client asking for a Send 216 // Receive and deliver locally one item from a client asking for a Send
217 // The header is passed by value to avoid issues of overwriting. 217 // The header is passed by value to avoid issues of overwriting.
218 func (client *expClient) serveSend(hdr header) { 218 func (client *expClient) serveSend(hdr header) {
219 nch := client.getChan(&hdr, Recv) 219 nch := client.getChan(&hdr, Recv)
220 if nch == nil { 220 if nch == nil {
221 return 221 return
222 } 222 }
223 // Create a new value for each received item. 223 // Create a new value for each received item.
224 » val := reflect.MakeZero(nch.ch.Type().(*reflect.ChanType).Elem()) 224 » val := reflect.MakeZero(nch.ch.Type().Elem())
225 if err := client.decode(val); err != nil { 225 if err := client.decode(val); err != nil {
226 expLog("value decode:", err, "; type ", nch.ch.Type()) 226 expLog("value decode:", err, "; type ", nch.ch.Type())
227 return 227 return
228 } 228 }
229 nch.send(val) 229 nch.send(val)
230 } 230 }
231 231
232 // Report that client has closed the channel that is sending to us. 232 // Report that client has closed the channel that is sending to us.
233 // The header is passed by value to avoid issues of overwriting. 233 // The header is passed by value to avoid issues of overwriting.
234 func (client *expClient) serveClosed(hdr header) { 234 func (client *expClient) serveClosed(hdr header) {
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 // wait for messages sent while it is running or messages that have not been 334 // wait for messages sent while it is running or messages that have not been
335 // dispatched to any client. If the timeout (measured in nanoseconds) is 335 // dispatched to any client. If the timeout (measured in nanoseconds) is
336 // positive and Sync takes longer than that to complete, an error is 336 // positive and Sync takes longer than that to complete, an error is
337 // returned. 337 // returned.
338 func (exp *Exporter) Sync(timeout int64) os.Error { 338 func (exp *Exporter) Sync(timeout int64) os.Error {
339 // This wrapper function is here so the method's comment will appear in godoc. 339 // This wrapper function is here so the method's comment will appear in godoc.
340 return exp.clientSet.sync(timeout) 340 return exp.clientSet.sync(timeout)
341 } 341 }
342 342
343 func checkChan(chT interface{}, dir Dir) (*reflect.ChanValue, os.Error) { 343 func checkChan(chT interface{}, dir Dir) (*reflect.ChanValue, os.Error) {
344 » chanType, ok := reflect.Typeof(chT).(*reflect.ChanType) 344 » chanType := reflect.Typeof(chT)
345 » if !ok { 345 » if chanType.Kind() != reflect.Chan {
346 return nil, os.ErrorString("not a channel") 346 return nil, os.ErrorString("not a channel")
347 } 347 }
348 if dir != Send && dir != Recv { 348 if dir != Send && dir != Recv {
349 return nil, os.ErrorString("unknown channel direction") 349 return nil, os.ErrorString("unknown channel direction")
350 } 350 }
351 » switch chanType.Dir() { 351 » switch chanType.ChanDir() {
352 case reflect.BothDir: 352 case reflect.BothDir:
353 case reflect.SendDir: 353 case reflect.SendDir:
354 if dir != Recv { 354 if dir != Recv {
355 return nil, os.ErrorString("to import/export with Send, must provide <-chan") 355 return nil, os.ErrorString("to import/export with Send, must provide <-chan")
356 } 356 }
357 case reflect.RecvDir: 357 case reflect.RecvDir:
358 if dir != Send { 358 if dir != Send {
359 return nil, os.ErrorString("to import/export with Recv, must provide chan<-") 359 return nil, os.ErrorString("to import/export with Recv, must provide chan<-")
360 } 360 }
361 } 361 }
(...skipping 29 matching lines...) Expand all
391 exp.names[name] = nil, false 391 exp.names[name] = nil, false
392 } 392 }
393 // TODO drop all instances of channel from client sets 393 // TODO drop all instances of channel from client sets
394 exp.mu.Unlock() 394 exp.mu.Unlock()
395 if !ok { 395 if !ok {
396 return os.ErrorString("netchan export: hangup: no such channel: " + name) 396 return os.ErrorString("netchan export: hangup: no such channel: " + name)
397 } 397 }
398 chDir.ch.Close() 398 chDir.ch.Close()
399 return nil 399 return nil
400 } 400 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b