how much socket buffer used?

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

how much socket buffer used?

Post by mael15 »

hi,
is there a way to determine how much socket buffer is used? i have a problem with a device showing me that its send buffer is full and i need to see if my app´s receive buffer might be too small. the amount of data sent by the device can vary during the app´s runtime, so i would like to change the size of the socket buffer when needed.
i change the socket buffer size using

Code: Select all

sock->SetOption(SOL_SOCKET, SO_RCVBUF, &newSize, sizeof(newSize));
unfortunately i could not find some command option to query the amount of buffer used.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how much socket buffer used?

Post by ONEEYEMAN »

Hi,
Why do you need to change the size of the buffer?
To answer you question: you can change the data/protocol setting the length of the packet as a first byte{s} and allocate appropriately.

Thank you.
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: how much socket buffer used?

Post by mael15 »

ONEEYEMAN wrote:Why do you need to change the size of the buffer?
since the data rate could vary between 1000 and 480000 with 5 byte samples per second, i thought it would be great to change the size of the input buffer as needed.
so, is there no way to check how full my socket input buffer is?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how much socket buffer used?

Post by ONEEYEMAN »

Hi,
I don't think so.
Just send the size of the data as the first couple of bytes and check if the number of bytes you read is the same as the number of bytes in the beginning of the packet.

Thank you.
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: how much socket buffer used?

Post by mael15 »

ONEEYEMAN wrote: Just send the size of the data as the first couple of bytes and check if the number of bytes you read is the same as the number of bytes in the beginning of the packet.
I am not sure what you mean? I can only do things with my receive buffer, i cannot change what the device sends? I would like to check how much of my receive buffer is used.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: how much socket buffer used?

Post by ONEEYEMAN »

Hi,
Do you know the protocol the device is sending the data?
If the protocol has different length usually the first byte{s} has the buffer length...

Thank you.
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: how much socket buffer used?

Post by mael15 »

the device is using tcp over ethernet.
maybe i am totally on the wrong track here, but if i want to check how much data has been received and waiting to be handled by my program, how can something in the transmission protocol be relevant?
thank you for your patience!
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how much socket buffer used?

Post by doublemax »

AFAIK there is no way to get this information. But i'm still not sure why you actually need it. In every data transmission, one of the two partners (sender/receiver) will be slower than the other. But the protocol should handle that, so that e.g. the sender stops sending until the receiver can receive again.
Use the source, Luke!
mael15
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 539
Joined: Fri May 22, 2009 8:52 am
Location: Bremen, Germany

Re: how much socket buffer used?

Post by mael15 »

doublemax wrote:But the protocol should handle that, so that e.g. the sender stops sending until the receiver can receive again.
that is the thing, the device keeps on sending data plus messages that its buffer is 50% or 75% full. so i want to find the problem on the receiving end. if it is not the receiving buffer, then maybe cpu speed or my program or something else...
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: how much socket buffer used?

Post by doublemax »

Is it actually fatal that the sending device says its send buffer is full? Or is it just a hint that it could send faster?

Do you do anything time consuming on the receiving end? If you can't process the data fast enough, all you can do is create a buffer as big as possible and hope that it's big enough to receive all data. If it's an endless stream of data and you can't process it fast enough, you're screwed ;)
Use the source, Luke!
Post Reply