Skip to content

Instantly share code, notes, and snippets.

View bnoordhuis's full-sized avatar

Ben Noordhuis bnoordhuis

View GitHub Profile
@bnoordhuis
bnoordhuis / cpuid.c
Created September 13, 2012 16:21
print cpuid info
/*
* Copyright (c) 2012, Ben Noordhuis <info@bnoordhuis.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
@bnoordhuis
bnoordhuis / echo.js
Created September 11, 2012 22:46
simple net + child process echo server
var child_process = require('child_process');
var net = require('net');
var server = net.createServer(function(conn) {
var proc = child_process.spawn('cat', [], { stdio: 'pipe' });
conn.pipe(proc.stdin);
proc.stdout.pipe(conn);
});
server.listen(8000);
@bnoordhuis
bnoordhuis / wq.c
Created August 31, 2012 23:24
[libuv] serialized work queue
#include "ngx-queue.h"
#include "uv.h"
struct work
{
ngx_queue_t wq;
uv_work_t req;
int your_data;
};
@bnoordhuis
bnoordhuis / fioclex.c
Created August 21, 2012 21:12
test ioctl() vs fcntl() syscall speed
// cc -O fioclex.c
// USE_IOCTL=0 time ./a.out
// USE_IOCTL=1 time ./a.out
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
var a = [0, 5, 2, 1, 3];
var p = 2; // pivot
function diff(a, b) {
return Math.abs(a - b);
}
function sort(a, b) {
var ax = diff(a, p);
var bx = diff(b, p);
@bnoordhuis
bnoordhuis / tcp-self-connect.c
Created June 11, 2012 14:12
Create an AF_INET socket and connect() it to itself
/*
* Copyright (c) 2012, Ben Noordhuis <info@bnoordhuis.nl>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static char **make_copy(int argc, char **argv)
{
size_t strlen_sum;
char **argp;
char *data;
size_t len;
@bnoordhuis
bnoordhuis / vcbuild.patch
Created February 17, 2012 14:37
multi-core msbuild
diff --git a/vcbuild.bat b/vcbuild.bat
index f6d0fef..54f579d 100644
--- a/vcbuild.bat
+++ b/vcbuild.bat
@@ -91,7 +91,7 @@ goto run
:msbuild-found
@rem Build the sln with msbuild.
-msbuild node.sln /t:%target% /p:Configuration=%config% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
+msbuild node.sln /m /t:%target% /p:Configuration=%config% /clp:NoSummary;NoItemAndPropertyList;Verbosity=minimal /nologo
diff --git a/lib/net.js b/lib/net.js
index f98bcfc..64c4dfd 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -569,8 +569,7 @@ Socket.prototype.connect = function(port /* [host], [cb] */) {
// There are no event listeners registered yet so defer the
// error event to the next tick.
process.nextTick(function() {
- self.emit('error', err);
- self.destroy();