当前位置:网站首页>5.2-5.3
5.2-5.3
2022-07-03 14:50:00 【III VII】
5.2 Linux/Unix Five kinds I/O Model
Processing IO When , Both blocking and non blocking are synchronous IO, Only special API Is asynchronous ;
Synchronization during multiplexing IO;
Five kinds IO Model
- Blocking
- Non blocking
- IO Reuse
- Signal driven
- asynchronous IO
1. Blocking blocking
The caller called a function , Wait for this function to return , Do nothing during , Keep checking if this function returns , You have to wait for this function to return for the next action .
2. Non blocking non-blocking ( NIO)
Blocking and non blocking are attributes of file descriptors
Non blocking waiting , Check it every once in a while IO Is the event ready . You can do something else without being ready . Non blocking I/O Executing a system call always returns immediately , Whether or not the event has occurred , If the event does not occur , Then return to -1, At this time, according to errno Distinguish between these two situations , about accept,recv and send, When the event did not occur ,errno Usually set to EAGAIN.
3 IO Reuse
Linux use select/poll/epoll Function implementation IO Reuse model , These functions also block the process , But with blocking IO The difference is that these functions can block multiple at the same time IO operation . And it can read multiple operations at the same time 、 Write operated IO Function to detect . Until data is readable or writable , To really call IO Operation function .
It can detect events of multiple clients at one time , Not used to handle high concurrency ( It requires multiple processes or threads );
4 Signal driven
Linux Signal drive with socket IO, Install a signal processing function , The process continues to run without blocking , When IO Event ready , Process received SIGIO The signal , Then process IO event .
The kernel is asynchronous in the first phase , The second stage is synchronization ; And non blocking IO The difference is that it provides a message notification mechanism , There is no need for the user process to continuously poll and check , Reduced system API Number of calls , Improved efficiency .
5 asynchronous
Linux in , You can call aio_read Function tells the kernel to describe the word buffer pointer and the size of the buffer 、 File offset and notification method , Then immediately return to , When the kernel copies the data to the buffer , Then inform the application .
Asynchrony means that the kernel completes the data copy operation ;
The signal is the application program to complete the data copy operation ;
5.3 web Servers and http agreement
web The server
One Web Server Is a server software ( Program ), Or the hardware running the server software ( Computer ). Its main function is through HTTP Protocol and client ( Usually a browser (Browser)) communicate , To receive , Storage , Handle... From the client HTTP request , And respond to their request HTTP Respond to , Return the requested content to the client ( file 、 Web page, etc ) Or return to a Error Information .
Usually users use Web The browser communicates with the corresponding server . Type... In the browser “ domain name ” or “IP Address : Port number ”, The browser resolves your domain name into the corresponding IP Address or directly according to your IP Address to the corresponding Web Server sends a HTTP request . This process must first pass TCP The three handshakes of the protocol are established with the target Web Server connection , then HTTP Protocol generation is targeted at Web Server's HTTP Request message , adopt TCP、IP Wait for the protocol to be sent to the target Web Server .
http The protocol is based on TCP Agreed ;
http agreement ( Application layer protocol )
Hypertext transfer protocol (Hypertext Transfer Protocol,HTTP) It's a simple request - Response protocol , It usually runs on TCP above . It specifies what messages the client may send to the server and what response it will get . The header of the request and response message is ASCII Form gives ; The message content has a similar MIME The format of .HTTP Is the foundation of data communication in the world wide web .
HTTP The development of tim · berners - Li Yu 1989 In the European Organization for nuclear research (CERN) Initiated by .HTTP The World Wide Web Association (World Wide Web Consortium,W3C) And the Internet Engineering Task Force (Internet Engineering Task Force,IETF) Coordination , A series of RFC, The most famous one is 1999 year 6 Of the month RFC 2616, Defined HTTP A widely used version of the protocol ——HTTP 1.1.
summary
HTTP It's a client terminal ( user ) And the server side ( Website ) Standard of request and response (TCP). By using a web browser 、 Web crawlers or other tools , The client initiates a HTTP Request to the specified port on the server ( The default port is 80). People
Call this client the user agent (user agent). There are some resources stored on the answering server , such as HTML Files and images . We call this answer server the source server (origin server). There may be more than one... Between the user agent and the source server “ Middle layer ”, For example, proxy server 、 Gateway or tunnel (tunnel).
Even though TCP/IP Protocol is the most popular application on the Internet ,HTTP Agreement , There's no requirement to use it or the layers it supports . in fact ,HTTP On any internet protocol , Or other networks .HTTP It is assumed that the underlying protocol provides reliable transmission . therefore , Any agreement that provides such a guarantee can be used by it . So it's in TCP/IP Protocol family uses TCP As its transport layer .
Usually , from HTTP Client initiates a request , Create a specific port to the server ( The default is 80 port ) Of TCP Connect .HTTP The server listens to the client's requests on that port . Once the request is received , The server returns a status to the client , such as "HTTP/1.1 200 OK", And what to return , Such as requested documents 、 Error message 、 Or other information .
working principle
HTTP Protocol definition Web How the client from Web Server request Web page , And how the server puts Web Page to client .HTTP The protocol takes the request / Response model . The client sends a request message to the server , The request message contains the method of the request 、URL、 Protocol version 、 Request headers and request data . The server responds with a status line , The response includes the version of the protocol 、 Success or error code 、 server information 、 Response headers and response data .
Workflow :

Request line ; Request header ; Request a blank line ( Separate data from other parts )
Status line , Response head , Respond to blank lines , Response Content ;

More status codes : Click here
边栏推荐
- 亚马逊、速卖通、Lazada、Shopee、eBay、wish、沃尔玛、阿里国际、美客多等跨境电商平台,测评自养号该如何利用产品上新期抓住流量?
- 【微信小程序】WXSS 模板样式
- Zzuli:1040 sum of sequence 1
- Plane vector addition
- Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th
- 提高效率 Or 增加成本,开发人员应如何理解结对编程?
- 洛谷P3065 [USACO12DEC]First! G 题解
- Luogu p3065 [usaco12dec]first! G problem solution
- 从书本《皮囊》摘录的几个句子
- Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
猜你喜欢

Bucket sorting in C language

【微信小程序】WXSS 模板样式

Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
![[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?](/img/f6/fe61c84f289f0e74a45946dac687a6.jpg)
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
![[ue4] Niagara's indirect draw](/img/8a/576022b5d19e1d6422ff0135c50c93.jpg)
[ue4] Niagara's indirect draw

Tonybot humanoid robot checks the port and corresponds to port 0701

US stock listing of polar: how can the delivery of 55000 units support the valuation of more than 20billion US dollars

基因家族特征分析 - 染色体定位分析

提高效率 Or 增加成本,开发人员应如何理解结对编程?

Use of form text box (I) select text
随机推荐
pyQt界面制作(登录+跳转页面)
光猫超级账号密码、宽带账号密码 获取
Zzuli:1045 numerical statistics
mmdetection 学习率与batch_size关系
[opengl] face pinching system
Bucket sorting in C language
洛谷P3065 [USACO12DEC]First! G 题解
C language STR function
[opengl] geometry shader
556. 下一个更大元素 III : 简单构造模拟题
7-3 rental (20 points)
从书本《皮囊》摘录的几个句子
[opengl] advanced chapter of texture - principle of flowmap
To improve efficiency or increase costs, how should developers understand pair programming?
[ue4] material and shader permutation
C language DUP function
tonybot 人形机器人 红外遥控玩法 0630
Time conversion ()
.NET六大设计原则个人白话理解,有误请大神指正
China PETG market forecast and Strategic Research Report (2022 Edition)