C: Question about Beej's networking guide... Is there an assumption here? -


I was just going through the network through the networking guide and I'm curious about this part of the code (in particular "From here" "and" here "):

  // (Main; loop; // for read_fds = master; copy it (if selected (FDMX + 1, and READ_FDS, NOUL, NOUL, NOUL) == -1 (Returns ("Select"); Exit (4);} // Run through the existing connection that searches for existing data (i = 0; i & lt; = fdmax; i ++) {if (FD_ISSET ( I, and read_fds)) {// We've got one !! if (i == listener) {// addrlen = sizeof remoteaddr; newfd = acceptable to add new connections (listener, (stroke, Socador *) and remoder , And Adrilon); if (newfd == -1) {false ("accept");} Other {FD_SET (newfd, & master); // Add to master set if (newfd> fdmax) {// max Keep track of fdmax = newfd; printf ("selectserver: new connection to% s on socket" socket% d \ n ", inet_ntop (remoteaddr.ss_family, get_in_addr (struct sockaddr *) and remander), remote, INET6_ADDRSTRLEN) , Newfd); }} Else {// handle the data from the client ----------------- From here ------------------ - ------ If ((nbytes = recv (i, buf, sizeof buf, 0)) & lt; = 0} {// got an error or closed connection by customer if (nbytes == 0) {// Connection closed printf ("selectserver: socket% d stolen \ n", i); } And {mirror ("RQ"); } Close (i); // Bye! FDCLR (I, and Master); // Remove from main set ----------------- Even here --------------------- - -----} else {// We got some data from a customer for (j = 0; j & lt; = fdmax; j ++) {// Send to everyone! If (J = Listener & amp; j! = I) {Send (J, Buff, NBAT, 0) == - (except listeners and themselves) (FD_ISST (J & M)) 1) { Mirror ("send"); }}}}}} / END handles the data from the client / / / END receives the new incoming connection} // END for looping through the file descriptor // End End (;;) - and you thought it will never end! Return 0;  

Now I know that reading does not always read "everything" which is read on socket and it can sometimes only return one part of it. In that situation, will not this code be wrong? I mean, after reading, the connection is shutting down ... instead, are we not considered to be some other mechanism? If so, what is the correct approach?

There was an error from the socket that is going to stop there only (Recv), otherwise it will be with the data The deal, which was read, even though it could not be read. Will you read it again when it will be hidden again?

Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -