How to do several things at the same time and at the same time in turn?
We continue to master the course “Network Programming in UNIX”, prepared by SkyDNS and Aydeko . Today we publish the sixth lecture.
Last time, we looked at programs based on the use of a finite state machine. Now let's go ahead and tell you how to “teach” an automaton-style program to handle several simultaneous connections in one process / thread. Previously, course author Alexander Patrakov has already touched on the topic of processing more than one client at a time. Then he proposed to go through the creation of several processes. But this method is not suitable for the astrological server, since its state is common to several processes (there is no such limitation when using threads). ')
There is a way to process more than one client at a time, not based on creating multiple processes or threads. This is a message processing cycle based on the select () function, which this lecture is dedicated to.
“This method is suitable if the limiting factor is not the performance of the processor or disk, and the program is busy mainly with network I / O,” explains Alexander Patrakov.
In this lesson, students were given the task to add a select () function call to an existing automaton program and thereby teach it to handle several clients.
We advise you to try your hand! Watch the video and do not forget to leave comments!