Socket never returns from read() function call

Z

zb011 message

Hi all,

I have coded an outbound Socket program in C on a solaris box that
sends out data and receives an acknowledgement for it.

However, have faced this problem of a "HANG" state, whereby the read()
function does not return any values.
===========code attached=============================
int readn(int fd, char *ptr)
{
int ntot, nread, found, sr; //sr added 11th May
char *start_posn, *end_posn;
start_posn = ptr;
found = 0;
ntot = 0;

nread = read(fd, ptr, 1); <===read does not return. "HANG STATE"
if (nread < 0)
{
if (found)
return -43;
else
return -42;
}
else if (nread == 0)
{
log(nread,"break from loop","",read_ini_file());
break;
}
============================================================
The required action was to stop and restart the socket.
Have tried to intercept this with a select() (to check on the socket)
However, with a select() 2sec is to be set for the timeval.

This will greatly cripple the performance and thus causing us to be
reluctant in adding this code.

Would be good if someone is able to explain why read() does not return
a vaule when there is no data to be read on the socket.

Thanks!
 
J

Joona I Palaste

zb011 message said:
I have coded an outbound Socket program in C on a solaris box that
sends out data and receives an acknowledgement for it.

ISO standard C does not define sockets. Please ask in
comp.unix.programmer.
 
C

CBFalconer

zb011 said:
I have coded an outbound Socket program in C on a solaris box
that sends out data and receives an acknowledgement for it.

However, have faced this problem of a "HANG" state, whereby the
read() function does not return any values.
===========code attached=============================
int readn(int fd, char *ptr)
{
int ntot, nread, found, sr; //sr added 11th May
char *start_posn, *end_posn;
start_posn = ptr;
found = 0;
ntot = 0;

nread = read(fd, ptr, 1); <===read does not return. "HANG STATE"

There is no such function as 'read' in ISO C. Either use fread or
supply the code for the read function, or ask in a newsgroup
dedicated to your system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top