>> Is the pointer used in the send being corrupted by timing problems
Bingo.
I'm really not sure about your method to "sends a command message to say provide valid data" and then "request the data, and I only provide valid data if I have received the command to provide valid data otherwise I provide stale data".
It really seems like the server is requesting data from itself, but again I get confused where this data is coming from and where it is going, and why you would want to provide stale data under certain
And making this all timing-dependent still doesn't seem like a great idea.
The 'normal' way to set up a server is with blocking calls, so that the server waits to receive data, rather than polling for it.
If a client connected through a socket requests data from the server, and the server in turn must request data from another source, here's how it should go (this is messy):
[tt]
+--------------------+ +--------------------+
| Srvr waits for req | | datasrc waits |
+--------------------+ +--------------------+
| |
blocked blocked
+------------------------+
* | Client sends a request | *
+------------------------+
unblocked < < < < < < < < < < < | *
| +------------------------+
+---------------------+ | Client waits for reply | *
| srvr processes req | +------------------------+
+---------------------+ | *
| blocked
+---------------------+ *
| srvr requests data | *
| from datasrc | *
+---------------------+ *
| > > > > > > > > > > > > > > > > > > > > > > > > unblocked
+---------------------+ * |
| srvr waits for reply| +--------------------+
+---------------------+ * | datasrc processes |
| | srvr's request |
blocked * +--------------------+
|
* * +--------------------+
| datasrc sends |
* * | reply to srvr |
+--------------------+
unblocked < < < < < < < < < < < < < < < < < < < < < < < < |
|
+---------------------+ *
| srvr sends reply |
| to client | *
+---------------------+
| > > > > > > > > > > > unblocked
|
+------------------------+
| Client receives reply. |
+------------------------+[/tt]
That seems to be what you need. Again, I get confused trying to understand your elaborate data request scheme and how sometimes you will provide stale data. And doing this on timers will only make matters worse.
P.S. I hate block diagrams
I REALLY hope that helps.
Will