int get_event_set(char *event_set, int wait) {
	int len;
	char link_path[BUF_SIZE];
	char file_path[BUF_SIZE];
	desc common_desc;

	common_desc = init_env(inot_dir, file_path, link_path);
	if ((common_desc.inot < 0) || (common_desc.file < 0) || \
			(common_desc.dir < 0) || (common_desc.link < 0)) {
		common_close(&common_desc);
		return -1;
	}
	if(test_actions(inot_dir, file_path, link_path) < 0) {
		common_close(&common_desc);
		return -1;
	}
	if (wait) {
		do_wait();
	}
	len = read_set(common_desc.inot, event_set);
	common_close(&common_desc);
#ifdef NODEL
	if (! (fDelete(file_path) == 0 &&
		fDelete(link_path) == 0 &&
		fRemDir(inot_dir) == 0))
		return -1;
#endif
	return len;
}
Exemple #2
0
int main(int argc, char* argv[]) {
  int listenfd, connfd;
  struct sockaddr_in addr;
  char buf[256];
  time_t tick;

  network_init();

  listenfd = common_socket(AF_INET, SOCK_STREAM, 0);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(5555);
  common_bind(listenfd, (struct sockaddr*)&addr, sizeof(addr));
  common_listen(listenfd, 5);

  for (;;) {
    connfd = common_accept(listenfd, NULL, NULL);

    tick = time(NULL);
    snprintf(buf, sizeof(buf), "%.24s\r\n", ctime(&tick));
    common_write(connfd, buf, strlen(buf));

    common_close(connfd);
  }
  common_close(listenfd);

  network_destroy();

  return 0;
}
Exemple #3
0
int main(int argc, char* argv[]) {
  int listenfd;
  int clientfd;
  struct sockaddr_in addr;
  socklen_t addrlen;

  network_init();

  listenfd = common_socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(5555);
  common_bind(listenfd, (struct sockaddr*)&addr, sizeof(addr));
  common_listen(listenfd, SOMAXCONN);

  printf("echo server start sucess !!!\n");
  for (;;) {
    addrlen = sizeof(addr);
    clientfd = common_accept(listenfd, (struct sockaddr*)&addr, &addrlen);

    CreateThread(NULL, 0, echo_process, &clientfd, 0, NULL);
  }
  common_close(listenfd);

  network_destroy();

  return 0;
}
Exemple #4
0
static DWORD WINAPI echo_process(void* arg) {
  int fd = *(int*)arg;

  ssize_t n;
  char buff[1024];

  while ((n = common_read(fd, sizeof(buff), buff)) > 0)
    common_writen(fd, buff, n);

  common_close(fd);

  return 0;
}
Exemple #5
0
int main(int argc, char* argv[]) {
  int sockfd;
  struct sockaddr_in addr;
  socklen_t addrlen = sizeof(addr);

  network_init();

  sockfd = common_socket(AF_INET, SOCK_STREAM, 0);
  addr.sin_addr.s_addr = inet_addr("127.0.0.1");
  addr.sin_family      = AF_INET;
  addr.sin_port        = htons(5555);
  common_connect(sockfd, (struct sockaddr*)&addr, addrlen);

  logical_cli(stdin, sockfd);

  common_close(sockfd);
  network_destroy();

  return 0;
}
Exemple #6
0
status_t
_user_close(int fd)
{
	return common_close(fd, false);
}
Exemple #7
0
status_t
_kern_close(int fd)
{
	return common_close(fd, true);
}