Permalink
Browse files

one domain per incoming data chunk :) MWAHAHA, MAD SCIENCE!

  • Loading branch information...
1 parent 144db92 commit 0e6f7bd4378a711c882ee250e6309c62e625f1f0 @thejh committed Dec 4, 2011
Showing with 28 additions and 14 deletions.
  1. +28 −14 lib/net.js
View
@@ -347,24 +347,38 @@ function onread(buffer, offset, length) {
// Emit 'data' event.
var data = buffer.slice(offset, end);
-
- if (Socket.genericEmitter != null) {
- Socket.genericEmitter.emit('data', self, data);
- }
-
- if (self._decoder) {
- // Emit a string.
- var string = self._decoder.write(data);
- if (string.length) self.emit('data', string);
+ var eventId;
+
+ if (Socket.eventDomains) {
+ eventId = Math.random();
+ var domain = domains.create(null, emitEvent);
+ // FIXME ugly, ugly, ugly hack
+ process.nextTick(function(){});
+ domain.eventId = eventId;
+ domain.isNetDataEventDomain = true;
} else {
- // Emit a slice.
- self.emit('data', data);
+ emitEvent()
}
- self.bytesRead += length;
+ function emitEvent() {
+ if (Socket.genericEmitter != null) {
+ Socket.genericEmitter.emit('data', self, data, eventId);
+ }
- // Optimization: emit the original buffer with end points
- if (self.ondata) self.ondata(buffer, offset, end);
+ if (self._decoder) {
+ // Emit a string.
+ var string = self._decoder.write(data);
+ if (string.length) self.emit('data', string);
+ } else {
+ // Emit a slice.
+ self.emit('data', data);
+ }
+
+ self.bytesRead += length;
+
+ // Optimization: emit the original buffer with end points
+ if (self.ondata) self.ondata(buffer, offset, end);
+ }
} else if (errno == 'EOF') {
// EOF

0 comments on commit 0e6f7bd

Please sign in to comment.