Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Socket never returns from read() function call

Reply
Thread Tools

Socket never returns from read() function call

 
 
zb011 message
Guest
Posts: n/a
 
      05-12-2004
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!
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      05-12-2004
zb011 message <(E-Mail Removed)> scribbled the following:
> 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.


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

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
 
Reply With Quote
 
 
 
 
CBFalconer
Guest
Posts: n/a
 
      05-12-2004
zb011 message wrote:
>
> 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.

--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 1 02-03-2009 06:20 AM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Steve Holden Python 0 02-01-2009 12:45 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM



Advertisments