Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: sdk/lib/io/socket.dart

Issue 85993002: Add UDP support to dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed first round of comments Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 class SocketOption { 311 class SocketOption {
312 /** 312 /**
313 * Enable or disable no-delay on the socket. If TCP_NODELAY is enabled, the 313 * Enable or disable no-delay on the socket. If TCP_NODELAY is enabled, the
314 * socket will not buffer data internally, but instead write each data chunk 314 * socket will not buffer data internally, but instead write each data chunk
315 * as an invidual TCP packet. 315 * as an invidual TCP packet.
316 * 316 *
317 * TCP_NODELAY is disabled by default. 317 * TCP_NODELAY is disabled by default.
318 */ 318 */
319 static const SocketOption TCP_NODELAY = const SocketOption._(0); 319 static const SocketOption TCP_NODELAY = const SocketOption._(0);
320 320
321 static const SocketOption _IP_MULTICAST_LOOP = const SocketOption._(1);
322 static const SocketOption _IP_MULTICAST_HOPS = const SocketOption._(2);
323 static const SocketOption _IP_MULTICAST_IF = const SocketOption._(3);
324 static const SocketOption _IP_BROADCAST = const SocketOption._(4);
325
321 const SocketOption._(this._value); 326 const SocketOption._(this._value);
322 final _value; 327 final _value;
323 } 328 }
324 329
325 /** 330 /**
326 * Events for the [RawSocket]. 331 * Events for the [RawSocket].
327 */ 332 */
328 class RawSocketEvent { 333 class RawSocketEvent {
329 static const RawSocketEvent READ = const RawSocketEvent._(0); 334 static const RawSocketEvent READ = const RawSocketEvent._(0);
330 static const RawSocketEvent WRITE = const RawSocketEvent._(1); 335 static const RawSocketEvent WRITE = const RawSocketEvent._(1);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 */ 499 */
495 InternetAddress get address; 500 InternetAddress get address;
496 501
497 /** 502 /**
498 * Returns the remote [InternetAddress] connected to by this socket. 503 * Returns the remote [InternetAddress] connected to by this socket.
499 */ 504 */
500 InternetAddress get remoteAddress; 505 InternetAddress get remoteAddress;
501 } 506 }
502 507
503 508
509 /**
510 * Datagram package. Data send to and received from datagram sockets
511 * contains the internet address and port of the destination or source
512 * togeter with the data.
513 */
514 class Datagram {
515 List<int> data;
516 InternetAddess address;
517 int port;
518
519 Datagram(this.data, this.address, this.port);
520 }
521
522
523 /**
524 * The [RawDatagramSocket] is a low-level interface to an UDP socket,
525 * exposing the raw events signaled by the system. It's a [Stream] of
526 * [RawSocketEvent]s.
527 *
528 * Note that the event [RawSocketEvent.READ_CLOSED] will never be
529 * received as an UDP socket cannot be closed by a remote peer.
530 */
531 abstract class RawDatagramSocket extends Stream<RawSocketEvent> {
532 /**
533 * Creates a new raw datagram socket binding it to an address and
534 * port.
535 */
536 static Future<RawDatagramSocket> bind(
537 host, int port, {bool reuseAddress: true}) =>
538 _RawDatagramSocket.bind(host, port, reuseAddress);
539
540 /**
541 * Returns the port used by this socket.
542 */
543 int get port;
544
545 /**
546 * Returns the address used by this socket.
547 */
548 InternetAddress get address;
549
550 /**
551 * Close the datagram socket.
552 */
553 void close();
554
555 /**
556 * Send a datagram.
557 *
558 * Returns `true` if the datagram was send.
559 */
560 bool send(List<data> buffer, InternetAddress address, int port);
561
562 /**
563 * Receive a datagram. If there are no datagrams available `null` is
564 * returned.
565 */
566 Datagram receive();
567
568 /**
569 * Join a multicast group.
570 *
571 * If an error occur when trying to join the multicast group an
572 * exception is thrown.
573 */
574 void join(InternetAddress group, {NetworkInterface interface});
575
576 /**
577 * Leave a multicast group.
578 *
579 * If an error occur when trying to join the multicase group an
580 * exception is thrown.
581 */
582 void leave(InternetAddress group, {NetworkInterface interface});
583
584 /**
585 * Set or get, if the [RawDatagramSocket] should listen for
586 * [RawSocketEvent.READ] events. Default is [true].
587 */
588 bool readEventsEnabled;
589
590 /**
591 * Set or get, if the [RawDatagramSocket] should listen for
592 * [RawSocketEvent.WRITE] events. Default is [true]. This is a
593 * one-shot listener, and writeEventsEnabled must be set to true
594 * again to receive another write event.
595 */
596 bool writeEventsEnabled;
597
598 /**
599 * Set or get, whether multicast traffic is looped back to the host.
600 *
601 * By default multicast loopback is enabled.
602 */
603 bool multicastLoopback;
604
605 /**
606 * Set or get, the maximum network hops for multicast packages
607 * originating from this socket.
608 *
609 * For IPv4 this is referred to as TTL (time to live).
610 *
611 * By default this value is 1 causing multicast traffic to stay on
612 * the local network.
613 */
614 int multicastHops;
615
616 /**
617 * Set or get, the network interface used for outgoing multicast packages.
618 *
619 * A value of `null`indicate that the system chooses the network
620 * interface to use.
621 *
622 * By default this value is `null`
623 */
624 NetworkInterface multicastInterface;
625
626 /**
627 * Set or get, whether IPv4 broadcast is enabled.
628 *
629 * IPv4 broadcast needs to be enabled by the sender for sending IPv4
630 * broadcast packages. By default IPv4 broadcast is disabled.
631 *
632 * For IPv6 there is no general broadcast mechanism. Use multicast
633 * instead.
634 */
635 bool broadcastEnabled;
636 }
637
638
504 class SocketException implements IOException { 639 class SocketException implements IOException {
505 final String message; 640 final String message;
506 final OSError osError; 641 final OSError osError;
507 final InternetAddress address; 642 final InternetAddress address;
508 final int port; 643 final int port;
509 644
510 const SocketException(String this.message, 645 const SocketException(String this.message,
511 {OSError this.osError, 646 {OSError this.osError,
512 InternetAddress this.address, 647 InternetAddress this.address,
513 int this.port}); 648 int this.port});
(...skipping 11 matching lines...) Expand all
525 } 660 }
526 if (address != null) { 661 if (address != null) {
527 sb.write(", address = ${address.host}"); 662 sb.write(", address = ${address.host}");
528 } 663 }
529 if (port != null) { 664 if (port != null) {
530 sb.write(", port = $port"); 665 sb.write(", port = $port");
531 } 666 }
532 return sb.toString(); 667 return sb.toString();
533 } 668 }
534 } 669 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698