OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 part of dart.io; | 5 part of dart.io; |
6 | 6 |
7 | 7 |
8 /** | 8 /** |
9 * [InternetAddressType] is the type an [InternetAddress]. Currently, | 9 * [InternetAddressType] is the type an [InternetAddress]. Currently, |
10 * IP version 4 (IPv4) and IP version 6 (IPv6) are supported. | 10 * IP version 4 (IPv4) and IP version 6 (IPv6) are supported. |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 class SocketOption { | 316 class SocketOption { |
317 /** | 317 /** |
318 * Enable or disable no-delay on the socket. If TCP_NODELAY is enabled, the | 318 * Enable or disable no-delay on the socket. If TCP_NODELAY is enabled, the |
319 * socket will not buffer data internally, but instead write each data chunk | 319 * socket will not buffer data internally, but instead write each data chunk |
320 * as an invidual TCP packet. | 320 * as an invidual TCP packet. |
321 * | 321 * |
322 * TCP_NODELAY is disabled by default. | 322 * TCP_NODELAY is disabled by default. |
323 */ | 323 */ |
324 static const SocketOption TCP_NODELAY = const SocketOption._(0); | 324 static const SocketOption TCP_NODELAY = const SocketOption._(0); |
325 | 325 |
326 static const SocketOption _IP_MULTICAST_LOOP = const SocketOption._(1); | |
327 static const SocketOption _IP_MULTICAST_HOPS = const SocketOption._(2); | |
328 static const SocketOption _IP_MULTICAST_IF = const SocketOption._(3); | |
329 static const SocketOption _IP_BROADCAST = const SocketOption._(4); | |
330 | |
326 const SocketOption._(this._value); | 331 const SocketOption._(this._value); |
327 final _value; | 332 final _value; |
328 } | 333 } |
329 | 334 |
330 /** | 335 /** |
331 * Events for the [RawSocket]. | 336 * Events for the [RawSocket]. |
332 */ | 337 */ |
333 class RawSocketEvent { | 338 class RawSocketEvent { |
334 static const RawSocketEvent READ = const RawSocketEvent._(0); | 339 static const RawSocketEvent READ = const RawSocketEvent._(0); |
335 static const RawSocketEvent WRITE = const RawSocketEvent._(1); | 340 static const RawSocketEvent WRITE = const RawSocketEvent._(1); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 */ | 504 */ |
500 InternetAddress get address; | 505 InternetAddress get address; |
501 | 506 |
502 /** | 507 /** |
503 * Returns the remote [InternetAddress] connected to by this socket. | 508 * Returns the remote [InternetAddress] connected to by this socket. |
504 */ | 509 */ |
505 InternetAddress get remoteAddress; | 510 InternetAddress get remoteAddress; |
506 } | 511 } |
507 | 512 |
508 | 513 |
514 /** | |
515 * Datagram package. Data send to and received from datagram sockets | |
516 * contains the internet address and port of the destination or source | |
517 * togeter with the data. | |
518 */ | |
519 class Datagram { | |
520 List<int> data; | |
521 InternetAddress address; | |
522 int port; | |
523 | |
524 Datagram(this.data, this.address, this.port); | |
525 } | |
526 | |
527 | |
528 /** | |
529 * The [RawDatagramSocket] is a low-level interface to an UDP socket, | |
530 * exposing the raw events signaled by the system. It's a [Stream] of | |
531 * [RawSocketEvent]s. | |
532 * | |
533 * Note that the event [RawSocketEvent.READ_CLOSED] will never be | |
534 * received as an UDP socket cannot be closed by a remote peer. | |
535 */ | |
536 abstract class RawDatagramSocket extends Stream<RawSocketEvent> { | |
Anders Johnsen
2013/12/12 12:19:58
Maybe add a static bool 'isMulticastEnabled(Networ
Søren Gjesse
2013/12/12 15:44:39
We should definitely add more information like thi
| |
537 /** | |
538 * Creates a new raw datagram socket binding it to an address and | |
539 * port. | |
540 */ | |
541 external static Future<RawDatagramSocket> bind( | |
542 host, int port, {bool reuseAddress: true}); | |
543 | |
544 /** | |
545 * Returns the port used by this socket. | |
546 */ | |
547 int get port; | |
548 | |
549 /** | |
550 * Returns the address used by this socket. | |
551 */ | |
552 InternetAddress get address; | |
553 | |
554 /** | |
555 * Close the datagram socket. | |
556 */ | |
557 void close(); | |
558 | |
559 /** | |
560 * Send a datagram. | |
561 * | |
562 * Returns the number of bytes written. This will always be either | |
563 * the size of [buffer] or `0`. | |
564 */ | |
565 int send(List<int> buffer, InternetAddress address, int port); | |
566 | |
567 /** | |
568 * Receive a datagram. If there are no datagrams available `null` is | |
569 * returned. | |
570 */ | |
571 Datagram receive(); | |
572 | |
573 /** | |
574 * Join a multicast group. | |
575 * | |
576 * If an error occur when trying to join the multicast group an | |
577 * exception is thrown. | |
578 */ | |
579 void joinMulticast(InternetAddress group, {NetworkInterface interface}); | |
580 | |
581 /** | |
582 * Leave a multicast group. | |
583 * | |
584 * If an error occur when trying to join the multicase group an | |
585 * exception is thrown. | |
586 */ | |
587 void leaveMulticast(InternetAddress group, {NetworkInterface interface}); | |
588 | |
589 /** | |
590 * Set or get, if the [RawDatagramSocket] should listen for | |
591 * [RawSocketEvent.READ] events. Default is [true]. | |
592 */ | |
593 bool readEventsEnabled; | |
594 | |
595 /** | |
596 * Set or get, if the [RawDatagramSocket] should listen for | |
597 * [RawSocketEvent.WRITE] events. Default is [true]. This is a | |
598 * one-shot listener, and writeEventsEnabled must be set to true | |
599 * again to receive another write event. | |
600 */ | |
601 bool writeEventsEnabled; | |
602 | |
603 /** | |
604 * Set or get, whether multicast traffic is looped back to the host. | |
605 * | |
606 * By default multicast loopback is enabled. | |
607 */ | |
608 bool multicastLoopback; | |
609 | |
610 /** | |
611 * Set or get, the maximum network hops for multicast packages | |
612 * originating from this socket. | |
613 * | |
614 * For IPv4 this is referred to as TTL (time to live). | |
615 * | |
616 * By default this value is 1 causing multicast traffic to stay on | |
617 * the local network. | |
618 */ | |
619 int multicastHops; | |
620 | |
621 /** | |
622 * Set or get, the network interface used for outgoing multicast packages. | |
623 * | |
624 * A value of `null`indicate that the system chooses the network | |
625 * interface to use. | |
626 * | |
627 * By default this value is `null` | |
628 */ | |
629 NetworkInterface multicastInterface; | |
630 | |
631 /** | |
632 * Set or get, whether IPv4 broadcast is enabled. | |
633 * | |
634 * IPv4 broadcast needs to be enabled by the sender for sending IPv4 | |
635 * broadcast packages. By default IPv4 broadcast is disabled. | |
636 * | |
637 * For IPv6 there is no general broadcast mechanism. Use multicast | |
638 * instead. | |
639 */ | |
640 bool broadcastEnabled; | |
641 } | |
642 | |
643 | |
509 class SocketException implements IOException { | 644 class SocketException implements IOException { |
510 final String message; | 645 final String message; |
511 final OSError osError; | 646 final OSError osError; |
512 final InternetAddress address; | 647 final InternetAddress address; |
513 final int port; | 648 final int port; |
514 | 649 |
515 const SocketException(String this.message, | 650 const SocketException(String this.message, |
516 {OSError this.osError, | 651 {OSError this.osError, |
517 InternetAddress this.address, | 652 InternetAddress this.address, |
518 int this.port}); | 653 int this.port}); |
(...skipping 11 matching lines...) Expand all Loading... | |
530 } | 665 } |
531 if (address != null) { | 666 if (address != null) { |
532 sb.write(", address = ${address.host}"); | 667 sb.write(", address = ${address.host}"); |
533 } | 668 } |
534 if (port != null) { | 669 if (port != null) { |
535 sb.write(", port = $port"); | 670 sb.write(", port = $port"); |
536 } | 671 } |
537 return sb.toString(); | 672 return sb.toString(); |
538 } | 673 } |
539 } | 674 } |
OLD | NEW |