size_t AsyncResponseStream::write(const uint8_t *data, size_t len){
  if(_finished() || (_content->room() == 0 && ETS_INTR_WITHINISR()))
    return 0;
  if(len > _content->available())
    len = _content->available();
  return _content->write((const char*)data, len);
}
示例#2
0
文件: not.c 项目: jh80chung/lvm2
int main(int args, char **argv) {
	const char *val = NULL;
	pid_t pid;
	int status;
	int FAILURE = 6;

	if (args < 2) {
		fprintf(stderr, "Need args\n");
		return FAILURE;
	}

	pid = fork();
	if (pid == -1) {
		fprintf(stderr, "Could not fork\n");
		return FAILURE;
	} else if (pid == 0) { 	/* child */
		if (!strcmp(argv[0], "not"))
			val = ">1";
		else if (!strcmp(argv[0], "invalid"))
			val = "3";
		else if (!strcmp(argv[0], "fail"))
			val = "5";

		if (val)
			setenv("LVM_EXPECTED_EXIT_STATUS", val, 1);

		execvp(argv[1], &argv[1]);
		/* should not be accessible */
		return FAILURE;
	} else {		/* parent */
		waitpid(pid, &status, 0);
		if (!WIFEXITED(status)) {
			if (WIFSIGNALED(status))
				fprintf(stderr,
					"Process %d died of signal %d.\n",
					pid, WTERMSIG(status));
			/* did not exit correctly */
			return FAILURE;
		}

		return _finished(argv[0], WEXITSTATUS(status), pid);
	}
	/* not accessible */
	return FAILURE;
}