| 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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 /** | 355 /** |
| 356 * The [RawSocket] is a low-level interface to a socket, exposing the raw | 356 * The [RawSocket] is a low-level interface to a socket, exposing the raw |
| 357 * events signaled by the system. It's a [Stream] of [RawSocketEvent]s. | 357 * events signaled by the system. It's a [Stream] of [RawSocketEvent]s. |
| 358 */ | 358 */ |
| 359 abstract class RawSocket implements Stream<RawSocketEvent> { | 359 abstract class RawSocket implements Stream<RawSocketEvent> { |
| 360 /** | 360 /** |
| 361 * Set or get, if the [RawSocket] should listen for [RawSocketEvent.READ] | 361 * Set or get, if the [RawSocket] should listen for [RawSocketEvent.READ] |
| 362 * events. Default is [true]. | 362 * events. Default is [:true:]. |
| 363 */ | 363 */ |
| 364 bool readEventsEnabled; | 364 bool readEventsEnabled; |
| 365 | 365 |
| 366 /** | 366 /** |
| 367 * Set or get, if the [RawSocket] should listen for [RawSocketEvent.WRITE] | 367 * Set or get, if the [RawSocket] should listen for [RawSocketEvent.WRITE] |
| 368 * events. Default is [true]. | 368 * events. Default is [:true:]. |
| 369 * This is a one-shot listener, and writeEventsEnabled must be set | 369 * This is a one-shot listener, and writeEventsEnabled must be set |
| 370 * to true again to receive another write event. | 370 * to true again to receive another write event. |
| 371 */ | 371 */ |
| 372 bool writeEventsEnabled; | 372 bool writeEventsEnabled; |
| 373 | 373 |
| 374 /** | 374 /** |
| 375 * Creates a new socket connection to the host and port and returns a [Future] | 375 * Creates a new socket connection to the host and port and returns a [Future] |
| 376 * that will complete with either a [RawSocket] once connected or an error | 376 * that will complete with either a [RawSocket] once connected or an error |
| 377 * if the host-lookup or connection failed. | 377 * if the host-lookup or connection failed. |
| 378 * | 378 * |
| 379 * [host] can either be a [String] or an [InternetAddress]. If [host] is a | 379 * [host] can either be a [String] or an [InternetAddress]. If [host] is a |
| 380 * [String], [connect] will perform a [InternetAddress.lookup] and use | 380 * [String], [connect] will perform a [InternetAddress.lookup] and use |
| 381 * the first value in the list. | 381 * the first value in the list. |
| 382 */ | 382 */ |
| 383 external static Future<RawSocket> connect(host, int port); | 383 external static Future<RawSocket> connect(host, int port); |
| 384 | 384 |
| 385 /** | 385 /** |
| 386 * Returns the number of received and non-read bytes in the socket that | 386 * Returns the number of received and non-read bytes in the socket that |
| 387 * can be read. | 387 * can be read. |
| 388 */ | 388 */ |
| 389 int available(); | 389 int available(); |
| 390 | 390 |
| 391 /** | 391 /** |
| 392 * Read up to [len] bytes from the socket. This function is | 392 * Read up to [len] bytes from the socket. This function is |
| 393 * non-blocking and will only return data if data is available. The | 393 * non-blocking and will only return data if data is available. The |
| 394 * number of bytes read can be less then [len] if fewer bytes are | 394 * number of bytes read can be less then [len] if fewer bytes are |
| 395 * available for immediate reading. If no data is available [null] | 395 * available for immediate reading. If no data is available [:null:] |
| 396 * is returned. | 396 * is returned. |
| 397 */ | 397 */ |
| 398 List<int> read([int len]); | 398 List<int> read([int len]); |
| 399 | 399 |
| 400 /** | 400 /** |
| 401 * Writes up to [count] bytes of the buffer from [offset] buffer offset to | 401 * Writes up to [count] bytes of the buffer from [offset] buffer offset to |
| 402 * the socket. The number of successfully written bytes is returned. This | 402 * the socket. The number of successfully written bytes is returned. This |
| 403 * function is non-blocking and will only write data if buffer space is | 403 * function is non-blocking and will only write data if buffer space is |
| 404 * available in the socket. | 404 * available in the socket. |
| 405 * | 405 * |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 * throw an exception and calling it several times is supported. Calling | 443 * throw an exception and calling it several times is supported. Calling |
| 444 * shutdown with either [SocketDirection.BOTH] or [SocketDirection.RECEIVE] | 444 * shutdown with either [SocketDirection.BOTH] or [SocketDirection.RECEIVE] |
| 445 * can result in a [RawSocketEvent.READ_CLOSED] event. | 445 * can result in a [RawSocketEvent.READ_CLOSED] event. |
| 446 */ | 446 */ |
| 447 void shutdown(SocketDirection direction); | 447 void shutdown(SocketDirection direction); |
| 448 | 448 |
| 449 /** | 449 /** |
| 450 * Use [setOption] to customize the [RawSocket]. See [SocketOption] for | 450 * Use [setOption] to customize the [RawSocket]. See [SocketOption] for |
| 451 * available options. | 451 * available options. |
| 452 * | 452 * |
| 453 * Returns [true] if the option was set successfully, false otherwise. | 453 * Returns [:true:] if the option was set successfully, false otherwise. |
| 454 */ | 454 */ |
| 455 bool setOption(SocketOption option, bool enabled); | 455 bool setOption(SocketOption option, bool enabled); |
| 456 } | 456 } |
| 457 | 457 |
| 458 /** | 458 /** |
| 459 * A high-level class for communicating over a TCP socket. | 459 * A high-level class for communicating over a TCP socket. |
| 460 * | 460 * |
| 461 * The [Socket] exposes both a [Stream] and a [IOSink] interface, making it | 461 * The [Socket] exposes both a [Stream] and a [IOSink] interface, making it |
| 462 * ideal for using together with other [Stream]s. | 462 * ideal for using together with other [Stream]s. |
| 463 */ | 463 */ |
| (...skipping 16 matching lines...) Expand all Loading... |
| 480 * | 480 * |
| 481 * Call [close](inherited from [IOSink]) to only close the [Socket] | 481 * Call [close](inherited from [IOSink]) to only close the [Socket] |
| 482 * for sending data. | 482 * for sending data. |
| 483 */ | 483 */ |
| 484 void destroy(); | 484 void destroy(); |
| 485 | 485 |
| 486 /** | 486 /** |
| 487 * Use [setOption] to customize the [RawSocket]. See [SocketOption] for | 487 * Use [setOption] to customize the [RawSocket]. See [SocketOption] for |
| 488 * available options. | 488 * available options. |
| 489 * | 489 * |
| 490 * Returns [true] if the option was set successfully, false otherwise. | 490 * Returns [:true:] if the option was set successfully, false otherwise. |
| 491 */ | 491 */ |
| 492 bool setOption(SocketOption option, bool enabled); | 492 bool setOption(SocketOption option, bool enabled); |
| 493 | 493 |
| 494 /** | 494 /** |
| 495 * Returns the port used by this socket. | 495 * Returns the port used by this socket. |
| 496 */ | 496 */ |
| 497 int get port; | 497 int get port; |
| 498 | 498 |
| 499 /** | 499 /** |
| 500 * Returns the remote port connected to by this socket. | 500 * Returns the remote port connected to by this socket. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 531 * The [RawDatagramSocket] is a low-level interface to an UDP socket, | 531 * The [RawDatagramSocket] is a low-level interface to an UDP socket, |
| 532 * exposing the raw events signaled by the system. It's a [Stream] of | 532 * exposing the raw events signaled by the system. It's a [Stream] of |
| 533 * [RawSocketEvent]s. | 533 * [RawSocketEvent]s. |
| 534 * | 534 * |
| 535 * Note that the event [RawSocketEvent.READ_CLOSED] will never be | 535 * Note that the event [RawSocketEvent.READ_CLOSED] will never be |
| 536 * received as an UDP socket cannot be closed by a remote peer. | 536 * received as an UDP socket cannot be closed by a remote peer. |
| 537 */ | 537 */ |
| 538 abstract class RawDatagramSocket extends Stream<RawSocketEvent> { | 538 abstract class RawDatagramSocket extends Stream<RawSocketEvent> { |
| 539 /** | 539 /** |
| 540 * Set or get, if the [RawDatagramSocket] should listen for | 540 * Set or get, if the [RawDatagramSocket] should listen for |
| 541 * [RawSocketEvent.READ] events. Default is [true]. | 541 * [RawSocketEvent.READ] events. Default is [:true:]. |
| 542 */ | 542 */ |
| 543 bool readEventsEnabled; | 543 bool readEventsEnabled; |
| 544 | 544 |
| 545 /** | 545 /** |
| 546 * Set or get, if the [RawDatagramSocket] should listen for | 546 * Set or get, if the [RawDatagramSocket] should listen for |
| 547 * [RawSocketEvent.WRITE] events. Default is [true]. This is a | 547 * [RawSocketEvent.WRITE] events. Default is [:true:]. This is a |
| 548 * one-shot listener, and writeEventsEnabled must be set to true | 548 * one-shot listener, and writeEventsEnabled must be set to true |
| 549 * again to receive another write event. | 549 * again to receive another write event. |
| 550 */ | 550 */ |
| 551 bool writeEventsEnabled; | 551 bool writeEventsEnabled; |
| 552 | 552 |
| 553 /** | 553 /** |
| 554 * Set or get, whether multicast traffic is looped back to the host. | 554 * Set or get, whether multicast traffic is looped back to the host. |
| 555 * | 555 * |
| 556 * By default multicast loopback is enabled. | 556 * By default multicast loopback is enabled. |
| 557 */ | 557 */ |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 664 } | 664 } |
| 665 if (address != null) { | 665 if (address != null) { |
| 666 sb.write(", address = ${address.host}"); | 666 sb.write(", address = ${address.host}"); |
| 667 } | 667 } |
| 668 if (port != null) { | 668 if (port != null) { |
| 669 sb.write(", port = $port"); | 669 sb.write(", port = $port"); |
| 670 } | 670 } |
| 671 return sb.toString(); | 671 return sb.toString(); |
| 672 } | 672 } |
| 673 } | 673 } |
| OLD | NEW |