当前位置: 首页>>代码示例>>C++>>正文


C++ HANDLE_EINTR函数代码示例

本文整理汇总了C++中HANDLE_EINTR函数的典型用法代码示例。如果您正苦于以下问题:C++ HANDLE_EINTR函数的具体用法?C++ HANDLE_EINTR怎么用?C++ HANDLE_EINTR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了HANDLE_EINTR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: FD_ZERO

int el::lib_event_pipe_t::wait_event()
{
	//!!!这里的日志不能使用线程打印,否则是死循环,继续调用日志事件!!!	

	timeval time_out_val;
	time_out_val.tv_sec = 0;
	time_out_val.tv_usec = 100000;//100毫秒

	fd_set fd_read_set;
	FD_ZERO(&fd_read_set);
	FD_SET(this->select_fd_max, &fd_read_set);

	int r = HANDLE_EINTR(::select(this->select_fd_max + 1, &fd_read_set, NULL, NULL, &time_out_val));
	if (0 == r){//time out
		return 0;
	}

	if (ERR == r){
		if (EBADF == errno){
			//ALERT_LOG("[err_code:%d, err:%s]", errno, strerror(errno));
		}
		return ERR;
	}

	if(FD_ISSET(this->select_fd_max, &fd_read_set)){
		char sz[100];
		int ret = (int)HANDLE_EINTR(::read(this->select_fd_max, sz, sizeof(sz)));
		return ret;
	}

	return 0;
}
开发者ID:75912001,项目名称:endless-lib,代码行数:32,代码来源:lib_thread.cpp

示例2: CreateTransport

nsresult
CreateTransport(base::ProcessId aProcIdOne,
                TransportDescriptor* aOne,
                TransportDescriptor* aTwo)
{
  wstring id = IPC::Channel::GenerateVerifiedChannelID(std::wstring());
  // Use MODE_SERVER to force creation of the socketpair
  Transport t(id, Transport::MODE_SERVER, nullptr);
  int fd1 = t.GetFileDescriptor();
  int fd2, dontcare;
  t.GetClientFileDescriptorMapping(&fd2, &dontcare);
  if (fd1 < 0 || fd2 < 0) {
    return NS_ERROR_TRANSPORT_INIT;
  }

  // The Transport closes these fds when it goes out of scope, so we
  // dup them here
  fd1 = dup(fd1);
  fd2 = dup(fd2);
  if (fd1 < 0 || fd2 < 0) {
    HANDLE_EINTR(close(fd1));
    HANDLE_EINTR(close(fd2));
    return NS_ERROR_DUPLICATE_HANDLE;
  }

  aOne->mFd = base::FileDescriptor(fd1, true/*close after sending*/);
  aTwo->mFd = base::FileDescriptor(fd2, true/*close after sending*/);
  return NS_OK;
}
开发者ID:bolt-dev,项目名称:gecko-dev,代码行数:29,代码来源:Transport_posix.cpp

示例3: OpenDeletedDirectory

static int
OpenDeletedDirectory()
{
  // We don't need this directory to persist between invocations of
  // the program (nor need it to be cleaned up if something goes wrong
  // here, because mkdtemp will choose a fresh name), so /tmp as
  // specified by FHS is adequate.
  char path[] = "/tmp/mozsandbox.XXXXXX";
  if (!mkdtemp(path)) {
    SANDBOX_LOG_ERROR("mkdtemp: %s", strerror(errno));
    return -1;
  }
  int fd = HANDLE_EINTR(open(path, O_RDONLY | O_DIRECTORY));
  if (fd < 0) {
    SANDBOX_LOG_ERROR("open %s: %s", path, strerror(errno));
    // Try to clean up.  Shouldn't fail, but livable if it does.
    DebugOnly<bool> ok = HANDLE_EINTR(rmdir(path)) == 0;
    MOZ_ASSERT(ok);
    return -1;
  }
  if (HANDLE_EINTR(rmdir(path)) != 0) {
    SANDBOX_LOG_ERROR("rmdir %s: %s", path, strerror(errno));
    AlwaysClose(fd);
    return -1;
  }
  return fd;
}
开发者ID:LordJZ,项目名称:gecko-dev,代码行数:27,代码来源:SandboxChroot.cpp

示例4: while

// SBCELT_HelperMonitor implements a monitor thread that runs
// when libsbcelt decides to use SBCELT_MODE_FUTEX.  It is
// response for determining whether the helper process has died,
// and if that happens, restart it.
static void *SBCELT_HelperMonitor(void *udata) {
	(void) udata;

	while (1) {
		uint64_t now = mtime();
		uint64_t elapsed = now - lastdead;
		lastdead = now;

		// Throttle helper re-launches to around 1 per sec.
		if (elapsed < 1*USEC_PER_SEC) {
			usleep(1*USEC_PER_SEC);
		}

		debugf("restarted sbcelt-helper; %lu usec since last death", elapsed);

		pid_t child = fork();
		if (child == -1) {
			// We're memory constrained. Wait and try again...
			usleep(5*USEC_PER_SEC);
			continue;
		} else if (child == 0) {
			// For SBCELT_SANDBOX_SECCOMP_BPF, it shouldn't matter
			// whether the child inherits any file descriptors, since
			// the only useful system call the process can make is futex(2).
			//
			// However, if we're running in Futex mode without a sandbox,
			// closing the file descriptors is indeed a good idea, which
			// is why we do it unconditionally below.
			(void) HANDLE_EINTR(close(0));
			(void) HANDLE_EINTR(close(1));
#ifndef DEBUG
			xclosefrom(2);
#else
			xclosefrom(3);
#endif

			char *const argv[] = {
				SBCELT_HelperBinary(),
				NULL,
			};
			execv(argv[0], argv);
			_exit(100);
		}

		int status;
		int retval = HANDLE_EINTR(waitpid(child, &status, 0));
		if (retval == child) {
			if (WIFEXITED(status)) {
				debugf("sbcelt-helper died with exit status: %i", WEXITSTATUS(status));
			} else if (WIFSIGNALED(status)) {
				debugf("sbcelt-helper died with signal: %i", WTERMSIG(status));
			}
		} else if (retval == -1 && errno == EINVAL) {
			fprintf(stderr, "libsbcelt: waitpid() failed with EINVAL; internal error!\n");
			fflush(stderr);
			exit(1);
		}
	}
}
开发者ID:chiefdome,项目名称:sbcelt,代码行数:63,代码来源:libsbcelt.c

示例5: compare_timezone_to_localtime

static int
compare_timezone_to_localtime( ScanDataRec*  scan,
                               const char*   path )
{
    struct  stat  st;
    int           fd1, fd2, result = 0;

    D( "%s: comparing %s:", __FUNCTION__, path );

    if ( stat( path, &st ) < 0 ) {
        D( " can't stat: %s\n", strerror(errno) );
        return 0;
    }

    if ( st.st_size != scan->localtime_st.st_size ) {
        D( " size mistmatch (%zd != %zd)\n", (size_t)st.st_size, (size_t)scan->localtime_st.st_size );
        return 0;
    }

    fd1 = open( scan->localtime, O_RDONLY );
    if (fd1 < 0) {
        D(" can't open %s: %s\n", scan->localtime, strerror(errno) );
        return 0;
    }
    fd2 = open( path, O_RDONLY );
    if (fd2 < 0) {
        D(" can't open %s: %s\n", path, strerror(errno) );
        close(fd1);
        return 0;
    }
    do {
        off_t  nn;

        for (nn = 0; nn < st.st_size; nn++) {
            char  temp[2];
            int   ret;

            ret = HANDLE_EINTR(read(fd1, &temp[0], 1));
            if (ret < 0) break;

            ret = HANDLE_EINTR(read(fd2, &temp[1], 1));
            if (ret < 0) break;

            if (temp[0] != temp[1])
                break;
        }

        result = (nn == st.st_size);

    } while (0);

    D( result ? " MATCH\n" : "no match\n" );

    close(fd2);
    close(fd1);

    return result;
}
开发者ID:Dorahe,项目名称:platform_external_qemu,代码行数:58,代码来源:timezone.c

示例6: connector

void connector(attendant__pipe_t in, attendant__pipe_t out) {
  const char *pipe = "pipe\n";
  int err;
  HANDLE_EINTR(write(in, pipe, strlen(pipe)), err);
  ok(err != -1, "request pipe");
  HANDLE_EINTR(read(out, fifo, sizeof(fifo)), err);
  fifo[strlen(fifo) - 1] = '\0';
  ok(err != -1, "get pipe # %s", fifo);
}
开发者ID:bigeasy,项目名称:attendant,代码行数:9,代码来源:retry.t.c

示例7: SBCELT_RWHelper

static int SBCELT_RWHelper() {
	while (1) {
		// Wait for the lib to signal us.
		if (HANDLE_EINTR(read(0, &workpage->pingpong, 1)) == -1) {
			return -2;
		}

		SBCELT_DecodeSingleFrame();

		if (HANDLE_EINTR(write(1, &workpage->pingpong, 1)) == -1) {
			return -3;
		}
	}
}
开发者ID:chiefdome,项目名称:sbcelt,代码行数:14,代码来源:sbcelt-helper.c

示例8: WaitForChildAndExit

// Block until child_pid exits, then exit. Try to preserve the exit code.
static void WaitForChildAndExit(pid_t child_pid) {
  int exit_code = -1;
  siginfo_t reaped_child_info;

  // Don't "Core" on SIGABRT. SIGABRT is sent by the Chrome OS session manager
  // when things are hanging.
  // Here, the current process is going to waitid() and _exit(), so there is no
  // point in generating a crash report. The child process is the one
  // blocking us.
  if (signal(SIGABRT, ExitWithErrorSignalHandler) == SIG_ERR) {
    FatalError("Failed to change signal handler");
  }

  int wait_ret =
      HANDLE_EINTR(waitid(P_PID, child_pid, &reaped_child_info, WEXITED));

  if (!wait_ret && reaped_child_info.si_pid == child_pid) {
    if (reaped_child_info.si_code == CLD_EXITED) {
      exit_code = reaped_child_info.si_status;
    } else {
      // Exit with code 0 if the child got signaled.
      exit_code = 0;
    }
  }
  _exit(exit_code);
}
开发者ID:AchironOS,项目名称:chromium-2,代码行数:27,代码来源:sandbox.c

示例9: socket_send_to

/**
	socket_send_to : 'socket -> buf:string -> pos:int -> length:int -> addr:{host:'int32,port:int} -> int
	<doc>
	Send data from an unconnected UDP socket to the given address.
	</doc>
**/
static value socket_send_to( value o, value data, value pos, value len, value vaddr ) {
	int p,l,dlen;
	value host, port;
	struct sockaddr_in addr;
	val_check_kind(o,k_socket);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	val_check(vaddr,object);
	host = val_field(vaddr, f_host);
	port = val_field(vaddr, f_port);
	val_check(host,int32);
	val_check(port,int);
	p = val_int(pos);
	l = val_int(len);
	dlen = val_strlen(data);
	memset(&addr,0,sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(val_int(port));
	*(int*)&addr.sin_addr.s_addr = val_int32(host);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
	POSIX_LABEL(send_again);
	dlen = sendto(val_sock(o), val_string(data) + p , l, MSG_NOSIGNAL, (struct sockaddr*)&addr, sizeof(addr));
	if( dlen == SOCKET_ERROR ) {
		HANDLE_EINTR(send_again);
		return block_error();
	}
	return alloc_int(dlen);
}
开发者ID:motion-twin,项目名称:neko,代码行数:36,代码来源:socket.c

示例10: sizeof

bool
app_launcher::get_output(int pipe, vogl::dynamic_string &output, size_t max_output)
{
    if (pipe != -1)
    {
        if (max_output <= 0)
            return true;

        for(;;)
        {
            char buf[4096];
            size_t nbytes = max_output;
            if (nbytes >= sizeof(buf))
                nbytes = sizeof(buf);

            // Try to read in nbytes. read returns 0:end of file, -1:error.
            ssize_t length = HANDLE_EINTR(read(pipe, buf, nbytes));
            if (length < 0)
                return false;

            max_output -= length;
            output.append(buf, (uint)length);

            if ((length != (ssize_t)nbytes) || (max_output <= 0))
                return true;
        }
    }

    return false;
}
开发者ID:Daft-Freak,项目名称:vogl,代码行数:30,代码来源:vogl_applauncher.cpp

示例11: SBCELT_CheckSeccomp

// SBCELT_CheckSeccomp checks for kernel support for
// SECCOMP.
//
// On success, the function returns a valid sandbox
// mode (see SBCELT_SANDBOX_*).
//
// On failure, the function returns
//  -1 if the helper process did not execute correctly.
//  -2 if the fork system call failed. This signals that the
//     host system is running low on memory. This is a
//     recoverable error, and in our case we should simply
//     wait a bit and try again.
static int SBCELT_CheckSeccomp() {
 	int status, err;
	pid_t child;

	child = fork();
	if (child == -1) {
 		return -2;
	} else if (child == 0) {
		char *const argv[] = {
			SBCELT_HelperBinary(),
			"detect",
			NULL,
		};
		execv(argv[0], argv);
		_exit(100);
	}

	if (HANDLE_EINTR(waitpid(child, &status, 0)) == -1) {
		return -1;
	}

	if (!WIFEXITED(status)) {
		return -1;
	}

	int code = WEXITSTATUS(status);
	if (!SBCELT_SANDBOX_VALID(code)) {
		return -1;
	}

	return code;
}
开发者ID:chiefdome,项目名称:sbcelt,代码行数:44,代码来源:libsbcelt.c

示例12: socket_close

/**
	socket_close : 'socket -> void
	<doc>Close a socket. Any subsequent operation on this socket will fail</doc>
**/
static value socket_close( value o ) {
	POSIX_LABEL(close_again);
	if( closesocket(val_sock(o)) ) {
		HANDLE_EINTR(close_again);
	}
	return alloc_bool(true);
}
开发者ID:KTXSoftware,项目名称:Kha-haxelib,代码行数:11,代码来源:Socket.cpp

示例13: socket_select

/**
	socket_select : read : 'socket array -> write : 'socket array -> others : 'socket array -> timeout:number? -> 'socket array array
	<doc>Perform the [select] operation. Timeout is in seconds or [null] if infinite</doc>
**/
static value socket_select( value rs, value ws, value es, value timeout ) {
	struct timeval tval;
	struct timeval *tt;
	SOCKET n = 0;
	fd_set rx, wx, ex;
	fd_set *ra, *wa, *ea;
	value r;
	POSIX_LABEL(select_again);
	ra = make_socket_array(rs,val_array_size(rs),&rx,&n);
	wa = make_socket_array(ws,val_array_size(ws),&wx,&n);
	ea = make_socket_array(es,val_array_size(es),&ex,&n);
	if( ra == &INVALID || wa == &INVALID || ea == &INVALID )
		neko_error();
	if( val_is_null(timeout) )
		tt = NULL;
	else {
		val_check(timeout,number);
		tt = &tval;
		init_timeval(val_number(timeout),tt);
	}
	if( select((int)(n+1),ra,wa,ea,tt) == SOCKET_ERROR ) {
		HANDLE_EINTR(select_again);
		neko_error();
	}
	r = alloc_array(3);
	val_array_ptr(r)[0] = make_array_result(rs,ra);
	val_array_ptr(r)[1] = make_array_result(ws,wa);
	val_array_ptr(r)[2] = make_array_result(es,ea);
	return r;
}
开发者ID:motion-twin,项目名称:neko,代码行数:34,代码来源:socket.c

示例14: socket_recv

/**
	socket_recv : 'socket -> buf:string -> pos:int -> len:int -> int
	<doc>Read up to [len] bytes from [buf] starting at [pos] from a connected socket.
	Return the number of bytes readed.</doc>
**/
static value socket_recv( value o, value data, value pos, value len ) {
	int p,l,dlen,ret;
	int retry = 0;
	val_check_kind(o,k_socket);
	val_check(data,string);
	val_check(pos,int);
	val_check(len,int);
	p = val_int(pos);
	l = val_int(len);
	dlen = val_strlen(data);
	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
	POSIX_LABEL(recv_again);
	if( retry++ > NRETRYS ) {
		sock_tmp t;
		t.sock = val_sock(o);
		t.buf = val_string(data) + p;
		t.size = l;
		neko_thread_blocking(tmp_recv,&t);
		ret = t.ret;
	} else
		ret = recv(val_sock(o), val_string(data) + p , l, MSG_NOSIGNAL);
	if( ret == SOCKET_ERROR ) {
		HANDLE_EINTR(recv_again);
		return block_error();
	}
	return alloc_int(ret);
}
开发者ID:motion-twin,项目名称:neko,代码行数:33,代码来源:socket.c

示例15: socket_recv_from

static value socket_recv_from( value o, value dataBuf, value pos, value len, value addr ) {
	int p,l,ret;
	int retry = 0;
	struct sockaddr_in saddr;
	SockLen slen = sizeof(saddr);
	val_check_kind(o,k_socket);
	val_check(dataBuf,buffer);
	buffer buf = val_to_buffer(dataBuf);
   char *data = buffer_data(buf);
   int dlen = buffer_size(buf);
	val_check(pos,int);
	val_check(len,int);
	val_check(addr,object);
	p = val_int(pos);
	l = val_int(len);

	if( p < 0 || l < 0 || p > dlen || p + l > dlen )
		neko_error();
   SOCKET sock = val_sock(o);
   gc_enter_blocking();
	POSIX_LABEL(recv_from_again);
	if( retry++ > NRETRYS ) {
      ret = recv(sock,data+p,l,MSG_NOSIGNAL);
	} else
		ret = recvfrom(sock, data + p , l, MSG_NOSIGNAL, (struct sockaddr*)&saddr, &slen);
	if( ret == SOCKET_ERROR ) {
		HANDLE_EINTR(recv_from_again);
		return block_error();
	}
   gc_exit_blocking();
	alloc_field(addr,f_host,alloc_int32(*(int*)&saddr.sin_addr));
	alloc_field(addr,f_port,alloc_int(ntohs(saddr.sin_port)));
	return alloc_int(ret);
}
开发者ID:CapturaCamera,项目名称:hxcpp,代码行数:34,代码来源:Socket.cpp


注:本文中的HANDLE_EINTR函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。