Browse files

updated Socket api

  • Loading branch information...
1 parent 0a3fdeb commit 4367db7f815fed94c288801f553a8407232ec988 tong committed Jul 23, 2012
Showing with 31 additions and 15 deletions.
  1. +31 −15 chrome/experimental/Socket.hx
View
46 chrome/experimental/Socket.hx
@@ -1,25 +1,41 @@
package chrome.experimental;
-typedef SocketSendInfo = {
- var bytesWritten : Int;
+@:fakeEnum(String) enum SocketType {
+ tcp;
+ udp;
}
-typedef SocketEvent = {
- var type : Int;
- var byteCount : Int;
- var bytes : Blob;
- var errorCode : Int;
- var errorMessage : String;
+typedef CreateInfo = {
+ var socketId : Int;
}
-typedef SocketInfo = {
- var socketId : Int;
+typedef ReadInfo = {
+ var data : ArrayBuffer;
+ var resultCode : Int;
+}
+
+typedef WriteInfo = {
+ var bytesWritten : Int;
+}
+
+typedef RecvFromInfo = {
+ var address : String;
+ var data : ArrayBuffer;
+ var port : Int;
+ var resultCode : Int;
}
@:native("chrome.experimental.socket") extern class Socket {
- static function create( type : String, host : String, port : Int, options : Dynamic, cb : SocketInfo->Void ) : Void;
- static function connect( socketId : Int, cb : Dynamic->Void ) : Void;
- //static function connect( socketId : Int, hostname : String, port : Int, cb : Bool->Void ) : Void;
- static function disconnect( socketId : Int, cb : Bool->Void ) : Void;
- static function write( socketId : Int, data : String, cb : SocketSendInfo->Void ) : Void;
+ static function bind( socketId : Int, address : String, port : Int, cb : Int->Void ) : Void;
+ static function connect( socketId : Int, hostname : String, port : Int, cb : Dynamic->Void ) : Void;
+ //static function create( type : SocketType, ?options : Dynamic, cb : CreateInfo->Void ) : Void;
+ static function create( type : String, ?options : Dynamic, cb : CreateInfo->Void ) : Void;
+ static function destroy( socketId : Int ) : Void;
+ static function disconnect( socketId : Int ) : Void;
+ static function read( socketId : Int, ?bufferSize : Int, cb : ReadInfo->Void ) : Void;
+ static function recvFrom( socketId : Int, ?bufferSize : Int, cb : RecvFromInfo->Void ) : Void;
+ static function sendTo( socketId : Int, data : ArrayBuffer, address : String, port : Int, cb : WriteInfo->Void ) : Void;
+ static function setKeepAlive( socketId : Int, enable : Bool, ?delay : Int, cb : Bool->Void ) : Void;
+ static function setNoDelay( socketId : Int, ?delay : Int, cb : Bool->Void ) : Void;
+ static function write( socketId : Int, data : ArrayBuffer, cb : WriteInfo->Void ) : Void;
}

0 comments on commit 4367db7

Please sign in to comment.