Exemplo n.º 1
0
 void startListen(Socket::ptr listen_socket, boost::barrier* barrier){
   listen_socket->listen();
   if(barrier) barrier->wait();
   while(conn_num--) {
          //accept will switch the contex to epoll fiber
          Socket::ptr socket = listen_socket->accept();
          Scheduler::getThis()->schedule(boost::bind(&TCPServer::handleConnect, this, socket));
   }
   listen_socket->shutdown();
 }
Exemplo n.º 2
0
  void handleConnect(Socket::ptr socket) {
      char buf[10];
      while(1) { 
          //receive will switch the contex to epoll fiber
             size_t len = socket->receive(buf, sizeof(buf));
             if(len == 0) {
                printf("receive 0, closed by remote\n");
                break;
             }
             socket->send(buf, len);
       }
       socket->shutdown();
 }