086c1f0c3a
For the server keep track of the state of the connection and close the socket when it is closed by the client. The client might close the connection both when processing a request and while the connection is an idle keep alive connection. For the client keep track of the active connections as well as the idle keep alive connections. When the client is closed make sure to close all connections. R=ajohnsen@google.com BUG=none TEST=tests/standalone/src/io/HttpShutdownTest.dart Review URL: https://chromiumcodereview.appspot.com//9589001 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@4932 260f80e4-7a28-3924-810f-c04153c831b5
129 lines
3.3 KiB
Dart
129 lines
3.3 KiB
Dart
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
interface ServerSocket default _ServerSocket {
|
|
/**
|
|
* Constructs a new server socket, binds it to a given address and port,
|
|
* and listens on it.
|
|
*/
|
|
ServerSocket(String bindAddress, int port, int backlog);
|
|
|
|
/**
|
|
* The connection handler gets called when there is a new incoming
|
|
* connection on the socket.
|
|
*/
|
|
void set onConnection(void callback(Socket connection));
|
|
|
|
/**
|
|
* The error handler gets called when a socket error occurs.
|
|
*/
|
|
void set onError(void callback());
|
|
|
|
/**
|
|
* Returns the port used by this socket.
|
|
*/
|
|
int get port();
|
|
|
|
/**
|
|
* Closes the socket.
|
|
*/
|
|
void close();
|
|
}
|
|
|
|
|
|
interface Socket extends Hashable default _Socket {
|
|
/**
|
|
* Constructs a new socket and connects it to the given host on the given
|
|
* port.
|
|
*/
|
|
Socket(String host, int port);
|
|
|
|
/**
|
|
* Returns the number of received and non-read bytes in the socket that
|
|
* can be read.
|
|
*/
|
|
int available();
|
|
|
|
/**
|
|
* Reads up to [count] bytes of data from the socket and stores them into
|
|
* buffer after buffer offset [offset]. The number of successfully read
|
|
* bytes is returned. This function is non-blocking and will only read data
|
|
* if data is available.
|
|
*/
|
|
int readList(List<int> buffer, int offset, int count);
|
|
|
|
/**
|
|
* Writes up to [count] bytes of the buffer from [offset] buffer offset to
|
|
* the socket. The number of successfully written bytes is returned. This
|
|
* function is non-blocking and will only write data if buffer space is
|
|
* available in the socket.
|
|
*/
|
|
int writeList(List<int> buffer, int offset, int count);
|
|
|
|
/**
|
|
* The connect handler gets called when connection to a given host
|
|
* succeeded.
|
|
*/
|
|
void set onConnect(void callback());
|
|
|
|
/**
|
|
* The data handler gets called when data becomes available at the socket.
|
|
*/
|
|
void set onData(void callback());
|
|
|
|
/**
|
|
* The write handler gets called when the socket becomes available for
|
|
* writing.
|
|
*/
|
|
void set onWrite(void callback());
|
|
|
|
/**
|
|
* The close handler gets called when a the last byte have been read
|
|
* from a socket. At this point the socket might still be open for
|
|
* writing for sending more data.
|
|
*/
|
|
void set onClosed(void callback());
|
|
|
|
/**
|
|
* The error handler gets called when a socket error occurs.
|
|
*/
|
|
void set onError(void callback());
|
|
|
|
/**
|
|
* Returns input stream to the socket.
|
|
*/
|
|
InputStream get inputStream();
|
|
|
|
/**
|
|
* Returns output stream of the socket.
|
|
*/
|
|
OutputStream get outputStream();
|
|
|
|
/**
|
|
* Returns the port used by this socket.
|
|
*/
|
|
int get port();
|
|
|
|
/**
|
|
* Closes the socket. Calling [close] will never throw an exception
|
|
* and calling it several times is supported. If [halfClose] is true
|
|
* the socket will only be closed for writing and it might still be
|
|
* possible to read data. Calling [close] will not trigger a call to
|
|
* [onClosed].
|
|
*/
|
|
void close([bool halfClose]);
|
|
|
|
/**
|
|
* Socket is hashable.
|
|
*/
|
|
int hashCode();
|
|
}
|
|
|
|
|
|
class SocketIOException implements Exception {
|
|
const SocketIOException([String this.message = ""]);
|
|
String toString() => "SocketIOException: $message";
|
|
final String message;
|
|
}
|