Skip to content

Instantly share code, notes, and snippets.

View piscisaureus's full-sized avatar
🦕

Bert Belder piscisaureus

🦕
View GitHub Profile
static ev_io watcher;
static void stdin_cb (EV_P_ ev_io *w, int revents) {
puts("you can now read some data");
ev_io_stop(&watcher);
}
int main() {
...
@piscisaureus
piscisaureus / daemonize.c
Created April 3, 2012 22:14
daemonize.c
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
void set_cloexec(int fd) {
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
void set_cloexec(int fd) {
var spawn = require('child_process').spawn;
// spawn_detached(file, [args = []], [options = {}], [callback]);
function spawn_detached(file, args, options, callback) {
if (arguments.length == 2 &&
typeof args == 'function') {
callback = arguments[1];
args = undefined;
}
var capture = "";
var cmd = require('child_process').spawn('cmd');
process.stdin.pipe(cmd.stdin);
cmd.stdout.pipe(process.stdout);
cmd.stderr.pipe(process.stderr);
cmd.stdout.on('data', function(data) {
capture += data.toString();
// This is a flaky webserver that introduces random weirdness and errors.
// It randomly pauses and resumes.
// It also writes out data in random-sized bursts with random delays.
var clientIdCounter = 0;
// Generate a 128k random data buffer
template <typename T>
class UvHandle {
T handle_;
public:
T* handle() { return &handle_; }
protected:
static void OnClose();
static Value* Close(uint32_t argc, Arguments& argv);
};
From d79af7ad612f1d9620338ebdb72f407961f0bc1f Mon Sep 17 00:00:00 2001
From: Bert Belder <[email protected]>
Date: Mon, 12 Mar 2012 21:10:25 +0100
Subject: [PATCH 1/1] Make inherited pipe handles non-inheritable to child
processes.
---
src/win/pipe.c | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
var fs = require('fs'),
path = require('path');
// Create a buffer of some size
var buf = new Buffer(1024);
buf.fill(66);
// This will fail
try {
fs.statSync('test/test2/file20');
From 8d938b2de6ecb291713ddf6ee4f79e9e0c871b93 Mon Sep 17 00:00:00 2001
From: Bert Belder <[email protected]>
Date: Thu, 8 Mar 2012 00:13:44 +0100
Subject: [PATCH 1/1] Windows: include syscall in fs errors
---
src/node_file.cc | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/src/node_file.cc b/src/node_file.cc