3.6 Learning content, Androidwifip2p,golang http. Listenandserve operating mechanism,

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Android Peer two articles:

http://blog.csdn.net/gophers/article/details/38060307

http://blog.csdn.net/max2005/article/details/12237905

Official Document: Http://developer.android.com/training/connect-devices-wirelessly/wifi-direct.html


Golang,

http://blog.csdn.net/gophers/article/details/37815009


  1. Func (SRV *server) Serve (l net. Listener) Error {
  2. Defer L.close ()
  3.     var tempdelay time. duration   
  4.     //  This cycle is the main cycle of the server, through the incoming listener receive requests from the client and establish a connection,   
  5.     //  then creates routine for each connection to execute C.serve (), this c.serve is the specific service that handled   
  6.     for  {  
  7.         rw, e := l.accept ()   
  8.         if  e != nil {   
  9.             if  ne, ok := e. (NET. Error);  ok && ne. temporary ()  {  
  10.                  if  tempdelay ==  0  {  
  11.                      tempdelay = 5  * time. millisecond  
  12.                  } else  {  
  13.                      tempdelay *= 2   
  14.                  }  
  15.                  if  MAX :=  Span class= "number" style= "margin:0px; padding:0px; Border:none; Color:rgb (192,0,0); Background-color:inherit ">1  * time. second; tempdelay > max {  
  16. Tempdelay = max
  17. }
  18.                  SRV.LOGF (" Http: accept error: %v; retrying in %v " , e, tempdelay)   
  19.                  time. Sleep (Tempdelay)   
  20.                  continue   
  21.             }   
  22.             return  E  
  23.         }  
  24.         tempdelay = 0   
  25.         c, err := srv.newconn (rw)   
  26.         if  err != nil {   
  27.             continue   
  28.         }  
  29.         c.setstate (C.rwc, StateNew)    before serve can return   
  30.         go c.serve ()  // <-here for each established connection to create a routine after the service &NBSP;&NBSP;
  31. }
  32. }
Line 30th means that the data returned by the thread is processed, so go generally has a lot of threads


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.