Skip to content

Commit 84d8d4f

Browse files
author
Jason Kridner
committed
Attempted to add epoll, but getting segfault
Test: cd bonescript node-waf configure build && node misctest.js
1 parent b235e9d commit 84d8d4f

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

.settings.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<settings version="0.0.4" ><auto><configurations debug="0" ><config path="blinkled.js" name="blinkled" extension="js" args="" /><config path="bone101.js" name="bone101" extension="js" args="" /><config path="footest.js" name="footest" extension="" args="" /><config path="input.js" name="input" extension="" args="" /></configurations><panel>{"ext/editors/editors":{"parent":{"visible":2,"flex":1},"visible":2,"flex":1},"ext/tree/tree":{"parent":{"visible":true,"width":"200"},"visible":true,"flex":1,"state":"normal"},"ext/console/console":{"parent":{"visible":2,"height":200},"visible":true,"flex":1},"ext/settings/settings":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"},"ext/openfiles/openfiles":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"}}</panel><tree_selection path="/workspace/bonescript/index.js" type="file"/><tree>["folder[1]","folder[1]/folder[2]"]</tree><console><input>this.subdir
1+
<settings version="0.0.4" ><auto><configurations debug="0" ><config path="blinkled.js" name="blinkled" extension="js" args="" /><config path="bone101.js" name="bone101" extension="js" args="" /><config path="footest.js" name="footest" extension="" args="" /><config path="input.js" name="input" extension="" args="" /></configurations><panel>{"ext/editors/editors":{"parent":{"visible":2,"flex":1},"visible":2,"flex":1},"ext/tree/tree":{"parent":{"visible":true,"width":"200"},"visible":true,"flex":1,"state":"normal"},"ext/console/console":{"parent":{"visible":2,"height":200},"visible":true,"flex":1},"ext/settings/settings":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"},"ext/openfiles/openfiles":{"parent":{"visible":true,"width":"200"},"visible":false,"flex":1,"state":"normal"}}</panel><tree_selection path="/workspace/bonescript/misctest.js" type="file"/><tree>["folder[1]","folder[1]/folder[2]"]</tree><console><input>this.subdir
22

33

4-
</input></console><customtypes/><zen>0.7</zen><recentfiles>[{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"wscript","value":"/workspace/bonescript/wscript"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"LICENSE","value":"/workspace/LICENSE"},{"caption":"bone.js","value":"/workspace/bonescript/bone.js"},{"caption":"polltest.c","value":"/workspace/bonescript/polltest.c"}]</recentfiles><extensions/><files active="/workspace/bonescript/index.js"><file path="/workspace/bonescript/index.js" type="file" size="19177" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Thu, 03 May 2012 14:43:58 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js" changed="0" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:10,&quot;column&quot;:29},&quot;end&quot;:{&quot;row&quot;:10,&quot;column&quot;:29}}}"/><file name="input.js" path="/workspace/input.js" scriptname="/var/lib/cloud9/input.js" oldpath="/workspace/input.js" modifieddate="Thu, 03 May 2012 14:42:27 +0100" changed="0" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:10,&quot;column&quot;:20},&quot;end&quot;:{&quot;row&quot;:10,&quot;column&quot;:20}}}"/><file type="file" name="polltest.c" path="/workspace/polltest.c" scriptname="/var/lib/cloud9/polltest.c" modifieddate="Thu, 03 May 2012 14:42:27 +0100" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:29,&quot;column&quot;:15},&quot;end&quot;:{&quot;row&quot;:29,&quot;column&quot;:15}}}"/><file path="/workspace/blinkled.js" type="file" size="364" name="blinkled.js" contenttype="application/javascript; charset=utf-8" modifieddate="Thu, 03 May 2012 14:42:27 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/blinkled.js" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:10,&quot;column&quot;:19},&quot;end&quot;:{&quot;row&quot;:10,&quot;column&quot;:19}}}"/><file name="misc.cpp" path="/workspace/bonescript/misc.cpp" scriptname="/var/lib/cloud9/bonescript/misc.cpp" oldpath="/workspace/Untitled1" modifieddate="Thu, 03 May 2012 14:42:27 +0100" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:14,&quot;column&quot;:1},&quot;end&quot;:{&quot;row&quot;:14,&quot;column&quot;:1}}}"/><file name="wscript" path="/workspace/bonescript/wscript" scriptname="/var/lib/cloud9/bonescript/wscript" oldpath="/workspace/Untitled1" modifieddate="Thu, 03 May 2012 14:42:27 +0100" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:25,&quot;column&quot;:46},&quot;end&quot;:{&quot;row&quot;:25,&quot;column&quot;:46}}}"/><file name="footest.js" path="/workspace/footest.js" scriptname="/var/lib/cloud9/footest.js" oldpath="/workspace/footest.js" modifieddate="Thu, 03 May 2012 14:42:27 +0100" changed="0" state="{&quot;scrolltop&quot;:0,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:2,&quot;column&quot;:23},&quot;end&quot;:{&quot;row&quot;:2,&quot;column&quot;:23}}}"/></files></auto><general name="General" saveallbeforerun="true" openfiles="true"/><beautify name="Beautify"><jsbeautify name="JS Beautify" preserveemptylines="true" keeparrayindentation="false" braces="end-expand"/></beautify><editors name="Editor"><code name="Code Editor" overwrite="false" selectstyle="line" activeline="true" showinvisibles="false" showprintmargin="true" printmargincolumn="80" softtabs="true" tabsize="4" scrollspeed="2" fontsize="12" wrapmode="false" wraplimitmin="" wraplimitmax="" gutter="true" highlightselectedword="true" autohidehorscrollbar="true"/></editors><search><word key="attachInterrupt"/><word key="rx"/><word key="analogRead"/><word key="digitalWrite"/><word key="HIGH"/><word key="output"/><word key="socket"/><word key="readFile"/><word key="pinmode"/><word key="eeproms"/><word key="eeprom"/><word key="eeproms"/><word key="socket.emit"/><word key="muxOption"/><word key="ex"/><word key="export"/><word key="getpinmode"/><word key="omap_mux"/><word key="readout"/><word key="omap_mux"/><word key="muxstruct"/><word key="socket.emit"/><word key="mode"/><word key="socket"/><word key="spawn"/><word key="socket.on"/><word key="fibers"/><word key="pinObject"/><word key="pull"/><word key="pinmode"/><word key="events"/><word key="gpmc_ben1"/><word key="opensync"/></search><breakpoints /></settings>
4+
</input></console><customtypes/><zen>0.7</zen><recentfiles>[{"caption":"misc.cpp","value":"/workspace/bonescript/misc.cpp"},{"caption":"misctest.js","value":"/workspace/bonescript/misctest.js"},{"caption":"footest.js","value":"/workspace/footest.js"},{"caption":"input.js","value":"/workspace/input.js"},{"caption":"index.js","value":"/workspace/bonescript/index.js"},{"caption":"epolltest.c","value":"/workspace/epolltest.c"},{"caption":"blinkled.js","value":"/workspace/blinkled.js"},{"caption":"polltest.c","value":"/workspace/polltest.c"},{"caption":"wscript","value":"/workspace/bonescript/wscript"},{"caption":"LICENSE","value":"/workspace/LICENSE"}]</recentfiles><extensions/><files active="/workspace/bonescript/misc.cpp"><file path="/workspace/bonescript/index.js" type="file" size="19586" name="index.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/index.js"/><file path="/workspace/input.js" type="file" size="745" name="input.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/input.js" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:0,&quot;column&quot;:0},&quot;end&quot;:{&quot;row&quot;:0,&quot;column&quot;:0}}}"/><file path="/workspace/blinkled.js" type="file" size="364" name="blinkled.js" contenttype="application/javascript; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/blinkled.js"/><file path="/workspace/bonescript/misc.cpp" type="file" size="1372" name="misc.cpp" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 03:22:37 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/bonescript/misc.cpp" changed="1" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:71,&quot;column&quot;:11},&quot;end&quot;:{&quot;row&quot;:71,&quot;column&quot;:11}}}"/><file path="/workspace/epolltest.c" type="file" size="1012" name="epolltest.c" contenttype="text/x-c; charset=utf-8" modifieddate="Fri, 04 May 2012 02:29:54 +0100" creationdate="" lockable="false" hidden="false" executable="false" scriptname="/var/lib/cloud9/epolltest.c" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:20,&quot;column&quot;:20},&quot;end&quot;:{&quot;row&quot;:20,&quot;column&quot;:20}}}"/><file type="file" name="misctest.js" path="/workspace/bonescript/misctest.js" scriptname="/var/lib/cloud9/bonescript/misctest.js" changed="0" modifieddate="Fri, 04 May 2012 03:04:13 +0100" state="{&quot;scrolltop&quot;:775,&quot;scrollleft&quot;:0,&quot;selection&quot;:{&quot;start&quot;:{&quot;row&quot;:3,&quot;column&quot;:42},&quot;end&quot;:{&quot;row&quot;:3,&quot;column&quot;:42}}}"/></files></auto><general name="General" saveallbeforerun="true" openfiles="true"/><beautify name="Beautify"><jsbeautify name="JS Beautify" preserveemptylines="true" keeparrayindentation="false" braces="end-expand"/></beautify><editors name="Editor"><code name="Code Editor" overwrite="false" selectstyle="line" activeline="true" showinvisibles="false" showprintmargin="true" printmargincolumn="80" softtabs="true" tabsize="4" scrollspeed="2" fontsize="12" wrapmode="false" wraplimitmin="" wraplimitmax="" gutter="true" highlightselectedword="true" autohidehorscrollbar="true"/></editors><search><word key="attachInterrupt"/><word key="rx"/><word key="analogRead"/><word key="digitalWrite"/><word key="HIGH"/><word key="output"/><word key="socket"/><word key="readFile"/><word key="pinmode"/><word key="eeproms"/><word key="eeprom"/><word key="eeproms"/><word key="socket.emit"/><word key="muxOption"/><word key="ex"/><word key="export"/><word key="getpinmode"/><word key="omap_mux"/><word key="readout"/><word key="omap_mux"/><word key="muxstruct"/><word key="socket.emit"/><word key="mode"/><word key="socket"/><word key="spawn"/><word key="socket.on"/><word key="fibers"/><word key="pinObject"/><word key="pull"/><word key="pinmode"/><word key="events"/><word key="gpmc_ben1"/><word key="opensync"/></search><breakpoints /></settings>

bonescript/misc.cpp

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
#include <fcntl.h>
77
#include <sys/epoll.h>
88
#include <sys/types.h>
9+
#include <stdio.h>
10+
#include <errno.h>
911

1012
using namespace std;
1113
using namespace node;
1214
using namespace v8;
1315

1416
static Handle<Value> PollpriAsync(const Arguments&);
1517
static int Pollpri(eio_req *);
16-
static int PollpriAfter(eio_req *);
18+
//static int PollpriAfter(eio_req *);
19+
static void PollpriAfter(ev_io* req, int revents);
1720
extern "C" void init(Handle<Object>);
1821

1922
struct pollpri_request {
@@ -36,26 +39,45 @@ static Handle<Value> PollpriAsync(const Arguments& args) {
3639
pr->cb = Persistent<Function>::New(cb);
3740
strncpy(pr->path, *path, path.length() + 1);
3841

39-
eio_custom(Pollpri, EIO_PRI_DEFAULT, PollpriAfter, pr);
40-
ev_ref(EV_DEFAULT_UC);
42+
int epfd = epoll_create(1);
43+
int fd = open(pr->path, O_RDWR | O_NONBLOCK);
44+
printf("open(%s) returned %d: %s\n", pr->path, fd, strerror(errno));
45+
struct epoll_event ev;
46+
struct epoll_event events;
47+
ev.events = EPOLLPRI;
48+
ev.data.fd = fd;
49+
int n = epoll_ctl(epfd, EPOLL_CTL_ADD, fd, &ev);
50+
printf("epoll_ctl(%d) returned %d (%d): %s\n", fd, n, epfd, strerror(errno));
51+
ev_io pollpri_watcher;
52+
ev_init(&pollpri_watcher, PollpriAfter);
53+
pollpri_watcher.data = pr;
54+
ev_io_set(&pollpri_watcher, epfd, EV_READ);
55+
ev_io_start(EV_DEFAULT_ &pollpri_watcher);
56+
57+
//eio_custom(Pollpri, EIO_PRI_DEFAULT, PollpriAfter, pr);
58+
//ev_ref(EV_DEFAULT_UC);
59+
printf("Leaving PollpriAsync\n");
4160
return(Undefined());
4261
}
4362

4463
static int Pollpri(eio_req *req) {
4564
struct pollpri_request * pr = (struct pollpri_request *)req->data;
65+
printf("Entered Pollpri\n");
4666
return(0);
4767
}
4868

49-
static int PollpriAfter(eio_req *req) {
69+
//static int PollpriAfter(eio_req *req) {
70+
static void PollpriAfter(ev_io* req, int revents) {
71+
printf("Entered PollpriAfter\n");
5072
HandleScope scope;
51-
ev_unref(EV_DEFAULT_UC);
73+
//ev_unref(EV_DEFAULT_UC);
5274
struct pollpri_request * pr = (struct pollpri_request *)req->data;
5375
Local<Value> argv[2];
5476
argv[0] = Local<Value>::New(Null());
5577
argv[1] = String::New(pr->path);
5678
pr->cb->Call(Context::GetCurrent()->Global(), 2, argv);
57-
pr->cb.Dispose();
58-
free(pr);
79+
//pr->cb.Dispose();
80+
//free(pr);
5981
}
6082

6183
extern "C" void init(Handle<Object> target) {

bonescript/misctest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
var misc = require('./misc');
22

33
console.log('Calling pollpri');
4-
misc.pollpri('my path', function(err, data) {
4+
misc.pollpri('/sys/class/gpio/gpio34/value', function(err, data) {
55
console.log(''+data);
66
});

0 commit comments

Comments
 (0)