Skip to content

Commit e697cfb

Browse files
committed
net_uv: shim up more methods
1 parent 52b517c commit e697cfb

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

lib/net_uv.js

+55-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,25 @@ if (process.env.NODE_DEBUG && /net/.test(process.env.NODE_DEBUG)) {
1414
}
1515

1616

17+
exports.createServer = function() {
18+
return new Server(arguments[0], arguments[1]);
19+
};
20+
21+
22+
exports.connect = exports.createConnection = function(port, host) {
23+
var s = new Socket();
24+
s.connect(port, host);
25+
return s;
26+
};
27+
28+
1729
function Socket(options) {
1830
if (!(this instanceof Socket)) return new Socket(options);
1931

2032
stream.Stream.call(this);
2133

2234
// private
23-
if (options.handle) {
35+
if (options && options.handle) {
2436
this._handle = options.handle;
2537
} else {
2638
this._handle = new TCP();
@@ -46,6 +58,39 @@ Socket.prototype.setTimeout = function(msecs, callback) {
4658
};
4759

4860

61+
Socket.prototype.setNoDelay = function() {
62+
/* TODO implement me */
63+
};
64+
65+
66+
Object.defineProperty(Socket.prototype, 'readyState', {
67+
get: function() {
68+
if (this._connecting) {
69+
return 'opening';
70+
} else if (this.readable && this.writable) {
71+
assert(typeof this.fd === 'number');
72+
return 'open';
73+
} else if (this.readable && !this.writable) {
74+
assert(typeof this.fd === 'number');
75+
return 'readOnly';
76+
} else if (!this.readable && this.writable) {
77+
assert(typeof this.fd === 'number');
78+
return 'writeOnly';
79+
} else {
80+
assert(typeof this.fd !== 'number');
81+
return 'closed';
82+
}
83+
}
84+
});
85+
86+
87+
Object.defineProperty(Socket.prototype, 'bufferSize', {
88+
get: function() {
89+
return this._handle.writeQueueSize;
90+
}
91+
});
92+
93+
4994
Socket.prototype.pause = function() {
5095
this._handle.readStop();
5196
};
@@ -204,6 +249,8 @@ Socket.prototype.connect = function(port, host) {
204249
throw new Error("ipv6 addresses not yet supported by libuv");
205250
}
206251

252+
ip = ip || '127.0.0.1';
253+
207254
self.remoteAddress = ip;
208255
self.remotePort = port;
209256

@@ -214,11 +261,11 @@ Socket.prototype.connect = function(port, host) {
214261

215262
self._connectReq = self._handle.connect(ip, port);
216263

217-
if (!self._connectReq) {
264+
if (self._connectReq) {
265+
self._connectReq.oncomplete = afterConnect;
266+
} else {
218267
self.destroy(errnoException(errno, 'connect'));
219268
}
220-
221-
self._connectReq.oncomplete = afterConnect;
222269
}
223270
});
224271
};
@@ -330,8 +377,12 @@ function onconnection(clientHandle) {
330377
var self = handle.socket;
331378

332379
var socket = new Socket({ handle: clientHandle });
380+
socket.readable = socket.writable = true;
333381
socket.resume();
334382

383+
self.connections++;
384+
socket.server = self;
385+
335386
DTRACE_NET_SERVER_CONNECTION(socket);
336387
self.emit('connection', socket);
337388
}

0 commit comments

Comments
 (0)