Re: Socket Resource temporarily unavailable
From: Fletcher Glenn (fletcher_at_removethisfoglight.com)
Date: 09/28/05
- Next message: Floyd L. Davidson: "Re: How can a server know its own IP address"
- Previous message: Fletcher Glenn: "Re: Information Extracted from socket"
- In reply to: eyal.rif_at_gmail.com: "Socket Resource temporarily unavailable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 28 Sep 2005 15:23:26 GMT
eyal.rif@gmail.com wrote:
> Hi,
>
> I am the following issue -
> the following program accept socket and tries to read and write to the
> socket.
>
> the "send" - has no problem but on "read" or "recv" I get the following
> error - "Resource temporarily unavailable"
>
> any idea what could be the problem?
>
> if((sock = accept(listener,(struct sockaddr *)&sin,&namelen)) < 0) {
> if(errno == EAGAIN) return(-1);
> if(errno != EINTR) {
> cl_error("Error %d accepting connection request
> on port %d",
> errno, listener);
> }
> return(-1);
> }
> if(send(sock,"Handling your connection - Please
> wait\n",strlen("Handling your connection - Please wait\n"),0) == -1)
> perror("send");
> c = read(sock,(void *)buf,160,0);
> Set to non-blocking IO
> if( c < 0) perror("Error read on mcs_accept before Set to
> non-blocking IO-");
> fcntl(sock, F_SETFL, O_NONBLOCK);
> if(send(sock,"Processing\n",strlen("Processing\n"),0) == -1)
> perror("send after Set to non-blocking IO");
> c = read(sock,(void *)buf,160,0);
> if( c < 0) perror("Error read on mcs_accept -");
>
>
> Thanks,
>
I'm surprised that this links. read() only has three arguments. recv
has four, and I presume that's what you want to use.
As for your error, if you set non-blocking I/O, then read or recv will
return EWOULDBLOCK if the data is not immediately available. In your
example above, you are not allowing enough time for the data round
trip. It's better to use select() if you don't want to see the
EWOULDBLOCK error.
-- Fletcher Glenn
- Next message: Floyd L. Davidson: "Re: How can a server know its own IP address"
- Previous message: Fletcher Glenn: "Re: Information Extracted from socket"
- In reply to: eyal.rif_at_gmail.com: "Socket Resource temporarily unavailable"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|