[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Linux socket + real-time signals

Jericho

11/2/2008 8:56:00 AM

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
4 Answers

John Lampe

11/2/2008 1:23:00 PM

0

The Doctor <no@email.address> wrote 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

Ron AF Greve

11/2/2008 1:41:00 PM

0

Hi,
Have you read the socket FAQ?

http://www.unixguide.net/network/...

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

http://www.InformationSuper...

"The Doctor" <no@email.address> wrote 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


Jericho

11/2/2008 2:16:00 PM

0

On Sun, 02 Nov 2008 07:22:41 -0600, John Lampe wrote:

> The Doctor <no@email.address> wrote 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

Sam

11/2/2008 3:18:00 PM

0

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.