Unix ___domain socket: Difference between revisions

Content deleted Content added
WikiCleanerBot (talk | contribs)
m v2.05b - Bot T20 CW#61 - Fix errors for CW project (Reference before punctuation)
The server process goes to sleep in the wait queue; it doesn't spin wait.
Line 27:
|page=1150}}</ref>
 
Two processes may communicate with each other if each obtains a socket. The server process ''binds'' its socket to an ''address'', opens a ''listen'' channel, and then continuously loops — [[Busy waiting|spin waiting]] for a client connection. UponInside ''accepting''the a client connectionloop, the server thenprocess executesis aput [[readto (systemsleep call)|read]]while [[system call]] that will [[Blocking (computing)|block wait]]. The client ''connects''waiting to the server's socket via the server's accept''address''. Thea client process then [[write (system call)|writes]] a [[String (computer science)|message]] for the server process to readconnection. The application's [[algorithm]] may entail multiple read/write interactions. Upon completion of the algorithm, the client executes <code>exit()</code><ref name="lpiunp-p1169p14_quote">{{cite book
|title=Unix Network Programming
|last1=Stevens
|first1=Richard W.
|last2=Fenner
|first2=Bill
|last3=Rudoff
|first3=Andrew M.
|publisher=Pearson Education
|year=2004
|isbn=81-297-0710-1
|quote=Normally, the server process is put to sleep in the call to ''accept'', waiting for a client connection to arrive and be accepted.
|page=14}}</ref> Upon ''accepting'' a client connection, the server then executes a [[read (system call)|read]] [[system call]] that will [[Blocking (computing)|block wait]]. The client ''connects'' to the server's socket via the server's ''address''. The client process then [[write (system call)|writes]] a [[String (computer science)|message]] for the server process to read. The application's [[algorithm]] may entail multiple read/write interactions. Upon completion of the algorithm, the client executes <code>exit()</code><ref name="lpi-p1169">{{cite book
|title=The Linux Programming Interface
|last=Kerrisk
Line 214 ⟶ 226:
if ( return_value == -1 ) assert( 0 );
 
/* Listen and spin waitaccept code omitted. */
}
</syntaxhighlight>
Line 252 ⟶ 264:
 
==Server accept a connection==
After opening a ''listen'' channel, the server enters an infinite loop. Inside the loop is a [[Busysystem waiting|spincall wait]]to <code>accept()</code>, which puts itself to sleep.<ref name="unp-p14_quote"/> The <code>accept()</code> system call will return a file descriptor when a client process executes <code>connect()</code>.<ref>{{cite web
|title=Linux manual page for accept()
|url=https://man7.org/linux/man-pages/man2/accept.2.html}}</ref>