> Do critical sections work in the same > thread or only for different threads?
Critical section work only for different threads. > The receiver puts incomming bytes into a ringbuffer with a greater size > than the buffer where TWSocket.receive puts the data in in the first > place. Then it checks whether there are packets of my format in the > ringpuffer and as long as there is one, one is fetched and given to a > callback in my application. > I send them in the loop (no sleep between the iterations) the whole > thing gets stuck somewhere. When you send data using a for loop you will receive more than one of your packets into a single call to receive unless you first receive the length (which could be fragmented) and then call receive to receive at most the length of your packet (You may receive less !). You must really pay attention to your code to receive your data. Always think you'll receive less than what you would like, or more ! If you change your packet format slightly, you life may be easier: insted of length and data, send data and delimiter. You'll then be able to use TWSocket line mode. Contribute to the SSL Effort. Visit http://www.overbyte.be/eng/ssl.html -- [EMAIL PROTECTED] Author of ICS (Internet Component Suite, freeware) Author of MidWare (Multi-tier framework, freeware) http://www.overbyte.be ----- Original Message ----- From: "Markus Humm" <[EMAIL PROTECTED]> To: "ICS support mailing" <twsocket@elists.org> Sent: Thursday, September 14, 2006 10:53 PM Subject: [twsocket] complex problem, probably not ICS related > Hello, > > sorry, this will be just a tiny bit longer... ;-) > > I'm currently building some large application where several parts will > act together. Two of them are connected via TCP and TWSocket. One is > client and one server (okay there is TWSocketServer, but since there's > always a 1:1 relation between them and I don't have time to learn [and > wikify] all ICS components right now...). > > The client sends requests to the server and the server will send back > the replies in the same format. This format is as follows: > > 1 integer defining the length of my packet > 1 integer some ID I need > x byte the other needed data, can be any size but mostly < 100 bytes > 1 word CRC so that it doesn't get too easy to spoof my connection. > > The receiver puts incomming bytes into a ringbuffer with a greater size > than the buffer where TWSocket.receive puts the data in in the first > place. Then it checks whether there are packets of my format in the > ringpuffer and as long as there is one, one is fetched and given to a > callback in my application. There the syntax of the x byte is checked > and it is added to a TStringList. Reading and writing to the TStringList > is protected by the same critical section. > > On the other side of the TStringList is a thread which will fetach one > entry and process it (will take around 50ms), but requests can come in > as fast as possible, thus this TStringList. If no requests are left in > the TStringList the threads gets sleepy (GetMessage) until something is > put into the TStringList again, which also will inform the Thread via > PostThreadMessage. > > Replies generated from processing will be in the same packet format and > will be stored in another TStringList where another thread will fetch > one after one and send them back to the requester via the same TWSocket. > For the reply TStringList another critical section is used to protect it. > > I have now a simple test client where I can send packets manually via > button or 1000 in one go via a for loop. The test app. displays the > replies in a memo. If I send some requests manually, all is fine, but if > I send them in the loop (no sleep between the iterations) the whole > thing gets stuck somewhere. At least no answers get back and it seems > that these requests are added to the request TStringList (I can see the > count of it) but something prevents further processing. This is a real > block for me now. > > Now I want to rule out that it has something todo with the TWSocket and > or rinbuffer implementation. Do critical sections work in the same > thread or only for different threads? > > Greetings > > Markus > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be