• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ set_nonblocking函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: make_connection

int make_connection(uint32 ip, uint16 port)
{
	struct sockaddr_in remote_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if (fd == -1) {
		ShowError("make_connection: socket creation failed (code %d)!\n", sErrno);
		return -1;
	}
	if( fd == 0 )
	{// reserved
		ShowError("make_connection: Socket #0 is reserved - Please report this!!!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE )
	{// socket number too big
		ShowError("make_connection: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd);

	remote_address.sin_family      = AF_INET;
	remote_address.sin_addr.s_addr = htonl(ip);
	remote_address.sin_port        = htons(port);

	ShowStatus("Connecting to %d.%d.%d.%d:%i\n", CONVIP(ip), port);

	result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in));
	if( result == SOCKET_ERROR ) {
		ShowError("make_connection: connect failed (socket #%d, code %d)!\n", fd, sErrno);
		do_close(fd);
		return -1;
	}
	//Now the socket can be made non-blocking. [Skotlex]
	set_nonblocking(fd, 1);

	if (fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd,&readfds);

	create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse);
	session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr);

	return fd;
}
开发者ID:deoxis9001,项目名称:frathena-r,代码行数:50,代码来源:socket.c


示例2: server_worker

void*	server_worker(void* arg)
{
    sockfd_t sock = 0;
    struct addrinfo *rp;
    for (rp = serv.ai; rp != NULL; rp = rp->ai_next) {
        sock = socket(rp->ai_family, rp->ai_socktype,
                      rp->ai_protocol);
        if (sock < 0) continue;

        int ret = 1;
        int err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR,
                             &ret, 4);
        if (err != 0) {
            sys_error("setsockopt: SO_REUSEADDR");
        }

        if (bind(sock, rp->ai_addr, rp->ai_addrlen) == 0) {
            break;
        }
    }

    if (rp == NULL) {
        sys_error("bind");
        goto server_worker_exit;
    }

    if (set_nonblocking(sock) == -1) {
        goto server_worker_exit;
    }

    if (serv.socktype == SOCK_STREAM) {
        if (listen(sock, 5) == -1) {
            sys_error("listen");
            goto server_worker_exit;
        }
    }

    serv.serv_sock = sock;
    struct event evt;
    event_set(&evt, sock, EV_READ | EV_PERSIST, serv.handler, arg);
    event_add(&evt, NULL);
    event_dispatch();

server_worker_exit:
    evt_close(sock);
#ifdef _WIN32
    WSACleanup();
#endif
    return NULL;
}
开发者ID:hnney,项目名称:evt-server,代码行数:50,代码来源:evt-server.c


示例3: do_accept_issue

int do_accept_issue(int listenfd){
    while(true){
        if(!isLoop)
            break;
        do{
            struct sockaddr_in client_addr;
            memset(&client_addr,0,sizeof(client_addr));
            socklen_t addrlen=sizeof(client_addr);

#if NOT_USE_NONBLOCK

            int connfd=accept(m_sockfd,\
                (struct sockaddr *)&client_addr,&addrlen);
            set_nonblocking(connfd);
#else

            int connfd=accept4(m_sockfd,(struct sockaddr*)&client_addr,\
                        &addrlen,SOCK_NONBLOCK|SOCK_CLOEXEC);
#endif

            if (connfd < 0){
                //log_error ...
            }else if(connfd > 0){
                if(EINTR == errno || EAGAIN == errno){
                        continue;
                }
                    continue;
            }else{
                //log_error ...
                    continue;
            }
            char client[IP_LEN + 1 + 10];
            memset(client,'\0',IP_LEN + 1 + 10);
            snprintf(client,IP_LEN + 1 + 10,"%s 's port: %d",\
            inet_ntoa(client_addr.sin_addr),\
            ntohs(client_addr.sin_port));
            /*
             *   needs a struct to manage processes or threads,not finish yet !
             *   if error return -1
             */
            notify_t *p_notify=p_notify_t+connfd%thread_num;
            int ret=write(p_notify->pipe_fd[1],&connfd,sizeof(connfd));
            if(ret!=sizeof(connfd)){
                close(connfd);
                return -1;
            }
        }while(false);
    }
    return 0;
}
开发者ID:Sim-szm,项目名称:zomoe_msg_queue,代码行数:50,代码来源:mq_socket.c


示例4: be_ssl_accept

static void be_ssl_accept(int client_fd, struct in_addr client_addr)
{
    if(!set_nonblocking(client_fd, 1)) {
        close(client_fd);
        return;
    }

    epdata_t *epd = malloc(sizeof(epdata_t));

    if(!epd) {
        close(client_fd);
        return;
    }

    bzero(epd, sizeof(epdata_t));

    if(NULL == ssl_ctx) {
        free(epd);
        LOGF(ERR, "ssl ctx not inited");
        close(client_fd);
        return;
    }

    if(ssl_epd_idx == -1) {
        epd->ssl_verify = 1;
    }

    epd->L = new_lua_thread(_L);

    if(epd->L) {
        lua_pushlightuserdata(epd->L, epd);
        lua_setglobal(epd->L, "__epd__");
    }

    epd->fd = client_fd;
    epd->client_addr = client_addr;
    epd->status = STEP_WAIT;
    epd->content_length = -1;
    epd->keepalive = -1;
    epd->response_sendfile_fd = -1;
    //epd->start_time = longtime();

    epd->se_ptr = se_add(loop_fd, client_fd, epd);
    epd->timeout_ptr = add_timeout(epd, STEP_WAIT_TIMEOUT, timeout_handle);

    se_be_read(epd->se_ptr, _be_ssl_accept);

    serv_status.active_counts++;
    serv_status.connect_counts++;
}
开发者ID:butland,项目名称:alilua,代码行数:50,代码来源:worker.c


示例5: make_connection

int make_connection(uint32 ip, uint16 port)
{
	struct sockaddr_in remote_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if (fd == -1) {
		ShowError("make_connection: criação do socket falhou ("CL_RED"%s"CL_RESET")!\n", error_msg());
		return -1;
	}
	if( fd == 0 )
	{// reserved
		ShowError("make_connection: Socket #"CL_WHITE"0"CL_RESET" é reservado - Reporte isso!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE )
	{// socket number too big
		ShowError("make_connection: Novo socket #"CL_WHITE"%d"CL_RESET" é maior que o que suporta-se! Aumente o valor do FD_SETSIZE (atualemente "CL_WHITE"%d"CL_RESET") para seu SO consertar isso!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd);

	remote_address.sin_family      = AF_INET;
	remote_address.sin_addr.s_addr = htonl(ip);
	remote_address.sin_port        = htons(port);

	ShowStatus("Conectando-se a "CL_WHITE"%d.%d.%d.%d"CL_RESET":"CL_WHITE"%i"CL_RESET"\n", CONVIP(ip), port);

	result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in));
	if( result == SOCKET_ERROR ) {
		ShowError("make_connection: conexão falhou (soquete #"CL_WHITE"%d"CL_RESET", "CL_WHITE"%s"CL_RESET")!\n", fd, error_msg());
		do_close(fd);
		return -1;
	}
	//Now the socket can be made non-blocking. [Skotlex]
	set_nonblocking(fd, 1);

	if (fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd,&readfds);

	create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse);
	session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr);

	return fd;
}
开发者ID:guihleao,项目名称:Cronus,代码行数:50,代码来源:socket.c


示例6: qnet_tcp_accept

int qnet_tcp_accept(int listen_fd,
                    struct sockaddr *addr, socklen_t *addrlen) {
  int fd;

  fd = accept(listen_fd, addr, addrlen);
  if (fd == -1) { 
    if (errno == EAGAIN || errno == EWOULDBLOCK) {
      return 0;
    }
    return -1;
  }
  set_nonblocking(fd);
  return fd;
}
开发者ID:changguanghua,项目名称:qnode,代码行数:14,代码来源:qnet.c


示例7: make_listen_bind

int make_listen_bind(uint32 ip, uint16 port)
{
	struct sockaddr_in server_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if( fd == -1 ) {
		ShowError("make_listen_bind: socket creation failed (%s)!\n", error_msg());
		exit(EXIT_FAILURE);
	}
	if( fd == 0 ) { // reserved
		ShowError("make_listen_bind: Socket #0 is reserved - Please report this!!!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE ) { // socket number too big
		ShowError("make_listen_bind: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd,NULL);
	set_nonblocking(fd, 1);

	server_address.sin_family      = AF_INET;
	server_address.sin_addr.s_addr = htonl(ip);
	server_address.sin_port        = htons(port);

	result = sBind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: bind failed (socket #%d, %s)!\n", fd, error_msg());
		exit(EXIT_FAILURE);
	}
	result = sListen(fd,5);
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: listen failed (socket #%d, %s)!\n", fd, error_msg());
		exit(EXIT_FAILURE);
	}

	if(fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd, &readfds);

	create_session(fd, connect_client, null_send, null_parse);
	session[fd]->client_addr = 0; // just listens
	session[fd]->rdata_tick = 0; // disable timeouts on this socket

	return fd;
}
开发者ID:Alvero,项目名称:Hercules,代码行数:50,代码来源:socket.c


示例8: start_server

void start_server(int f_in, int f_out, int argc, char *argv[])
{
	set_nonblocking(f_in);
	set_nonblocking(f_out);

	io_set_sock_fds(f_in, f_out);
	setup_protocol(f_out, f_in);

	if (protocol_version >= 23)
		io_start_multiplex_out();

	if (am_sender) {
		keep_dirlinks = 0; /* Must be disabled on the sender. */
		if (need_messages_from_generator)
			io_start_multiplex_in();

		recv_filter_list(f_in);
		do_server_sender(f_in, f_out, argc, argv);
	} else {
		do_server_recv(f_in, f_out, argc, argv);
	}
	exit_cleanup(0);
}
开发者ID:OPSF,项目名称:uClinux,代码行数:23,代码来源:main.c


示例9: bgp_connect

/* BGP try to connect to the peer.  */
int
bgp_connect (struct peer *peer)
{
  ifindex_t ifindex = 0;

  /* Make socket for the peer. */
  peer->fd = sockunion_socket (&peer->su);
  if (peer->fd < 0)
    return -1;

  set_nonblocking (peer->fd);

  /* Set socket send buffer size */
  bgp_update_sock_send_buffer_size(peer->fd);

  bgp_set_socket_ttl (peer, peer->fd);

  sockopt_reuseaddr (peer->fd);
  sockopt_reuseport (peer->fd);
  
#ifdef IPTOS_PREC_INTERNETCONTROL
  if (bgpd_privs.change (ZPRIVS_RAISE))
    zlog_err ("%s: could not raise privs", __func__);
  if (sockunion_family (&peer->su) == AF_INET)
    setsockopt_ipv4_tos (peer->fd, IPTOS_PREC_INTERNETCONTROL);
  else if (sockunion_family (&peer->su) == AF_INET6)
    setsockopt_ipv6_tclass (peer->fd, IPTOS_PREC_INTERNETCONTROL);
  if (bgpd_privs.change (ZPRIVS_LOWER))
    zlog_err ("%s: could not lower privs", __func__);
#endif

  if (peer->password)
    bgp_md5_set_connect (peer->fd, &peer->su, peer->password);

  /* Bind socket. */
  bgp_bind (peer);

  /* Update source bind. */
  bgp_update_source (peer);

  if (peer->ifname)
    ifindex = ifname2ifindex (peer->ifname);

  if (BGP_DEBUG (events, EVENTS))
    plog_debug (peer->log, "%s [Event] Connect start to %s fd %d",
	       peer->host, peer->host, peer->fd);

  /* Connect to the remote peer. */
  return sockunion_connect (peer->fd, &peer->su, htons (peer->port), ifindex);
}
开发者ID:ColinBS,项目名称:quagga-rtrlib,代码行数:51,代码来源:bgp_network.c


示例10: make_listen_bind

int make_listen_bind(uint32 ip, uint16 port)
{
	struct sockaddr_in server_address = { 0 };
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if( fd == -1 ) {
		ShowError("make_listen_bind: Criacao de socket falhou (%s)!\n", error_msg());
		exit(EXIT_FAILURE);
	}
	if( fd == 0 ) { // reserved
		ShowError("make_listen_bind: Socket #0 esta reservado - Por favor reporte isso!!!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE ) { // socket number too big
		ShowError("make_listen_bind: Novo socket #%d e maior do que o limite suportado! Aumentando o valor para FD_SETSIZE (atualmente %d) seu SO deve corrigir isso!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd,NULL);
	set_nonblocking(fd, 1);

	server_address.sin_family      = AF_INET;
	server_address.sin_addr.s_addr = htonl(ip);
	server_address.sin_port        = htons(port);

	result = sBind(fd, (struct sockaddr*)&server_address, sizeof(server_address));
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: socket-bind falhou (socket #%d, %s)!\n", fd, error_msg());
		exit(EXIT_FAILURE);
	}
	result = sListen(fd,5);
	if( result == SOCKET_ERROR ) {
		ShowError("make_listen_bind: socket-listen falhou (socket #%d, %s)!\n", fd, error_msg());
		exit(EXIT_FAILURE);
	}

	if(sockt->fd_max <= fd) sockt->fd_max = fd + 1;
	sFD_SET(fd, &readfds);

	create_session(fd, connect_client, null_send, null_parse);
	session[fd]->client_addr = 0; // just listens
	session[fd]->rdata_tick = 0; // disable timeouts on this socket

	return fd;
}
开发者ID:Gubio,项目名称:brAthena,代码行数:50,代码来源:socket.c


示例11: make_connection

int make_connection(uint32 ip, uint16 port, struct hSockOpt *opt) {
	struct sockaddr_in remote_address = { 0 };
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if (fd == -1) {
		ShowError("make_connection: Criacao de socket falhou (%s)!\n", error_msg());
		return -1;
	}
	if( fd == 0 ) {// reserved
		ShowError("make_connection: Socket #0 esta reservado - Por favor reporte isso!!!\n");
		sClose(fd);
		return -1;
	}
	if( fd >= FD_SETSIZE ) {// socket number too big
		ShowError("make_connection: Novo socket #%d e maior do que o limite suportado! Aumentando o valor para FD_SETSIZE (atualmente %d) seu SO deve corrigir isso!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd,opt);

	remote_address.sin_family      = AF_INET;
	remote_address.sin_addr.s_addr = htonl(ip);
	remote_address.sin_port        = htons(port);

	if( !( opt && opt->silent ) )
		ShowStatus("Conectando-se a %d.%d.%d.%d:%i\n", CONVIP(ip), port);

	result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in));
	if( result == SOCKET_ERROR ) {
		if( !( opt && opt->silent ) )
			ShowError("make_connection: Falha na conexao (socket #%d, %s)!\n", fd, error_msg());
		sockt->close(fd);
		return -1;
	}
	//Now the socket can be made non-blocking. [Skotlex]
	set_nonblocking(fd, 1);

	if (sockt->fd_max <= fd) sockt->fd_max = fd + 1;
	sFD_SET(fd,&readfds);

	create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse);
	session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr);

	return fd;
}
开发者ID:Gubio,项目名称:brAthena,代码行数:49,代码来源:socket.c


示例12: qnet_tcp_connect

int
qnet_tcp_connect(int port, const char *addr, int *error, int *fd) {
  struct sockaddr_in  dstaddr;
  socklen_t           len;

  if ((*fd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    *error = errno;
    qerror("create socket error: %s", strerror(errno));
    return QERROR;
  }

  if (set_nonblocking(*fd) < 0) {
    *error = errno;
    return QERROR;
  }

  dstaddr.sin_family = AF_INET;
  dstaddr.sin_port = htons(port);
  if (inet_aton(addr, &dstaddr.sin_addr) == 0) {
    qerror("invalid bind address");
    *error = errno;
    close(*fd);
    return QERROR;
  }

  len = sizeof(dstaddr);
  while (1) {
    if (connect(*fd, (struct sockaddr*)(&dstaddr), len) == -1) {
      if (errno == EINTR) {
        continue;
      }   
      if (errno == EINPROGRESS) {
        *error = errno;
        return QNONBLOCKING;
      }   

      if (errno == EISCONN) {
        return QOK;
      }

      qerror("connect to %s:%d error: %s", addr, port, strerror(errno));
      close(*fd);
      return QERROR;
    }
    break;
  }

  return QOK;
}
开发者ID:DiaosiDev,项目名称:qnode,代码行数:49,代码来源:qnet.c


示例13: test_connect

static void test_connect(struct network_test *t)
{
	int s;
	struct sockaddr_in s_in;

	if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1)
		err(1, "socket()");

	t->nt_s = s;

	prepare_ctl(t);

	if (t->nt_proto == TEST_TCP) {
		int off = 0;

		if (tcpcryptd_setsockopt(&t->nt_ctl, TCP_CRYPT_ENABLE, &off,
					 sizeof(off)) == -1)
			errx(1, "tcpcryptd_setsockopt()");
	} else {
		int one = 1;
		assert(t->nt_proto == TEST_CRYPT);
		if (tcpcryptd_setsockopt(&t->nt_ctl, TCP_CRYPT_NOCACHE, &one,
					 sizeof(one)) == -1)
			errx(1, "tcpcryptd_setsockopt()");
	}

	set_nonblocking(s);

	memset(&s_in, 0, sizeof(s_in));

	s_in.sin_family      = AF_INET;
	s_in.sin_port        = htons(t->nt_port);
	s_in.sin_addr        = _state.s_nt_ip;

	if (connect(s, (struct sockaddr*) &s_in, sizeof(s_in)) == -1) {
#ifdef __WIN32__
		if (WSAGetLastError() != WSAEWOULDBLOCK)
#else
		if (errno != EINPROGRESS)
#endif
			err(1, "connect()");
	}

	t->nt_ctl.tcc_dst   = s_in.sin_addr;
	t->nt_ctl.tcc_dport = s_in.sin_port;

	t->nt_state = TEST_STATE_CONNECTING;
	t->nt_start = time(NULL);
}
开发者ID:Inzulus,项目名称:tcpcrypt,代码行数:49,代码来源:tcpcryptd.c


示例14: connection_handler

static void connection_handler(ioloop_t *loop, int listen_fd, unsigned int events, void *args) {
    socklen_t   addr_len;
    int         conn_fd;
    struct sockaddr_in  remo_addr;
    iostream_t *stream;

    // -------- Accepting connection ----------------------------
    debug("Accepting new connection...");
    addr_len = sizeof(struct sockaddr_in);
    conn_fd = accept(listen_fd, (struct sockaddr*) &remo_addr, &addr_len);
    debug("Connection fd: %d...", conn_fd);
    if (conn_fd == -1) {
        error("Error accepting new connection");
        return;
    }

    if (set_nonblocking(conn_fd)) {
        error("Error configuring Non-blocking");
        return;
    }
    stream = iostream_create(loop, conn_fd, 1024, 1024, NULL);
    iostream_set_close_handler(stream, connection_close_handler);
    switch(mode) {
    case 0:
        error("Testing read 16 bytes");
        iostream_read_bytes(stream, 16, read_bytes, NULL);
        break;
            
    case 1:
        error("Testing read_until two blank lines(\\n\\n)");
        iostream_read_until(stream, "\r\n\r\n", read_headers);
        break;

    case 2:
        error("Testing writing dummy data");
        write_texts(stream);
        break;

    case 3:
        error("Testing sending file");
        send_file(stream);
        break;

    default:
        error("Unknown mode: read_until two blank lines(\\n)");
        iostream_read_until(stream, "\r\n\r\n", read_headers);
        break;
    }
}
开发者ID:doop-ymc,项目名称:breeze,代码行数:49,代码来源:test_iostream.c


示例15: my_write

static VALUE my_write(VALUE io, VALUE str, int io_wait)
{
	struct wr_args a;
	long n;

	prepare_write(&a, io, str);
	set_nonblocking(a.fd);
retry:
	n = (long)write(a.fd, a.ptr, a.len);
	if (write_check(&a, n, "write", io_wait) != 0)
		goto retry;
	if (TYPE(a.buf) != T_SYMBOL)
		kgio_autopush_write(io);
	return a.buf;
}
开发者ID:LegalHackers,项目名称:takemyphotodown,代码行数:15,代码来源:write.c


示例16: my_read

static VALUE my_read(int io_wait, int argc, VALUE *argv, VALUE io)
{
	struct io_args a;
	long n;

	prepare_read(&a, argc, argv, io);

	if (a.len > 0) {
		set_nonblocking(a.fd);
retry:
		n = (long)read(a.fd, a.ptr, a.len);
		if (read_check(&a, n, "read", io_wait) != 0)
			goto retry;
	}
	return a.buf;
}
开发者ID:simplegeo,项目名称:kgio,代码行数:16,代码来源:read_write.c


示例17: be_accept

static void be_accept(int client_fd, struct in_addr client_addr)
{
    /* Disable the Nagle (TCP No Delay) algorithm */
    int flag = 1;
    int ret = setsockopt(client_fd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag));

    if(ret == -1) {
        LOGF(ERR, "Couldn't setsockopt(TCP_NODELAY)");
    }

    if(!set_nonblocking(client_fd, 1)) {
        close(client_fd);
        return;
    }

    epdata_t *epd = malloc(sizeof(epdata_t));

    if(!epd) {
        close(client_fd);
        return;
    }

    bzero(epd, sizeof(epdata_t));

    epd->L = new_lua_thread(_L);

    if(epd->L) {
        lua_pushlightuserdata(epd->L, epd);
        lua_setglobal(epd->L, "__epd__");
    }

    epd->fd = client_fd;
    epd->client_addr = client_addr;
    epd->status = STEP_WAIT;
    epd->content_length = -1;
    epd->keepalive = -1;
    epd->response_sendfile_fd = -1;
    //epd->start_time = longtime();

    epd->se_ptr = se_add(loop_fd, client_fd, epd);
    epd->timeout_ptr = add_timeout(epd, STEP_WAIT_TIMEOUT, timeout_handle);

    se_be_read(epd->se_ptr, network_be_read);

    serv_status.active_counts++;
    serv_status.connect_counts++;
}
开发者ID:hopestar,项目名称:alilua,代码行数:47,代码来源:worker.c


示例18: read_from_sd

static int read_from_sd ( int sd )
{
   char buf[100];
   int n;

   set_blocking(sd);
   n = read(sd, buf, 99);
   if (n <= 0) return 0; /* closed */
   copyout(buf, n);

   set_nonblocking(sd);
   while (1) {
      n = read(sd, buf, 100);
      if (n <= 0) return 1; /* not closed */
      copyout(buf, n);
   }
}
开发者ID:MShudrak,项目名称:flayer,代码行数:17,代码来源:valgrind-listener.c


示例19: zclient_start

/* Make connection to zebra daemon. */
int
zclient_start (struct zclient *zclient)
{
  if (zclient_debug)
    zlog_debug ("zclient_start is called");

  /* zclient is disabled. */
  if (! zclient->enable)
    return 0;

  /* If already connected to the zebra. */
  if (zclient->sock >= 0)
    return 0;

  /* Check connect thread. */
  if (zclient->t_connect)
    return 0;

  if (zclient_socket_connect(zclient) < 0)
    {
      if (zclient_debug)
	zlog_debug ("zclient connection fail");
      zclient->fail++;
      zclient_event (ZCLIENT_CONNECT, zclient);
      return -1;
    }

  if (set_nonblocking(zclient->sock) < 0)
    zlog_warn("%s: set_nonblocking(%d) failed", __func__, zclient->sock);

  /* Clear fail count. */
  zclient->fail = 0;
  if (zclient_debug)
    zlog_debug ("zclient connect success with socket [%d]", zclient->sock);
      
  /* Create read thread. */
  zclient_event (ZCLIENT_READ, zclient);

  zebra_hello_send (zclient);

  /* Inform the successful connection. */
  if (zclient->zebra_connected)
    (*zclient->zebra_connected) (zclient);

  return 0;
}
开发者ID:ishidawataru,项目名称:quagga,代码行数:47,代码来源:zclient.c


示例20: unix_init

int unix_init(void)
{
	GIOChannel *io;
	struct sockaddr_un addr = {
		AF_UNIX, BT_IPC_SOCKET_NAME
	};

	int sk, err;

	sk = socket(PF_LOCAL, SOCK_STREAM, 0);
	if (sk < 0) {
		err = -errno;
		error("Can't create unix socket: %s (%d)", strerror(-err),
									-err);
		return err;
	}

	if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
		err = -errno;
		error("Can't bind unix socket: %s (%d)", strerror(-err),
									-err);
		close(sk);
		return err;
	}

	set_nonblocking(sk);

	if (listen(sk, 1) < 0) {
		err = -errno;
		error("Can't listen on unix socket: %s (%d)", strerror(-err),
									-err);
		close(sk);
		return err;
	}

	unix_sock = sk;

	io = g_io_channel_unix_new(sk);
	g_io_add_watch(io, G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
							server_cb, NULL);
	g_io_channel_unref(io);

	DBG("Unix socket created: %d", sk);

	return 0;
}
开发者ID:Krlos0208,项目名称:Sintetizador_Voz,代码行数:46,代码来源:unix.c



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ set_normalized_timespec函数代码示例发布时间:2022-05-30
下一篇:
C++ set_nonblock函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap