read() returns zero when the connection is lost for blocking sockets.
On Mon, 8 Nov 1999, pramodh mallipatna wrote:
> Hi,
>
> I had a question regarding non-blocking read in a TCP socket program.
> I have the code below.
>
> The non-blocking code works, but, I see that the "perror("Read");" in my
> server returns "Resource temporarily unavailable" instead of "success".
> Is this normal?
>
> Also, when my client closes the connection, I do not get "Connection reset
> by peer" at my server. This happens for both blocked read and non-block
> read. In this case, the server reads 0 bytes and goes into a infinite
> loop. Shouldn't I get a ECONNRESET in this case?
>
> TIA,
> Pramodh
>
> server code
> -----------------
> newsockfd = accept(sockfd,(struct sockaddr *)&client,&clilen);
> ioctl(newsockfd, FIONBIO, (char *)&arg);
> while (1) {
> if ((len = read(newsockfd, buff, 2)) < 0) {
> perror("Read error:");
> sleep(2);
> continue;
> }
> perror("Read");
> }
> -------------------------------
>
> client code
> ---------------------
> connect(sockfd,(struct sockaddr *)&server,sizeof(struct sockaddr_in));
> writes 5 times {
> len = write(sockfd,buff,10);
> sleep(5);
> }
> ---------------------------------
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-net" in
> the body of a message to [EMAIL PROTECTED]
>
-
To unsubscribe from this list: send the line "unsubscribe linux-net" in
the body of a message to [EMAIL PROTECTED]