Linux socket + real-time signals

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • The Doctor

    Linux socket + real-time signals

    Hey people,

    I have two applications:

    the server, which creates a server socket, waits for a real-time signal,
    and if it receives one, it creates a client socket.

    The client, which will connect to the server. This will generate a real-
    time signal at the server, who will create a client socket for this
    client.

    This all works well, and I see a client appearing at my server, on a
    connection attempt. But then, the client tries to send the server-side
    client socket some data. This is where it all goes wrong. The client
    sends, but sometimes, the server doesn't receive it. The weird thing is,
    it receives it when the client is killed. Some other times, the
    application just works, and the server receives the data at the moment it
    is sent from the client.

    I think this could be some problem with an output buffer at the client or
    so? Is there anyone who knows what the problem is?

    Grtz, The Doctor
  • John Lampe

    #2
    Re: Linux socket + real-time signals

    The Doctor <no@email.addre sswrote in
    news:490d6b33$0 $30903$e4fe514c @dreader19.news .xs4all.nl:
    Hey people,
    >
    I have two applications:
    >
    the server, which creates a server socket, waits for a real-time
    signal, and if it receives one, it creates a client socket.
    >
    The client, which will connect to the server. This will generate a
    real- time signal at the server, who will create a client socket for
    this client.
    >
    This all works well, and I see a client appearing at my server, on a
    connection attempt. But then, the client tries to send the server-side
    client socket some data. This is where it all goes wrong. The client
    sends, but sometimes, the server doesn't receive it. The weird thing
    is, it receives it when the client is killed. Some other times, the
    application just works, and the server receives the data at the moment
    it is sent from the client.
    >
    I think this could be some problem with an output buffer at the client
    or so? Is there anyone who knows what the problem is?
    >
    Grtz, The Doctor
    >

    I believe this may be off-topic.

    To (attempt) to answer your question: Have you tried either manually
    flushing the client socket, or setting TCP_NODELAY on it? (to force the
    socket to send the data right away).


    Best Regards
    JL

    Comment

    • Ron AF Greve

      #3
      Re: Linux socket + real-time signals

      Hi,
      Have you read the socket FAQ?



      Also make sure you handle interrupted calls correctly (depending how you
      read) For instance read might return when an interrupt is received (EINTR).

      Regards, Ron AF Greve



      "The Doctor" <no@email.addre sswrote in message
      news:490d6b33$0 $30903$e4fe514c @dreader19.news .xs4all.nl...
      Hey people,
      >
      I have two applications:
      >
      the server, which creates a server socket, waits for a real-time signal,
      and if it receives one, it creates a client socket.
      >
      The client, which will connect to the server. This will generate a real-
      time signal at the server, who will create a client socket for this
      client.
      >
      This all works well, and I see a client appearing at my server, on a
      connection attempt. But then, the client tries to send the server-side
      client socket some data. This is where it all goes wrong. The client
      sends, but sometimes, the server doesn't receive it. The weird thing is,
      it receives it when the client is killed. Some other times, the
      application just works, and the server receives the data at the moment it
      is sent from the client.
      >
      I think this could be some problem with an output buffer at the client or
      so? Is there anyone who knows what the problem is?
      >
      Grtz, The Doctor

      Comment

      • The Doctor

        #4
        Re: Linux socket + real-time signals

        On Sun, 02 Nov 2008 07:22:41 -0600, John Lampe wrote:
        The Doctor <no@email.addre sswrote in
        news:490d6b33$0 $30903$e4fe514c @dreader19.news .xs4all.nl:
        >
        >Hey people,
        >>
        >I have two applications:
        >>
        >the server, which creates a server socket, waits for a real-time
        >signal, and if it receives one, it creates a client socket.
        >>
        >The client, which will connect to the server. This will generate a
        >real- time signal at the server, who will create a client socket for
        >this client.
        >>
        >This all works well, and I see a client appearing at my server, on a
        >connection attempt. But then, the client tries to send the server-side
        >client socket some data. This is where it all goes wrong. The client
        >sends, but sometimes, the server doesn't receive it. The weird thing
        >is, it receives it when the client is killed. Some other times, the
        >application just works, and the server receives the data at the moment
        >it is sent from the client.
        >>
        >I think this could be some problem with an output buffer at the client
        >or so? Is there anyone who knows what the problem is?
        >>
        >Grtz, The Doctor
        >>
        >>
        >
        I believe this may be off-topic.
        >
        To (attempt) to answer your question: Have you tried either manually
        flushing the client socket, or setting TCP_NODELAY on it? (to force the
        socket to send the data right away).
        >
        >
        Best Regards
        JL
        How do I manually flush a socket?

        Grtz, The Doctor

        Comment

        • Sam

          #5
          Re: Linux socket + real-time signals

          The Doctor writes:
          Hey people,
          >
          I have two applications:
          >
          the server, which creates a server socket, waits for a real-time signal,
          and if it receives one, it creates a client socket.
          >
          The client, which will connect to the server. This will generate a real-
          time signal at the server, who will create a client socket for this
          client.
          >
          This all works well, and I see a client appearing at my server, on a
          connection attempt. But then, the client tries to send the server-side
          client socket some data. This is where it all goes wrong. The client
          sends, but sometimes, the server doesn't receive it. The weird thing is,
          it receives it when the client is killed. Some other times, the
          application just works, and the server receives the data at the moment it
          is sent from the client.
          >
          I think this could be some problem with an output buffer at the client or
          so? Is there anyone who knows what the problem is?
          Your problem has nothing to do with C++, the language. There is no such
          thing as a "socket", or a "real time signal" defined by the C++ language.

          Furthermore, your usage of "real time signal" is unclear, as well. All
          signals in POSIX are "real time", whatever that means.

          Your problem is likely to do with the interaction of signals, and socket
          I/O. It is notoriously difficult to get this right. There are many race
          conditions that can potentially occur. Generally, signal handling, and
          socket I/O do not mix very well.

          I forget whether it was 2.6.25 or 2.6.26, but recently an implementation of
          non-POSIX standard API for signal handling with file descriptors was added
          to the Linux kernel. Signal events are reported through a file descriptor,
          so you can have a combined poll()/select() call that processes either
          traditional file descriptor activity, or signal events, whichever one
          occurs. This eliminates the whole slew of race conditions present in
          classical signal handling, and makes many things much easier to do. You
          should look into it, but, again, this has nothing to do with C++, the
          language.


          -----BEGIN PGP SIGNATURE-----
          Version: GnuPG v1.4.9 (GNU/Linux)

          iEYEABECAAYFAkk NxLwACgkQx9p3GY HlUOK4mgCeLgoSg zeaOgVHcuNASnPl KN/Y
          sCAAn3K18UZhszR nX8ifdbThXfO7DL yO
          =moFd
          -----END PGP SIGNATURE-----

          Comment

          Working...