Re: Socket Resource temporarily unavailable

From: Fletcher Glenn (fletcher_at_removethisfoglight.com)
Date: 09/28/05


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


Relevant Pages

  • Re: Receive no data
    ... It is a best practice to shutdown ... a socket for sending once all data has been sent. ... I see multiple recv() statements in the code. ...
    (microsoft.public.win32.programmer.networks)
  • RE: BUG in Winsock on P4 HT CPU
    ... If you read the help on WSAAsyncSelect it states ... Network transport stack receives 100 bytes of data on socket s and causes ... The application issues recv(s, buffptr, 50, 0) to read 50 bytes. ... on CPU's that do not support HT, or CPUs with HT disabled. ...
    (microsoft.public.win32.programmer.networks)
  • Re: how to avoid recv() blocking issue?
    ... using WSAEventSelect. ... we have a weak link in a chain: a timeout. ... drop the connection abnormally such that the blocking recv will never ... TerminateThread- btw, it's not a good idea, because a socket ...
    (microsoft.public.win32.programmer.networks)
  • Re: Connection broken on recv() function
    ... >>> with the error code WSAECONNRESET. ... it still blocked in the recv() function. ... >>> I don't want to use a nonblock socket. ... On my system whenever I unplug the cable: ...
    (microsoft.public.win32.programmer.kernel)
  • Re: TCP Socket Using connect in Non Blocking - Results in errors using recv()
    ... >the flags to - setting the socket to blocking. ... >I subsequently use a listening thread which repeatedly calls recv() ...
    (comp.unix.questions)