The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 07-23-2007
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,960
Very first request please use CODE tags


Code:
n = read(newsockfd,buffer,1024);/*read from client*/
if (n < 0) perror("\n ERROR reading from socket \n");/*check for errors*/

Why do you continue here even after an error ? ( after perror )
Do you want to continue even when n == 0


Code:
if(k==0)
break;
break;

Does that mean to break irrespective of the value of ' k '. Then why is that part of the code ? Anything specific here ?



Code:
if(j==0)
{
close(newsockfd);
close(sockfd);
exit(0);
}

Parent not waiting for the child to complete



Code:
write(newsockfd,"\n Client wrote",14);/*write to client*/

Flusing before writing and not after that.


Code:
n=write(newsockfd,buffer,sizeof(buffer));/*write to client*/
if(n<0)perror("Write Failed");
}


The same pattern where it continues processing even after write call returns a negative value



Code:
gets(buf);

This function would not check any buffer overrun.

try to use fgets.