zoukankan      html  css  js  c++  java
  • 第7月第20天 epoll

    1.

    while (1)
                    {
                      struct sockaddr in_addr;
                      socklen_t in_len;
                      int infd;
                      char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
    
                      in_len = sizeof in_addr;
                      infd = accept (sfd, &in_addr, &in_len);
                      if (infd == -1)
                        {
                          if ((errno == EAGAIN) ||
                              (errno == EWOULDBLOCK))
                            {
                              /* We have processed all incoming
                                 connections. */
                              break;
                            }
                          else
                            {
                              perror ("accept");
                              break;
                            }
                        }
    
                      s = getnameinfo (&in_addr, in_len,
                                       hbuf, sizeof hbuf,
                                       sbuf, sizeof sbuf,
                                       NI_NUMERICHOST | NI_NUMERICSERV);
                      if (s == 0)
                        {
                          printf("Accepted connection on descriptor %d "
                                 "(host=%s, port=%s)
    ", infd, hbuf, sbuf);
                        }
    
                      /* Make the incoming socket non-blocking and add it to the
                         list of fds to monitor. */
                      s = make_socket_non_blocking (infd);
                      if (s == -1)
                        abort ();
    
                      event.data.fd = infd;
                      event.events = EPOLLIN | EPOLLET;
                      s = epoll_ctl (efd, EPOLL_CTL_ADD, infd, &event);
                      if (s == -1)
                        {
                          perror ("epoll_ctl");
                          abort ();
                        }
                    }
                  continue;

    http://blog.jobbole.com/93566/

    http://blog.csdn.net/piao00lingping/article/details/48000955

  • 相关阅读:
    0006 字符串转整数
    0005 反转整数
    0004 最长回文子串
    0003 无重复字符的最长子串
    0002 两数相加
    0001 两数之和
    使用jquery+css实现瀑布流布局
    更简单的轮播实现
    类和对象
    生产者-消费者(wait-notify实现)
  • 原文地址:https://www.cnblogs.com/javastart/p/6739271.html
Copyright © 2011-2022 走看看