Browse Source

net_uv: shim up more methods

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
e697cfb6fc
  1. 59
      lib/net_uv.js

59
lib/net_uv.js

@ -14,13 +14,25 @@ if (process.env.NODE_DEBUG && /net/.test(process.env.NODE_DEBUG)) {
}
exports.createServer = function() {
return new Server(arguments[0], arguments[1]);
};
exports.connect = exports.createConnection = function(port, host) {
var s = new Socket();
s.connect(port, host);
return s;
};
function Socket(options) {
if (!(this instanceof Socket)) return new Socket(options);
stream.Stream.call(this);
// private
if (options.handle) {
if (options && options.handle) {
this._handle = options.handle;
} else {
this._handle = new TCP();
@ -46,6 +58,39 @@ Socket.prototype.setTimeout = function(msecs, callback) {
};
Socket.prototype.setNoDelay = function() {
/* TODO implement me */
};
Object.defineProperty(Socket.prototype, 'readyState', {
get: function() {
if (this._connecting) {
return 'opening';
} else if (this.readable && this.writable) {
assert(typeof this.fd === 'number');
return 'open';
} else if (this.readable && !this.writable) {
assert(typeof this.fd === 'number');
return 'readOnly';
} else if (!this.readable && this.writable) {
assert(typeof this.fd === 'number');
return 'writeOnly';
} else {
assert(typeof this.fd !== 'number');
return 'closed';
}
}
});
Object.defineProperty(Socket.prototype, 'bufferSize', {
get: function() {
return this._handle.writeQueueSize;
}
});
Socket.prototype.pause = function() {
this._handle.readStop();
};
@ -204,6 +249,8 @@ Socket.prototype.connect = function(port, host) {
throw new Error("ipv6 addresses not yet supported by libuv");
}
ip = ip || '127.0.0.1';
self.remoteAddress = ip;
self.remotePort = port;
@ -214,11 +261,11 @@ Socket.prototype.connect = function(port, host) {
self._connectReq = self._handle.connect(ip, port);
if (!self._connectReq) {
if (self._connectReq) {
self._connectReq.oncomplete = afterConnect;
} else {
self.destroy(errnoException(errno, 'connect'));
}
self._connectReq.oncomplete = afterConnect;
}
});
};
@ -330,8 +377,12 @@ function onconnection(clientHandle) {
var self = handle.socket;
var socket = new Socket({ handle: clientHandle });
socket.readable = socket.writable = true;
socket.resume();
self.connections++;
socket.server = self;
DTRACE_NET_SERVER_CONNECTION(socket);
self.emit('connection', socket);
}

Loading…
Cancel
Save