Socket never returns from read() function call

Discussion in 'C Programming' started by zb011 message, May 12, 2004.

  1. 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!
     
    zb011 message, May 12, 2004
    #1
    1. Advertising

  2. zb011 message <> 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 () ------------- Finland --------\
    \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
     
    Joona I Palaste, May 12, 2004
    #2
    1. Advertising

  3. zb011 message

    CBFalconer Guest

    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?
     
    CBFalconer, May 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Soren Kuula
    Replies:
    1
    Views:
    462
    Henry S. Thompson
    Dec 1, 2005
  2. Kevin
    Replies:
    4
    Views:
    432
    Irrwahn Grausewitz
    Oct 17, 2003
  3. Laszlo Nagy
    Replies:
    1
    Views:
    4,874
    Mark Wooding
    Jan 27, 2009
  4. Jean-Paul Calderone
    Replies:
    0
    Views:
    979
    Jean-Paul Calderone
    Jan 27, 2009
  5. Laszlo Nagy
    Replies:
    0
    Views:
    557
    Laszlo Nagy
    Feb 1, 2009
Loading...

Share This Page