Tcp.hx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package hl.uv;
  2. @:hlNative("uv")
  3. class Tcp extends Stream {
  4. public function new( ?loop : Loop ) {
  5. if( loop == null ) loop = Loop.getDefault();
  6. super(tcp_init_wrap(loop));
  7. }
  8. public function connect( host : sys.net.Host, port : Int, onConnected : Bool -> Void ) {
  9. var h = tcp_connect_wrap(handle, host.ip, port, onConnected);
  10. if( h == null ) throw haxe.io.Error.Custom("Failed to connect to "+host+":"+port);
  11. }
  12. public function bind( host : sys.net.Host, port : Int ) {
  13. if( !tcp_bind_wrap(handle, host.ip, port) )
  14. throw haxe.io.Error.Custom("Failed to bind socket to "+host+":"+port);
  15. }
  16. public function accept() {
  17. var client = handle == null ? null : tcp_accept_wrap(handle);
  18. if( client == null ) throw new haxe.io.Eof();
  19. return new Stream(client);
  20. }
  21. static function tcp_init_wrap( loop : Loop ) : HandleData {
  22. return null;
  23. }
  24. static function tcp_connect_wrap( h : HandleData, host : Int, port : Int, onConnected : Bool -> Void ) : HandleData {
  25. return null;
  26. }
  27. static function tcp_bind_wrap( h : HandleData, host : Int, port : Int ) : Bool {
  28. return false;
  29. }
  30. static function tcp_accept_wrap( h : HandleData ) : HandleData {
  31. return null;
  32. }
  33. }