Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-12

lNet UDP and the send-function

6 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

John vd Waeter

Hi All,

I have a lNet UDP in a thread (linux console app).

In a setup on a lan (100 MBit) this lNet UDP sends chunks of data to a receiving pc.
This chunk of data allways has the same size.

I use Send(buffer, sizeof(buffer), peeraddressport) ;

Buffer is an array of 144 bytes

In about 0.3 % of the total of sent pakets, the send-function returns 112 instead of the expected 114 bytes. At the receiving site indeed 112 bytes are received.

Any clues?

tia!
John

John vd Waeter www.jvdw.nl www.gps-carpool.net www.shotinthedark.nl www.pdaforms.nl www.dbapocket.nl

Reply by email

John vd Waeter
to John vd Waeter

Further trying, it looks like the errorrate in the number of sent bytes decreases when aligning to multiples of 4 bytes.

The speed at which send() is called has no influence. Wether it is called once a second or 100 times a second, result is the same: sometimes just sending a few less bytes.

However, now occasionnally errors appear in the OnError-event while sending:

Send Error [22]: Invalid argument

???

Reply by email

IntelliAdmin Support
to John vd Waeter

John,

I have a question about that. Normally access to integer values is atomic, and you do not need to thread protect them when accessing. Was this size value a 32 bit integer value?

Or are you compiling on a different hardware platform than x86?

Thanks,

Joel

John vd Waeter wrote 10 lines
Ok, solved. Did not realize in multithread environment one thread could read a variabele when other thread was just not finished filling this variabele.... -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

John vd Waeter
to IntelliAdmin Support

Hi Joel,

No, that was not the problem.

The buffer I talked about is actually a record.

First I filled record.Buffer and record.sizeofbuffer

Then I pass this record to a routine that calculates and adds a checksum to the buffer, hereby adding 2 bytes to the buffer and thus adding 2 to the size.

Only now the record is ready to be sent by the UDP

But the thread that does the sending just captured the buffer while it was filled with the contents, but no crc added yet, so just inbetween the steps mentioned above. Hence the size was 2 bytes smaller then expected.

Just developing on x86.

John

IntelliAdmin Support wrote 30 lines
John, I have a question about that. Normally access to integer values is atomic, and you do not need to thread protect them when accessing. Was this size value a 32 bit integer value? Or are you compiling on a different hardware platform than x86? Thanks, Joel On Thu, Dec 24, 2009 at 6:49 AM, John vd Waeter wrote: > Ok, solved. > Did not realize in multithread environment one thread could read a variabele > when other thread was just not finished filling this variabele.... > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
John vd Waeter www.jvdw.nl www.gps-carpool.net www.shotinthedark.nl www.pdaforms.nl www.dbapocket.nl

Reply by email

IntelliAdmin Support
to John vd Waeter

Ahh. OK. Now I see.

Thanks,

Joel

John vd Waeter wrote 78 lines
Hi Joel, No, that was not the problem. The buffer I talked about is actually a record. First I filled record.Buffer and record.sizeofbuffer Then I pass this record to a routine that calculates and adds a checksum to the buffer, hereby adding 2 bytes to the buffer and thus adding 2 to the size. Only now the record is ready to be sent by the UDP But the thread that does the sending just captured the buffer while it was filled with the contents, but no crc added yet, so just inbetween the steps mentioned above. Hence the size was 2 bytes smaller then expected. Just developing on x86. John IntelliAdmin Support wrote: > > John, > > I have a question about that. Normally access to integer values is > atomic, and you do not need to thread protect them when accessing. Was > this size value a 32 bit integer value? > > Or are you compiling on a different hardware platform than x86? > > Thanks, > > Joel > > On Thu, Dec 24, 2009 at 6:49 AM, John vd Waeter wrote: >> >> Ok, solved. >> Did not realize in multithread environment one thread could read a >> variabele >> when other thread was just not finished filling this variabele.... >> >> -- >> _______________________________________________ >> Lazarus mailing list >> >> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus >> > > -- > _______________________________________________ > Lazarus mailing list > > http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus > -- John vd Waeter www.jvdw.nl www.gps-carpool.net www.shotinthedark.nl www.pdaforms.nl www.dbapocket.nl -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email