Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Rewrite libeio After callback to use req->result instead of req->erro…
Browse files Browse the repository at this point in the history
…rno for error checking

Conflicts:

	src/node_file.cc
  • Loading branch information
ry committed Nov 16, 2010
1 parent ae20874 commit b6eedde
Showing 1 changed file with 38 additions and 52 deletions.
90 changes: 38 additions & 52 deletions src/node_file.cc
Expand Up @@ -43,33 +43,28 @@ static int After(eio_req *req) {

ev_unref(EV_DEFAULT_UC);

int argc = 0;
Local<Value> argv[6]; // 6 is the maximum number of args

if (req->errorno != 0) {
argc = 1;
switch (req->type) {
case EIO_STAT:
case EIO_LSTAT:
case EIO_LINK:
case EIO_UNLINK:
case EIO_RMDIR:
case EIO_RENAME:
case EIO_READLINK:
case EIO_OPEN:
case EIO_CHMOD:
case EIO_CHOWN:
case EIO_MKDIR:
argv[0] = ErrnoException(req->errorno, NULL, "", static_cast<const char*>(req->ptr1));
break;
default:
argv[0] = ErrnoException(req->errorno);
// there is always at least one argument. "error"
int argc = 1;
Local<Value> argv[2]; // 6 is the maximum number of args

// NOTE: This may be needed to be changed if something returns a -1
// for a success, which is possible.
if (req->result == -1) {
// If the request doesn't have a path parameter set.
if (!req->ptr1) {
argv[0] = ErrnoException(req->errorno);
} else {
argv[0] = ErrnoException(req->errorno, NULL, "", static_cast<const char*>(req->ptr1));
}
} else {
// Note: the error is always given the first argument of the callback.
// If there is no error then then the first argument is null.
// error value is empty or null for non-error.
argv[0] = Local<Value>::New(Null());

// All have at least two args now.
argc = 2;

switch (req->type) {
// These all have no data to pass.
case EIO_CLOSE:
case EIO_RENAME:
case EIO_UNLINK:
Expand All @@ -82,68 +77,59 @@ static int After(eio_req *req) {
case EIO_SYMLINK:
case EIO_CHMOD:
case EIO_CHOWN:
argc = 0;
// These, however, don't.
argc = 1;
break;

case EIO_OPEN:
case EIO_SENDFILE:
argc = 2;
argv[1] = Integer::New(req->result);
break;

case EIO_WRITE:
argc = 2;
argv[1] = Integer::New(req->result);
break;

case EIO_STAT:
case EIO_LSTAT:
case EIO_FSTAT:
{
struct stat *s = reinterpret_cast<struct stat*>(req->ptr2);
argc = 2;
argv[1] = BuildStatsObject(s);
{
struct stat *s = reinterpret_cast<struct stat*>(req->ptr2);
argv[1] = BuildStatsObject(s);
}
break;
}

case EIO_READLINK:
{
argc = 2;
argv[1] = String::New(static_cast<char*>(req->ptr2), req->result);
break;
}

case EIO_READ:
{
// Buffer interface
argv[1] = Integer::New(req->result);
argc = 2;
break;
}

case EIO_READDIR:
{
char *namebuf = static_cast<char*>(req->ptr2);
int nnames = req->result;
{
char *namebuf = static_cast<char*>(req->ptr2);
int nnames = req->result;

Local<Array> names = Array::New(nnames);
Local<Array> names = Array::New(nnames);

for (int i = 0; i < nnames; i++) {
Local<String> name = String::New(namebuf);
names->Set(Integer::New(i), name);
for (int i = 0; i < nnames; i++) {
Local<String> name = String::New(namebuf);
names->Set(Integer::New(i), name);
#ifndef NDEBUG
namebuf += strlen(namebuf);
assert(*namebuf == '\0');
namebuf += 1;
namebuf += strlen(namebuf);
assert(*namebuf == '\0');
namebuf += 1;
#else
namebuf += strlen(namebuf) + 1;
namebuf += strlen(namebuf) + 1;
#endif
}
}

argc = 2;
argv[1] = names;
argv[1] = names;
}
break;
}

default:
assert(0 && "Unhandled eio response");
Expand Down

0 comments on commit b6eedde

Please sign in to comment.