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

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: 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
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | tests/standalone/io/raw_datagram_socket_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
Anders Johnsen 2013/11/25 18:00:06 Should we move private ones to start by, say 16?
Søren Gjesse 2013/11/28 13:58:52 The numbers are not visible outside, so it does no
322 static const SocketOption _IP_MULTICAST_TTL = const SocketOption._(2);
323 static const SocketOption _IP_BROADCAST = const SocketOption._(3);
324
321 const SocketOption._(this._value); 325 const SocketOption._(this._value);
322 final _value; 326 final _value;
323 } 327 }
324 328
325 /** 329 /**
326 * Events for the [RawSocket]. 330 * Events for the [RawSocket].
327 */ 331 */
328 class RawSocketEvent { 332 class RawSocketEvent {
329 static const RawSocketEvent READ = const RawSocketEvent._(0); 333 static const RawSocketEvent READ = const RawSocketEvent._(0);
330 static const RawSocketEvent WRITE = const RawSocketEvent._(1); 334 static const RawSocketEvent WRITE = const RawSocketEvent._(1);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 */ 498 */
495 InternetAddress get address; 499 InternetAddress get address;
496 500
497 /** 501 /**
498 * Returns the remote [InternetAddress] connected to by this socket. 502 * Returns the remote [InternetAddress] connected to by this socket.
499 */ 503 */
500 InternetAddress get remoteAddress; 504 InternetAddress get remoteAddress;
501 } 505 }
502 506
503 507
508 /**
509 * Datagram package. Data send to and received from datagram sockets
510 * contains the internet address and port of the destination or source
511 * togeter with the data.
512 */
513 class Datagram {
514 List<int> data;
515 InternetAddess address;
516 int port;
517
518 Datagram(this.data, this.address, this.port);
519 }
520
521
522 /**
523 * The [RawDatagramSocket] is a low-level interface to an UDP socket,
524 * exposing the raw events signaled by the system. It's a [Stream] of
525 * [RawSocketEvent]s.
526 *
527 * Note that the event [RawSocketEvent.CLOSED] will never be received
528 * as there is no connection which can be closed by a remote peer.
Anders Johnsen 2013/11/25 18:00:06 '[...] as an UDP socket cannot be closed by a remo
Søren Gjesse 2013/11/28 13:58:52 Done.
529 */
530 abstract class RawDatagramSocket extends Stream {
Anders Johnsen 2013/11/25 18:00:06 Can the Stream type be Stream<RawSocketEvent> ?
Søren Gjesse 2013/11/28 13:58:52 Done.
531 /**
532 * Creates a new raw datagram socket binding it to an address and
533 * port.
534 */
535 factory RawDatagramSocket(InternetAddress address, int port) =>
Anders Johnsen 2013/11/25 18:00:06 I think this should be like a Socket and ServerSoc
Søren Gjesse 2013/11/28 13:58:52 I will make it return a future, and change the typ
536 new _RawDatagramSocket(address, port);
537
538 /**
539 * Returns the port used by this socket.
540 */
541 int get port;
542
543 /**
544 * Returns the address used by this socket.
545 */
546 InternetAddress get address;
547
548 /**
549 * Close the datagram socket.
550 */
551 void close();
Anders Johnsen 2013/11/25 18:00:06 Does directional-close work for UDP sockets? (I'm
Søren Gjesse 2013/11/28 13:58:52 No the shutdown is a TCP thing.
552
553 /**
554 * Send a datagram.
555 *
556 * Returns `true` if the datagram was send.
557 */
558 bool send(Datagram datagram);
559
560 /**
561 * Send a datagram.
562 *
563 * Returns `true` if the datagram was send.
564 */
565 bool sendTo(List<data> buffer, InternetAddress address, int port);
Anders Johnsen 2013/11/25 18:00:06 Having both send and sendTo, with so little differ
Søren Gjesse 2013/11/28 13:58:52 Removed one.
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 join(InternetAddress group, [NetworkInterface interface]);
Anders Johnsen 2013/11/25 18:00:06 This is really cool, with the optional interface.
Søren Gjesse 2013/11/28 13:58:52 Done.
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 leave(InternetAddress group, [NetworkInterface interface]);
Anders Johnsen 2013/11/25 18:00:06 Ditto.
Søren Gjesse 2013/11/28 13:58:52 Done.
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;
Anders Johnsen 2013/11/25 18:00:06 Is it true by default? I thought it is only set to
Søren Gjesse 2013/11/28 13:58:52 It starts out as true.
602
603 /**
604 * Set or get, whether multicast traffic is looped back to the host.
Anders Johnsen 2013/11/25 18:00:06 This, and those below, needs a default value in do
Søren Gjesse 2013/11/28 13:58:52 Done.
605 */
606 bool multicastLoopback;
607
608 /**
609 * Set or get, the TTL (time to live) for multicast traffic.
610 */
611 int multicastTTL;
612
613 /**
614 * Set or get, whether broadcast is enabled for the local interface.
615 */
616 bool broadcastEnabled;
617 }
618
619
504 class SocketException implements IOException { 620 class SocketException implements IOException {
505 final String message; 621 final String message;
506 final OSError osError; 622 final OSError osError;
507 final InternetAddress address; 623 final InternetAddress address;
508 final int port; 624 final int port;
509 625
510 const SocketException(String this.message, 626 const SocketException(String this.message,
511 {OSError this.osError, 627 {OSError this.osError,
512 InternetAddress this.address, 628 InternetAddress this.address,
513 int this.port}); 629 int this.port});
(...skipping 11 matching lines...) Expand all
525 } 641 }
526 if (address != null) { 642 if (address != null) {
527 sb.write(", address = ${address.host}"); 643 sb.write(", address = ${address.host}");
528 } 644 }
529 if (port != null) { 645 if (port != null) {
530 sb.write(", port = $port"); 646 sb.write(", port = $port");
531 } 647 }
532 return sb.toString(); 648 return sb.toString();
533 } 649 }
534 } 650 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | tests/standalone/io/raw_datagram_socket_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698