コード例 #1
0
ファイル: fs_poll.c プロジェクト: KennethWilke/luv
static void luv_fs_poll_cb(uv_fs_poll_t* handle, int status, const uv_stat_t* prev, const uv_stat_t* curr) {
  lua_State* L = luv_state(handle->loop);

  // err
  luv_status(L, status);

  // prev
  if (prev) {
    luv_push_stats_table(L, prev);
  }
  else {
    lua_pushnil(L);
  }

  // curr
  if (curr) {
    luv_push_stats_table(L, curr);
  }
  else {
    lua_pushnil(L);
  }

  luv_call_callback(L, handle->data, LUV_FS_POLL, 3);
}
コード例 #2
0
ファイル: luv_fs.c プロジェクト: AndrewTsao/luvit
int luv_process_fs_result(lua_State* L, uv_fs_t* req) {
  luv_fs_ref_t* ref = req->data;

  int argc = 0;
  if (req->result == -1) {
    uv_err_t err;
    memset(&err, 0, sizeof err);
    err.code = (uv_err_code)req->errorno;
    luv_push_async_error(L, err, "after_fs", req->path);
  } else {
    lua_pushnil(L);
    switch (req->fs_type) {

      case UV_FS_CLOSE:
      case UV_FS_RENAME:
      case UV_FS_UNLINK:
      case UV_FS_RMDIR:
      case UV_FS_MKDIR:
      case UV_FS_FTRUNCATE:
      case UV_FS_FSYNC:
      case UV_FS_FDATASYNC:
      case UV_FS_LINK:
      case UV_FS_SYMLINK:
      case UV_FS_CHMOD:
      case UV_FS_FCHMOD:
      case UV_FS_CHOWN:
      case UV_FS_FCHOWN:
      case UV_FS_UTIME:
      case UV_FS_FUTIME:
        argc = 0;
        break;

      case UV_FS_OPEN:
      case UV_FS_SENDFILE:
      case UV_FS_WRITE:
        argc = 1;
        lua_pushinteger(L, req->result);
        break;

      case UV_FS_STAT:
      case UV_FS_LSTAT:
      case UV_FS_FSTAT:
        argc = 1;
        luv_push_stats_table(L, (struct stat*)req->ptr);
        break;

      case UV_FS_READLINK:
        argc = 1;
        lua_pushstring(L, (char*)req->ptr);
        break;

      case UV_FS_READ:
        argc = 2;
        lua_pushlstring(L, ref->buf, req->result);
        lua_pushinteger(L, req->result);
        free(ref->buf);
        break;

      case UV_FS_READDIR:
        {
          int i;
          char* namebuf = (char*)req->ptr;
          int nnames = req->result;

          argc = 1;
          lua_createtable(L, nnames, 0);
          for (i = 0; i < nnames; i++) {
            lua_pushstring(L, namebuf);
            lua_rawseti(L, -2, i + 1);
            namebuf += strlen(namebuf);
            assert(*namebuf == '\0');
            namebuf += 1;
          }
        }
        break;

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

  }

  return argc;

}
コード例 #3
0
ファイル: luv_fs.c プロジェクト: Theintercooler/luvit
int luv_process_fs_result(lua_State* L, uv_fs_t* req) {
  luv_fs_ref_t* ref = req->data;

  int argc = 0;
  if (req->result < 0) {
    luv_push_async_error(L, req->result, "after_fs", req->path);
  } else {
    lua_pushnil(L);
    switch (req->fs_type) {

      case UV_FS_CLOSE:
      case UV_FS_RENAME:
      case UV_FS_UNLINK:
      case UV_FS_RMDIR:
      case UV_FS_MKDIR:
      case UV_FS_FTRUNCATE:
      case UV_FS_FSYNC:
      case UV_FS_FDATASYNC:
      case UV_FS_LINK:
      case UV_FS_SYMLINK:
      case UV_FS_CHMOD:
      case UV_FS_FCHMOD:
      case UV_FS_CHOWN:
      case UV_FS_FCHOWN:
      case UV_FS_UTIME:
      case UV_FS_FUTIME:
        argc = 0;
        break;

      case UV_FS_OPEN:
      case UV_FS_SENDFILE:
      case UV_FS_WRITE:
        argc = 1;
        lua_pushinteger(L, req->result);
        break;

      case UV_FS_STAT:
      case UV_FS_LSTAT:
      case UV_FS_FSTAT:
        argc = 1;
        luv_push_stats_table(L, &req->statbuf);
        break;

      case UV_FS_READLINK:
        argc = 1;
        lua_pushstring(L, (char*)req->ptr);
        break;

      case UV_FS_READ:
        argc = 2;
        lua_pushlstring(L, ref->buf, req->result);
        lua_pushinteger(L, req->result);
        free(ref->buf);
        break;

      case UV_FS_SCANDIR:
        {
          uv_dirent_t ent;
          int err = uv_fs_scandir_next(req, &ent);

          argc = 1;
          lua_createtable(L, 0, 0);
          int i = 0;
          while(err != UV_EOF) {
            lua_createtable(L, 2, 0);
            lua_pushstring(L, "name");
            lua_pushstring(L, ent.name);
            lua_settable(L, -3);

            lua_pushstring(L, "type");
            switch(ent.type) {
              case UV_DIRENT_FILE:
                  lua_pushstring(L, "FILE");
                  break;
              case UV_DIRENT_DIR:
                  lua_pushstring(L, "DIR");
                  break;
              case UV_DIRENT_LINK:
                  lua_pushstring(L, "LINK");
                  break;
              case UV_DIRENT_FIFO:
                  lua_pushstring(L, "FIFO");
                  break;
              case UV_DIRENT_SOCKET:
                  lua_pushstring(L, "SOCKET");
                  break;
              case UV_DIRENT_CHAR:
                  lua_pushstring(L, "CHAR");
                  break;
              case UV_DIRENT_BLOCK:
                  lua_pushstring(L, "BLOCK");
                  break;
              default:
              case UV_DIRENT_UNKNOWN:
                  lua_pushstring(L, "UNKOWN");
                  break;
            }
            lua_settable(L, -3);

            lua_rawseti(L, -2, ++i);

            err = uv_fs_scandir_next(req, &ent);
          }
        }
        break;

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

  }

  return argc;

}
コード例 #4
0
ファイル: fs.c プロジェクト: kidaa/luv
/* Processes a result and pushes the data onto the stack
   returns the number of items pushed */
static int push_fs_result(lua_State* L, uv_fs_t* req) {
  luv_req_t* data = req->data;

  if (req->fs_type == UV_FS_ACCESS) {
    lua_pushboolean(L, req->result >= 0);
    return 1;
  }

  if (req->result < 0) {
    lua_pushnil(L);
    if (req->path) {
      lua_pushfstring(L, "%s: %s: %s", uv_err_name(req->result), uv_strerror(req->result), req->path);
    }
    else {
      lua_pushfstring(L, "%s: %s", uv_err_name(req->result), uv_strerror(req->result));
    }
    return 2;
  }

  switch (req->fs_type) {
    case UV_FS_CLOSE:
    case UV_FS_RENAME:
    case UV_FS_UNLINK:
    case UV_FS_RMDIR:
    case UV_FS_MKDIR:
    case UV_FS_FTRUNCATE:
    case UV_FS_FSYNC:
    case UV_FS_FDATASYNC:
    case UV_FS_LINK:
    case UV_FS_SYMLINK:
    case UV_FS_CHMOD:
    case UV_FS_FCHMOD:
    case UV_FS_CHOWN:
    case UV_FS_FCHOWN:
    case UV_FS_UTIME:
    case UV_FS_FUTIME:
      lua_pushboolean(L, 1);
      return 1;

    case UV_FS_OPEN:
    case UV_FS_SENDFILE:
    case UV_FS_WRITE:
      lua_pushinteger(L, req->result);
      return 1;

    case UV_FS_STAT:
    case UV_FS_LSTAT:
    case UV_FS_FSTAT:
      luv_push_stats_table(L, &req->statbuf);
      return 1;

    case UV_FS_MKDTEMP:
      lua_pushstring(L, req->path);
      return 1;

    case UV_FS_READLINK:
      lua_pushstring(L, (char*)req->ptr);
      return 1;

    case UV_FS_READ:
      lua_pushlstring(L, data->data, req->result);
      return 1;

    case UV_FS_SCANDIR:
      // Expose the userdata for the request.
      lua_rawgeti(L, LUA_REGISTRYINDEX, data->req_ref);
      return 1;

    default:
      lua_pushnil(L);
      lua_pushfstring(L, "UNKNOWN FS TYPE %d\n", req->fs_type);
      return 2;
  }

}