OLD | NEW |
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 Package netchan implements type-safe networked channels: | 6 Package netchan 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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 | 277 |
278 // ServeConn exports the Exporter's channels on conn. | 278 // ServeConn exports the Exporter's channels on conn. |
279 // It blocks until the connection is terminated. | 279 // It blocks until the connection is terminated. |
280 func (exp *Exporter) ServeConn(conn io.ReadWriter) { | 280 func (exp *Exporter) ServeConn(conn io.ReadWriter) { |
281 exp.addClient(conn).run() | 281 exp.addClient(conn).run() |
282 } | 282 } |
283 | 283 |
284 // NewExporter creates a new Exporter that exports a set of channels. | 284 // NewExporter creates a new Exporter that exports a set of channels. |
285 func NewExporter() *Exporter { | 285 func NewExporter() *Exporter { |
286 e := &Exporter{ | 286 e := &Exporter{ |
287 » » clientSet: &clientSet{ | 287 » » clientSet: { |
288 names: make(map[string]*chanDir), | 288 names: make(map[string]*chanDir), |
289 clients: make(map[unackedCounter]bool), | 289 clients: make(map[unackedCounter]bool), |
290 }, | 290 }, |
291 } | 291 } |
292 return e | 292 return e |
293 } | 293 } |
294 | 294 |
295 // ListenAndServe exports the exporter's channels through the | 295 // ListenAndServe exports the exporter's channels through the |
296 // given network and local address defined as in net.Listen. | 296 // given network and local address defined as in net.Listen. |
297 func (exp *Exporter) ListenAndServe(network, localaddr string) error { | 297 func (exp *Exporter) ListenAndServe(network, localaddr string) error { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 delete(exp.names, name) | 391 delete(exp.names, name) |
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 errors.New("netchan export: hangup: no such channel: " +
name) | 396 return errors.New("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 } |
OLD | NEW |