Tcp.hx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. public function noDelay(b:Bool) {
  22. tcp_nodelay_wrap(handle, b);
  23. }
  24. static function tcp_init_wrap( loop : Loop ) : HandleData {
  25. return null;
  26. }
  27. static function tcp_connect_wrap( h : HandleData, host : Int, port : Int, onConnected : Bool -> Void ) : HandleData {
  28. return null;
  29. }
  30. static function tcp_bind_wrap( h : HandleData, host : Int, port : Int ) : Bool {
  31. return false;
  32. }
  33. static function tcp_accept_wrap( h : HandleData ) : HandleData {
  34. return null;
  35. }
  36. static function tcp_nodelay_wrap( h : HandleData, b : Bool ) : Void {
  37. }
  38. }