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.