Browse Source

Remove send fd functionality

It was broken anyway. It will go into its own class later.
v0.7.4-release
Ryan Dahl 15 years ago
parent
commit
f8c3b6009d
  1. 66
      lib/net.js

66
lib/net.js

@ -23,8 +23,6 @@ var accept = binding.accept;
var close = binding.close; var close = binding.close;
var shutdown = binding.shutdown; var shutdown = binding.shutdown;
var read = binding.read; var read = binding.read;
var recvMsg = binding.recvMsg;
var sendFD = binding.sendFD;
var write = binding.write; var write = binding.write;
var toRead = binding.toRead; var toRead = binding.toRead;
var setNoDelay = binding.setNoDelay; var setNoDelay = binding.setNoDelay;
@ -248,13 +246,11 @@ function _doFlush () {
var socket = this.socket; var socket = this.socket;
// Stream becomes writeable on connect() but don't flush if there's // Stream becomes writeable on connect() but don't flush if there's
// nothing actually to write // nothing actually to write
if ((socket._writeQueueSize == 0) && (socket._writeMessageQueueSize == 0)) { if (socket._writeQueueSize == 0) {
return; return;
} }
if (socket.flush()) { if (socket.flush()) {
assert(socket._writeQueueSize == 0); assert(socket._writeQueueSize == 0);
assert(socket._writeMessageQueueSize == 0);
if (socket._events && socket._events['drain']) socket.emit("drain"); if (socket._events && socket._events['drain']) socket.emit("drain");
if (socket.ondrain) socket.ondrain(); // Optimization if (socket.ondrain) socket.ondrain(); // Optimization
} }
@ -280,21 +276,10 @@ function initStream (self) {
var bytesRead; var bytesRead;
try { try {
if (self.type == "unix") {
bytesRead = recvMsg(self.fd,
recvBuffer,
recvBuffer.used,
recvBuffer.length - recvBuffer.used);
//debug('recvMsg.fd ' + recvMsg.fd);
if (recvMsg.fd) {
self.emit('fd', recvMsg.fd);
}
} else {
bytesRead = read(self.fd, bytesRead = read(self.fd,
recvBuffer, recvBuffer,
recvBuffer.used, recvBuffer.used,
recvBuffer.length - recvBuffer.used); recvBuffer.length - recvBuffer.used);
}
} catch (e) { } catch (e) {
self.forceClose(e); self.forceClose(e);
return; return;
@ -302,7 +287,7 @@ function initStream (self) {
//debug('bytesRead ' + bytesRead + '\n'); //debug('bytesRead ' + bytesRead + '\n');
if (!recvMsg.fd && bytesRead == 0) { if (bytesRead == 0) {
self.readable = false; self.readable = false;
self._readWatcher.stop(); self._readWatcher.stop();
@ -351,7 +336,6 @@ function initStream (self) {
self._writeQueue = []; // queue of buffers that need to be written to socket self._writeQueue = []; // queue of buffers that need to be written to socket
// XXX use link list? // XXX use link list?
self._writeQueueSize = 0; // in bytes, not to be confused with _writeQueue.length! self._writeQueueSize = 0; // in bytes, not to be confused with _writeQueue.length!
self._writeMessageQueueSize = 0; // number of messages remaining to be sent
self._writeWatcher = ioWatchers.alloc(); self._writeWatcher = ioWatchers.alloc();
self._writeWatcher.socket = self; self._writeWatcher.socket = self;
@ -442,30 +426,17 @@ Stream.prototype._writeString = function (data, encoding) {
var charsWritten; var charsWritten;
var bytesWritten; var bytesWritten;
// The special encoding "fd" means that data is an integer FD and we want if (encoding.toLowerCase() == 'utf8') {
// to pass the FD on the socket with sendmsg()
if (encoding == "fd") {
buffer.isFd = true;
// TODO is this OK -- does it guarantee that the fd is the only thing in the buffer?
charsWritten = buffer.asciiWrite(data, buffer.used, buffer.length - buffer.used);
bytesWritten = charsWritten;
} else if (encoding.toLowerCase() == 'utf8') {
buffer.isFd = false;
charsWritten = buffer.utf8Write(data, buffer.used); charsWritten = buffer.utf8Write(data, buffer.used);
bytesWritten = Buffer.utf8ByteLength(data.slice(0, charsWritten)); bytesWritten = Buffer.utf8ByteLength(data.slice(0, charsWritten));
} else { } else {
// ascii // ascii
buffer.isFd = false;
charsWritten = buffer.asciiWrite(data, buffer.used); charsWritten = buffer.asciiWrite(data, buffer.used);
bytesWritten = charsWritten; bytesWritten = charsWritten;
} }
buffer.used += bytesWritten; buffer.used += bytesWritten;
if (buffer.isFd) {
self._writeMessageQueueSize += 1;
} else {
self._writeQueueSize += bytesWritten; self._writeQueueSize += bytesWritten;
}
//debug('charsWritten ' + charsWritten); //debug('charsWritten ' + charsWritten);
//debug('buffer.used ' + buffer.used); //debug('buffer.used ' + buffer.used);
@ -596,28 +567,6 @@ Stream.prototype._writeQueued = function (data, encoding) {
return this.flush(); return this.flush();
}; };
// Sends a file descriptor over a unix socket
Stream.prototype.sendFD = function(socketToPass) {
var self = this;
if (!self.writable) throw new Error('Stream is not writable');
if (self.__writeQueueLast() == END_OF_FILE) {
throw new Error('socket.close() called already; cannot write.');
}
if (self.type != "unix") {
throw new Error('FD passing only available on unix sockets');
}
if (! socketToPass instanceof Stream) {
throw new Error('Provided arg is not a socket');
}
return self.write(socketToPass.fd.toString(), "fd");
};
// Flushes the write buffer out. // Flushes the write buffer out.
// Returns true if the entire buffer was flushed. // Returns true if the entire buffer was flushed.
Stream.prototype.flush = function () { Stream.prototype.flush = function () {
@ -644,15 +593,10 @@ Stream.prototype.flush = function () {
var fdToSend = null; var fdToSend = null;
try { try {
if (b.isFd) {
fdToSend = parseInt(b.asciiSlice(b.sent, b.used - b.sent));
bytesWritten = writeFD(self.fd, fdToSend);
} else {
bytesWritten = write(self.fd, bytesWritten = write(self.fd,
b, b,
b.sent, b.sent,
b.used - b.sent); b.used - b.sent);
}
} catch (e) { } catch (e) {
self.forceClose(e); self.forceClose(e);
return false; return false;
@ -667,10 +611,6 @@ Stream.prototype.flush = function () {
self._writeWatcher.start(); self._writeWatcher.start();
assert(self._writeQueueSize > 0); assert(self._writeQueueSize > 0);
return false; return false;
} else if (b.isFd) {
b.sent = b.used;
self._writeMessageQueueSize -= 1;
//debug('sent fd: ' + fdToSend);
} else { } else {
b.sent += bytesWritten; b.sent += bytesWritten;
self._writeQueueSize -= bytesWritten; self._writeQueueSize -= bytesWritten;

Loading…
Cancel
Save