| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 | 5 |
| 6 class _SocketBase { | 6 class _SocketBase { |
| 7 // Bit flags used when communicating between the eventhandler and | 7 // Bit flags used when communicating between the eventhandler and |
| 8 // dart code. The EVENT flags are used to indicate events of | 8 // dart code. The EVENT flags are used to indicate events of |
| 9 // interest when sending a message from dart code to the | 9 // interest when sending a message from dart code to the |
| 10 // eventhandler. When receiving a message from the eventhandler the | 10 // eventhandler. When receiving a message from the eventhandler the |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 return null; | 216 return null; |
| 217 } | 217 } |
| 218 if (port != 0) { | 218 if (port != 0) { |
| 219 socket._port = port; | 219 socket._port = port; |
| 220 } | 220 } |
| 221 return socket; | 221 return socket; |
| 222 } | 222 } |
| 223 | 223 |
| 224 _ServerSocket._internal(); | 224 _ServerSocket._internal(); |
| 225 | 225 |
| 226 Socket accept() { | |
| 227 if (_id >= 0) { | |
| 228 _Socket socket = new _Socket._internal(); | |
| 229 if (_accept(socket)) { | |
| 230 return socket; | |
| 231 } | |
| 232 return null; | |
| 233 } | |
| 234 throw new | |
| 235 SocketIOException("Error: accept failed - invalid socket handle"); | |
| 236 } | |
| 237 | |
| 238 bool _accept(Socket socket) native "ServerSocket_Accept"; | 226 bool _accept(Socket socket) native "ServerSocket_Accept"; |
| 239 | 227 |
| 240 bool _createBindListen(String bindAddress, int port, int backlog) | 228 bool _createBindListen(String bindAddress, int port, int backlog) |
| 241 native "ServerSocket_CreateBindListen"; | 229 native "ServerSocket_CreateBindListen"; |
| 242 | 230 |
| 243 void set connectionHandler(void callback(Socket connection)) { | 231 void set connectionHandler(void callback(Socket connection)) { |
| 244 _clientConnectionHandler = callback; | 232 _clientConnectionHandler = callback; |
| 245 _setHandler(_IN_EVENT, | 233 _setHandler(_IN_EVENT, |
| 246 _clientConnectionHandler != null ? _connectionHandler : null); | 234 _clientConnectionHandler != null ? _connectionHandler : null); |
| 247 } | 235 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 } | 349 } |
| 362 } | 350 } |
| 363 | 351 |
| 364 bool _createConnect(String host, int port) native "Socket_CreateConnect"; | 352 bool _createConnect(String host, int port) native "Socket_CreateConnect"; |
| 365 | 353 |
| 366 void set writeHandler(void callback()) { | 354 void set writeHandler(void callback()) { |
| 367 _setHandler(_OUT_EVENT, callback); | 355 _setHandler(_OUT_EVENT, callback); |
| 368 } | 356 } |
| 369 | 357 |
| 370 void set connectHandler(void callback()) { | 358 void set connectHandler(void callback()) { |
| 359 // TODO(ager): Make sure that write handler and connect handler do |
| 360 // not compete for the out events. |
| 371 _setHandler(_OUT_EVENT, callback); | 361 _setHandler(_OUT_EVENT, callback); |
| 372 } | 362 } |
| 373 | 363 |
| 374 void set dataHandler(void callback()) { | 364 void set dataHandler(void callback()) { |
| 375 _setHandler(_IN_EVENT, callback); | 365 _setHandler(_IN_EVENT, callback); |
| 376 } | 366 } |
| 377 | 367 |
| 378 void set closeHandler(void callback()) { | 368 void set closeHandler(void callback()) { |
| 379 _setHandler(_CLOSE_EVENT, callback); | 369 _setHandler(_CLOSE_EVENT, callback); |
| 380 } | 370 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 396 return _outputStream; | 386 return _outputStream; |
| 397 } | 387 } |
| 398 | 388 |
| 399 bool _closedRead = false; | 389 bool _closedRead = false; |
| 400 bool _closedWrite = false; | 390 bool _closedWrite = false; |
| 401 bool _pipe = false; | 391 bool _pipe = false; |
| 402 SocketInputStream _inputStream; | 392 SocketInputStream _inputStream; |
| 403 SocketOutputStream _outputStream; | 393 SocketOutputStream _outputStream; |
| 404 } | 394 } |
| 405 | 395 |
| OLD | NEW |