コード例 #1
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void chmod_cb(uv_fs_t* req) {
  TUV_ASSERT(req->fs_type == UV_FS_CHMOD);
  TUV_ASSERT(req->result == 0);
  chmod_cb_count++;
  uv_fs_req_cleanup(req);
  check_permission(filename1, *(int*)req->data);
}
コード例 #2
0
static void shutdown_cb(uv_shutdown_t *req, int status) {
  TUV_ASSERT(req == &shutdown_req);
  TUV_ASSERT(called_connect_cb == 1);
  TUV_ASSERT(!got_eof);

  called_shutdown_cb++;
}
コード例 #3
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void unlink_cb(uv_fs_t* req) {
  TUV_ASSERT(req == &unlink_req);
  TUV_ASSERT(req->fs_type == UV_FS_UNLINK);
  TUV_ASSERT(req->result == 0);
  unlink_cb_count++;
  uv_fs_req_cleanup(req);
}
コード例 #4
0
ファイル: test_tcp_open_raw.c プロジェクト: esevan/libtuv
static void connect_cb(uv_connect_t* req, int status) {
  uv_buf_t buf = uv_buf_init((char*)"PING", 4);
  uv_stream_t* stream;
  int r;

  if (status == UV__ECONNREFUSED) {
    TDLOG("tcp_open Connection refused. Run server first.");
    TUV_ASSERT(0);
  }

  printf(">> connect_cb status(%d)", status);

  TUV_ASSERT(req == &connect_req);
  TUV_ASSERT(status == 0);

  stream = req->handle;
  connect_cb_called++;

  r = uv_write(&write_req, stream, &buf, 1, write_cb);
  TUV_ASSERT(r == 0);

  /* Shutdown on drain. */
  // r = uv_shutdown(&shutdown_req, stream, shutdown_cb);
  //TUV_ASSERT(r == 0);

  /* Start reading */
  r = uv_read_start(stream, alloc_cb, read_cb);
  TUV_ASSERT(r == 0);
}
コード例 #5
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void sendfile_cb(uv_fs_t* req) {
  TUV_ASSERT(req == &sendfile_req);
  TUV_ASSERT(req->fs_type == UV_FS_SENDFILE);
  TUV_ASSERT(req->result == 65546);
  sendfile_cb_count++;
  uv_fs_req_cleanup(req);
}
コード例 #6
0
ファイル: test_tcp_open_raw.c プロジェクト: esevan/libtuv
static void shutdown_cb(uv_shutdown_t* req, int status) {
  TUV_ASSERT(req == &shutdown_req);
  TUV_ASSERT(status == 0);

  /* Now we wait for the EOF */
  shutdown_cb_called++;
}
コード例 #7
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void readlink_cb(uv_fs_t* req) {
  TUV_ASSERT(req->fs_type == UV_FS_READLINK);
  TUV_ASSERT(req->result == 0);
  TUV_ASSERT(strcmp((const char*)req->ptr, "test_file_symlink2") == 0);
  readlink_cb_count++;
  uv_fs_req_cleanup(req);
}
コード例 #8
0
static void read_cb(uv_stream_t* t, ssize_t nread, const uv_buf_t* buf) {
  TUV_ASSERT((uv_tcp_t*)t == &tcp);


  if (buf->base)
    free(buf->base);

  if (nread == 0) {
    return;
  }

  if (nread > 0) {
    TUV_ASSERT(0);
    //TUV_ASSERT(!got_eof);
    //TUV_ASSERT(buf->base[0] == 'Q');
    //uv_buf_t qbuf = uv_buf_init((char*)"Q", 1);
    //int r = uv_write(&write_req, t, &qbuf, 1, NULL);
    //TUV_ASSERT(r == 0);
    //got_q = 1;
  } else {
    TUV_ASSERT(nread == UV_EOF);
    uv_close((uv_handle_t*)t, NULL);
    got_eof = 1;
  }
}
コード例 #9
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void fstat_cb(uv_fs_t* req) {
  uv_stat_t* s = (uv_stat_t*)req->ptr;
  TUV_ASSERT(req->fs_type == UV_FS_FSTAT);
  TUV_ASSERT(req->result == 0);
  TUV_ASSERT(s->st_size == sizeof(test_buf));
  uv_fs_req_cleanup(req);
  fstat_cb_count++;
}
コード例 #10
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void file_scandir_cb(uv_fs_t* req) {
  TUV_ASSERT(req == &scandir_req);
  TUV_ASSERT(req->fs_type == UV_FS_SCANDIR);
  TUV_ASSERT(req->result == UV_ENOTDIR);
  TUV_ASSERT(req->ptr == NULL);
  uv_fs_req_cleanup(req);
  scandir_cb_count++;
}
コード例 #11
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void rename_cb(uv_fs_t* req) {
  TUV_ASSERT(req == &rename_req);
  TUV_ASSERT(req->fs_type == UV_FS_RENAME);
  TUV_ASSERT(req->result == 0);
  rename_cb_count++;

  uv_fs_req_cleanup(req);
}
コード例 #12
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void rmdir_cb(uv_fs_t* req) {
  TUV_ASSERT(req == &rmdir_req);
  TUV_ASSERT(req->fs_type == UV_FS_RMDIR);
  TUV_ASSERT(req->result == 0);
  rmdir_cb_count++;
  TUV_ASSERT(req->path);
  TUV_ASSERT(memcmp(req->path, "test_dir\0", 9) == 0);
  uv_fs_req_cleanup(req);
}
コード例 #13
0
static void walk_cb(uv_handle_t* handle, void* arg) {
  TUV_ASSERT(arg == (void*)magic_cookie);

  if (handle == (uv_handle_t*)&timer) {
    seen_timer_handle++;
  } else {
    TUV_ASSERT(0 && "unexpected handle");
  }
}
コード例 #14
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void stat_cb(uv_fs_t* req) {
  TUV_ASSERT(req == &stat_req);
  TUV_ASSERT(req->fs_type == UV_FS_STAT || req->fs_type == UV_FS_LSTAT);
  TUV_ASSERT(req->result == 0);
  TUV_ASSERT(req->ptr);
  stat_cb_count++;
  uv_fs_req_cleanup(req);
  TUV_ASSERT(!req->ptr);
}
コード例 #15
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void ftruncate_cb(uv_fs_t* req) {
  int r;
  TUV_ASSERT(req == &ftruncate_req);
  TUV_ASSERT(req->fs_type == UV_FS_FTRUNCATE);
  TUV_ASSERT(req->result == 0);
  ftruncate_cb_count++;
  uv_fs_req_cleanup(req);
  r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
  TUV_ASSERT(r == 0);
}
コード例 #16
0
ファイル: test_timer.c プロジェクト: akosthekiss/libtuv
static void repeat_cb(uv_timer_t* handle) {
  TUV_ASSERT(handle != NULL);
  TUV_ASSERT(1 == uv_is_active((uv_handle_t*) handle));

  repeat_cb_called++;

  if (repeat_cb_called == 5) {
    uv_close((uv_handle_t*)handle, repeat_close_cb);
  }
}
コード例 #17
0
ファイル: test_tcp_open_raw.c プロジェクト: esevan/libtuv
static void write_cb(uv_write_t* req, int status) {
  TUV_ASSERT(req != NULL);

  if (status) {
    TDLOG("tcp_open uv_write error: %s", uv_strerror(status));
    TUV_ASSERT(0);
  }

  write_cb_called++;
}
コード例 #18
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void write_cb(uv_fs_t* req) {
  int r;
  TUV_ASSERT(req == &write_req);
  TUV_ASSERT(req->fs_type == UV_FS_WRITE);
  TUV_ASSERT(req->result >= 0);  /* FIXME(bnoordhuis) Check if requested size? */
  write_cb_count++;

  uv_fs_req_cleanup(req);
  r = uv_fs_fdatasync(loop, &fdatasync_req, open_req1.result, fdatasync_cb);
  TUV_ASSERT(r == 0);
}
コード例 #19
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void fdatasync_cb(uv_fs_t* req) {
  int r;
  TUV_ASSERT(req == &fdatasync_req);
  TUV_ASSERT(req->fs_type == UV_FS_FDATASYNC);
  TUV_ASSERT(req->result == 0);
  fdatasync_cb_count++;

  uv_fs_req_cleanup(req);
  r = uv_fs_fsync(loop, &fsync_req, open_req1.result, fsync_cb);
  TUV_ASSERT(r == 0);
}
コード例 #20
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void open_cb_simple(uv_fs_t* req) {
  TUV_ASSERT(req->fs_type == UV_FS_OPEN);
  if (req->result < 0) {
    TDLOG("async open error: %d\n", (int)req->result);
    TUV_ASSERT(0);
  }
  open_cb_count++;

  TUV_ASSERT(req->path);
  uv_fs_req_cleanup(req);
}
コード例 #21
0
ファイル: test_timer.c プロジェクト: akosthekiss/libtuv
static void huge_repeat_cb(uv_timer_t* handle) {
  if (huge_repeat_cb_ncalls == 0)
    TUV_ASSERT(handle == &huge_timer1);
  else
    TUV_ASSERT(handle == &tiny_timer);

  if (++huge_repeat_cb_ncalls == 10) {
    uv_close((uv_handle_t*) &tiny_timer, NULL);
    uv_close((uv_handle_t*) &huge_timer1, NULL);
  }
}
コード例 #22
0
static void once_cb(uv_timer_t* handle) {
  TUV_ASSERT(handle != NULL);
  TUV_ASSERT(0 == uv_is_active((uv_handle_t*) handle));

  once_cb_called++;

  uv_close((uv_handle_t*)handle, once_close_cb);

  /* Just call this randomly for the code coverage. */
  uv_update_time(uv_default_loop());
}
コード例 #23
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void fsync_cb(uv_fs_t* req) {
  int r;
  TUV_ASSERT(req == &fsync_req);
  TUV_ASSERT(req->fs_type == UV_FS_FSYNC);
  TUV_ASSERT(req->result == 0);
  fsync_cb_count++;

  uv_fs_req_cleanup(req);
  r = uv_fs_close(loop, &close_req, open_req1.result, close_cb);
  TUV_ASSERT(r == 0);
}
コード例 #24
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void create_cb(uv_fs_t* req) {
  int r;
  TUV_ASSERT(req == &open_req1);
  TUV_ASSERT(req->fs_type == UV_FS_OPEN);
  TUV_ASSERT(req->result >= 0);
  create_cb_count++;
  uv_fs_req_cleanup(req);
  iov = uv_buf_init(test_buf, sizeof(test_buf));

  r = uv_fs_write(loop, &write_req, req->result, &iov, 1, -1, write_cb);
  TUV_ASSERT(r == 0);
}
コード例 #25
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void close_cb(uv_fs_t* req) {
  int r;
  TUV_ASSERT(req == &close_req);
  TUV_ASSERT(req->fs_type == UV_FS_CLOSE);
  TUV_ASSERT(req->result == 0);
  close_cb_count++;
  uv_fs_req_cleanup(req);
  if (close_cb_count == 3) {
    r = uv_fs_unlink(loop, &unlink_req, filename2, unlink_cb);
    TUV_ASSERT(r == 0);
  }
}
コード例 #26
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void futime_cb(uv_fs_t* req) {
  utime_check_t* c;

  TUV_ASSERT(req == &futime_req);
  TUV_ASSERT(req->result == 0);
  TUV_ASSERT(req->fs_type == UV_FS_FUTIME);

  c = (utime_check_t*)req->data;
  check_utime(c->path, c->atime, c->mtime);

  uv_fs_req_cleanup(req);
  futime_cb_count++;
}
コード例 #27
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void check_permission(const char* filename, unsigned int mode) {
  int r;
  uv_fs_t req;
  uv_stat_t* s;

  r = uv_fs_stat(uv_default_loop(), &req, filename, NULL);
  TUV_ASSERT(r == 0);
  TUV_ASSERT(req.result == 0);

  s = &req.statbuf;
  TUV_ASSERT((s->st_mode & 0777) == mode);

  uv_fs_req_cleanup(&req);
}
コード例 #28
0
ファイル: test_tcp_open_raw.c プロジェクト: esevan/libtuv
static uv_os_sock_t create_tcp_socket(void) {
  uv_os_sock_t sock;

  sock = tuvp_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
  TUV_ASSERT(sock >= 0);

  {
    /* Allow reuse of the port. */
    int yes = 1;
    int r = tuvp_setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
    TUV_ASSERT(r == 0);
  }

  return sock;
}
コード例 #29
0
static int timer_final(void* vparam) {
  timer_param_t* param = (timer_param_t*)vparam;

  TUV_ASSERT(once_cb_called == 1);

  // for platforms that needs cleaning
  TUV_ASSERT(0 == uv_loop_close(param->loop));

  // cleanup tuv param
  free(param);

  // jump to next test
  run_tests_continue();

  return 0;
}
コード例 #30
0
ファイル: test_fs.c プロジェクト: esevan/libtuv
static void check_utime(const char* path, double atime, double mtime) {
  uv_stat_t* s;
  uv_fs_t req;
  int r;

  r = uv_fs_stat(loop, &req, path, NULL);
  TUV_ASSERT(r == 0);

  TUV_ASSERT(req.result == 0);
  s = &req.statbuf;

  TUV_ASSERT(s->st_atim.tv_sec == atime);
  TUV_ASSERT(s->st_mtim.tv_sec == mtime);

  uv_fs_req_cleanup(&req);
}