SDSM
SDSM

Reputation: 13

Read function isn't returning any value

Value of n coming 9, sockfd = 3 and as it calls the read function, it was not coming out of the read function. After printing read start line, it stops there only:

while(1)
{
        if (n < 0)  
            {
                printf("ERROR writing to socket");              
            }   
        else if(n == 0)
            {
                printf("Nothing");

            }
            printf(" read start n=%d\n ,sockfd = %d\n",n,sockfd);
            n = read(sockfd,buffer,1024);

        if (n < 0)
            {   error("ERROR reading from socket");
            }
            printf("Reply= %s",buffer);
            write_buf_to_file("/root/abc_regr/receive.txt",buffer);  
}
return;

Upvotes: 0

Views: 1791

Answers (1)

Pranit Kothari
Pranit Kothari

Reputation: 9859

read() is by default blocking call, so it will wait till it gets the data. If you want non-blocking function read answers of this question.

Upvotes: 1

Related Questions