Rewrite libeio After callback to use req->result instead of req->errorno for error checking

Conflicts:

	src/node_file.cc
This commit is contained in:
Ryan Dahl committed 2010-11-16 10:36:46 -08:00
1 parent ae2087460b
commit b6eeddeb17
1 file changed
+37 -51
+37 -51
View File
@@ -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
// there is always at least one argument. "error"
int argc = 1;
Local<Value> argv[2]; // 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);
// 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:
@@ -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");