当前位置:网站首页>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
边栏推荐
- Fundamentals of PHP deserialization
- Luogu p3065 [usaco12dec]first! G problem solution
- Zzuli: cumulative sum of 1050 factorials
- 【7.3】146. LRU缓存机制
- Analysis of gene family characteristics - chromosome location analysis
- dllexport和dllimport
- Déformation de la chaîne bm83 de niuke (conversion de cas, inversion de chaîne, remplacement de chaîne)
- Four data flows and cases of grpc
- [opengl] bone animation blending effect
- Bucket sorting in C language
猜你喜欢
How can entrepreneurial teams implement agile testing to improve quality and efficiency? Voice network developer entrepreneurship lecture Vol.03
Qt development - scrolling digital selector commonly used in embedded system
Puzzle (016.4) domino effect
链表有环,快慢指针走3步可以吗
Tailing rushes to the scientific and Technological Innovation Board: it plans to raise 1.3 billion, and Xiaomi Changjiang is the shareholder
Zhonggan micro sprint technology innovation board: annual revenue of 240million, net loss of 17.82 million, proposed to raise 600million
cpu飙升排查方法
Protobuf and grpc
dllexport和dllimport
Tiantu investment sprint Hong Kong stocks: asset management scale of 24.9 billion, invested in xiaohongshu and Naixue
随机推荐
How to color ordinary landscape photos, PS tutorial
C language fcntl function
How to query the baby category of tmall on Taobao
Zzuli:1054 monkeys eat peaches
Detailed explanation of four modes of distributed transaction (Seata)
C language dup2 function
表单文本框的使用(一) 选择文本
牛客 BM83 字符串變形(大小寫轉換,字符串反轉,字符串替換)
Simulation of LS -al command in C language
Zzuli:1047 logarithmic table
Talking about part of data storage in C language
【7.3】146. LRU caching mechanism
Fundamentals of PHP deserialization
从书本《皮囊》摘录的几个句子
论文分享:Generating Playful Palettes from Images
To improve efficiency or increase costs, how should developers understand pair programming?
cpu飙升排查方法
牛客 BM83 字符串变形(大小写转换,字符串反转,字符串替换)
C language to implement a password manager (under update)
[ue4] geometry drawing pipeline