15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


CAsyncSocket datagram size confusion

Erik Heuer -- erik.heuer@ks-t.no
Thursday, October 03, 1996


Environment: Win NT 3.51, VC++ 4.1

I am using CAsyncSocket, reading from a SOCK_DGRAM socket which is being
broadcast to from other machines.  In my OnReceive code I do this:

	DWORD toread;
	VERIFY(IOCtl(FIONREAD,&toread));

to see how big a buffer I need for the incoming datagram.  
Despite what the CAsyncSocket:IOCtl() spec says:

	FIONREAD   Determine the maximum number of bytes that can be
	read with one Receive call from this socket. ...[snip] ... 
        If this socket is of type SOCK_DGRAM, FIONREAD returns the 
        size of the first datagram queued on the socket.

I am experiencing (under high incoming datagram rates) that toread 
contains the total queue size and not just the size of the first 
datagram, such that the subsequent statement:

	ASSERT((actualread = Receive(buff,toread)) == toread);

asserts, with actualread set to the datagram size.

Have you experienced this problem?  Do you know any solution or workaround?

Thanks....
Erik Heuer, Kongsberg Simulation & Training, 3600 Kongsberg, Norway
E-mail: erik.heuer@ks-t.no  Phone:(+47) 32735766 Fax:(+47) 32736965




Gabriel Parlea-Visalon -- Gabriel@derivs.demon.co.uk
Tuesday, October 08, 1996

In your message dated Thursday 3, October 1996 you wrote :
> 
> Environment: Win NT 3.51, VC++ 4.1
> 
> I am using CAsyncSocket, reading from a SOCK_DGRAM socket which is being
> broadcast to from other machines.  In my OnReceive code I do this:
> 
> 	DWORD toread;
> 	VERIFY(IOCtl(FIONREAD,&toread));
> 
> to see how big a buffer I need for the incoming datagram.  
> Despite what the CAsyncSocket:IOCtl() spec says:
> 
> 	FIONREAD   Determine the maximum number of bytes that can be
> 	read with one Receive call from this socket. ...[snip] ... 
>         If this socket is of type SOCK_DGRAM, FIONREAD returns the 
>         size of the first datagram queued on the socket.
> 
> I am experiencing (under high incoming datagram rates) that toread 
> contains the total queue size and not just the size of the first 
> datagram, such that the subsequent statement:
> 
> 	ASSERT((actualread = Receive(buff,toread)) == toread);
> 
> asserts, with actualread set to the datagram size.
> 
> Have you experienced this problem?  Do you know any solution or workaround?
> 
> Thanks....
> Erik Heuer, Kongsberg Simulation & Training, 3600 Kongsberg, Norway
> E-mail: erik.heuer@ks-t.no  Phone:(+47) 32735766 Fax:(+47) 32736965
> 
> 

CAsyncSocket::Receive() entry in the Class Library Reference clearly says that 
for datagram sockets, data is extracted from the first enqued datagram, up to 
the size of the buffer supplied. The buffer need not necessarily be filled 
entirely.

That is why your code asserts, as it should, if the buffer size is larger or 
equal to the datagram size.

Rather than VERIFY() and ASSERT() it would be worth probably checking those 
errors first, especilly if you expect high incoming datagram rates. There's a 
handy function GetLastError() to retrieve them.

I hope this helps you.

Gabriel

-- 
                             Gabriel Parlea-Visalon
                               Software Engineer
                           Derivative Trading Systems
                           gabriel@derivs.demon.co.uk





| Вернуться в корень Архива |