For Programmers: Free Programming Magazines  


Home > Archive > Unix Programming > September 2005 > Socket Resource temporarily unavailable









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Socket Resource temporarily unavailable
eyal.rif@gmail.com

2005-09-28, 8:06 am

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,

Fletcher Glenn

2005-09-28, 6:59 pm

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

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com