In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "analyzing web buffering problems". In daily operation, I believe many people have doubts about analyzing web buffering problems. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "analyzing web buffering problems". Next, please follow the editor to study!
Change the buffer type
In the previous article, I talked about some default buffering types, such as:
The stream to the end device is line buffered
Standard errors are unbuffered
The stream pointing to the file is fully buffered
……
So how do you modify these default buffer types? There are several functions that can be used to change the buffer type:
# include void setbuf (FILE * stream,char * buf); void setbuffer (FILE * stream,char * buf, size_t size); void setlinebuf (FILE * stream); int setvbuf (FILE * stream,char * buf, int mode, size_t size)
The parameters are described as follows:
Stream FILE * type, file pointer
Buf buffer pointer
Mode buffering mode, including _ IOFBF (full buffering), _ IOLBF (line buffering), _ IONBF (without buffering)
Size buffer size
There are four related functions that work similarly, but with different scope of modification.
In the setbuf function, buffering is turned off if buf is set to NULL; otherwise, it points to a buffer of length BUFSIZ and is a row buffer.
# include # include int main (void) {setbuf (stdout,NULL); printf ("bianchengzhuji"); sleep (10); return 0;}
If it is set here without buffering, the buf and size parameters are ignored. When set to full buffering or row buffering. And the buf is NULL, and a system buffer of the appropriate length is used, otherwise a user-defined buffer is used. This is the end of the buffer setting.
Fputs failed to output in time
In fact, with the previous foundation, many problems can be easily solved.
Look at the following example:
# include # include int main (void) {/ / setbuf (stdout,NULL); fputc ('axiomain stdout); sleep (10); return 0;}
For example, if you want to output a character, print it to the terminal, but according to the above method, the character will not be output to the terminal in time, so it is line buffered by default. Open the comment line and set it without buffering.
The log printed by printf has no output
I do not know if you have ever encountered such a situation, ready to debug a certain bug, and found that every time you run to a certain place, the printing is over, and then hang up, making you mistakenly think that the execution of the program ends at the print place, however, it is possible that the program executes at the back, just because the print is line buffered, resulting in part of the print not coming out, it is very likely that you did not add a newline character to print.
At this point you can set it without buffering, or the key location fflush, or print remember to add a newline character.
The file is still lost after fflush
After reading the previous content, do you feel suddenly enlightened? Don't be happy too soon.
The above measures are not all right.
What kind of pit might you step into?
After the content of the file is written, the fflush and the content are available, and then after completion, the system immediately resets. After the reset, the content of the file is still lost.
Decompress a compressed package and decompress it successfully. after the system is reset, it is found that the file size is 0 and the file is lost.
If you haven't encountered such a problem yet, you need to pay special attention. Although the previous fflush and other measures carried out the contents of the buffer with the operation of buffer O, the operating system also needs to write the buffer of the file system to disk, so a direct reset immediately will result in file loss! What should I do? You can use:
Fsync/sync function
Sync command
At this point, the study on "analyzing the problem of web buffering" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.