Re: [twsocket] Socket flushing
Hi Eric, You cannot be 100% all data is sent if you destroy or close a socket immediately after send. You should put code in OnDataSend and set a flag or so. At this point you know TWSocket has all data delivered to winsock but perhaps not yet sent. OnSendData is called after it, there you know winsock buffer is empty and will not fill again because buffer in TWSocket is empty. There you can call Shutdown or CloseDelayed. Then OnSessionClosed is fired. At this point you can call Release method to destroy TWSocket and / or your class. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Éric Fleming Bonilha Verzonden: maandag 1 augustus 2011 21:39 Aan: 'ICS support mailing' Onderwerp: Re: [twsocket] Socket flushing Then use Shutdown(2); Easy to do a testcase for Eric I think. His proposition to use Close() is not good, CloseDelayed should give a little better but not on a LAN. I see The problem is that I can´t wait, because actually this is can be even done on classes destructors such as: procedure TMyClass.SendTeardown; begin FSocket.Send(@Data[0], Length(Data)); end; destructor TMyClass.destroy; begin // Send RTSP Teardown message SendTeardown; // Release the socket FSocket.Free; inherited Destroy; end; So, I can´t wait for events or anything because the socket will be destroyed In my testing, if I send the data and destroy the socket, the data is actually sent (I can see it on sniffer), even on remote internet hosts Eric -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Arno Garrels Verzonden: maandag 1 augustus 2011 16:57 Aan: ICS support mailing Onderwerp: Re: [twsocket] Socket flushing Wilfried Mestdagh wrote: Hi Eric, Socket.Send(@Data[0], Length(Data)); Socket.Close; I think this is better: Socket.Send(@Data[0], Length(Data)); Socket.Shutdown(1); This can be dangerous, Shutdown(1) disables sends on the socket, if not all has been sent yet you'll get a socket exception on the next internal send attempt. Best practise is to set a flag and call it from OnDataSent if that flag is set. Well, you could check WSocket.AllSent however what would you do if it returnd False? -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Hi Arno, Why? Do you have arguments? No, just something I recall, but it is very long time ago so I assume you are right. I agree that Flush generally violates the async paradigm and _might cause problems, however removing the call to MessagePump should not make a difference. OK -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
If the reason that you call the Flush method is because you want to be sure all is sent before closing the socket then you can better call ShutDown(1) method. Yes, thats it, it is something like this Socket.Send(@Data[0], Length(Data)); Socket.Close; But I have found that if my data is small enough to fit on sending buffer, it is actually sent, even not calling Flush method, and since where I need flush my data is small I have removed Flush method from my entire code. Thank you for the replies! Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Hi Eric, Socket.Send(@Data[0], Length(Data)); Socket.Close; I think this is better: Socket.Send(@Data[0], Length(Data)); Socket.Shutdown(1); This will send all data, telling the other end to signal to close when received. There is in your case no need to call the Flush method. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Wilfried Mestdagh wrote: Hi Eric, Socket.Send(@Data[0], Length(Data)); Socket.Close; I think this is better: Socket.Send(@Data[0], Length(Data)); Socket.Shutdown(1); This can be dangerous, Shutdown(1) disables sends on the socket, if not all has been sent yet you'll get a socket exception on the next internal send attempt. Best practise is to set a flag and call it from OnDataSent if that flag is set. Well, you could check WSocket.AllSent however what would you do if it returnd False? -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Then use Shutdown(2); Easy to do a testcase for Eric I think. His proposition to use Close() is not good, CloseDelayed should give a little better but not on a LAN. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Arno Garrels Verzonden: maandag 1 augustus 2011 16:57 Aan: ICS support mailing Onderwerp: Re: [twsocket] Socket flushing Wilfried Mestdagh wrote: Hi Eric, Socket.Send(@Data[0], Length(Data)); Socket.Close; I think this is better: Socket.Send(@Data[0], Length(Data)); Socket.Shutdown(1); This can be dangerous, Shutdown(1) disables sends on the socket, if not all has been sent yet you'll get a socket exception on the next internal send attempt. Best practise is to set a flag and call it from OnDataSent if that flag is set. Well, you could check WSocket.AllSent however what would you do if it returnd False? -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Then use Shutdown(2); Easy to do a testcase for Eric I think. His proposition to use Close() is not good, CloseDelayed should give a little better but not on a LAN. I see The problem is that I can´t wait, because actually this is can be even done on classes destructors such as: procedure TMyClass.SendTeardown; begin FSocket.Send(@Data[0], Length(Data)); end; destructor TMyClass.destroy; begin // Send RTSP Teardown message SendTeardown; // Release the socket FSocket.Free; inherited Destroy; end; So, I can´t wait for events or anything because the socket will be destroyed In my testing, if I send the data and destroy the socket, the data is actually sent (I can see it on sniffer), even on remote internet hosts Eric -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Arno Garrels Verzonden: maandag 1 augustus 2011 16:57 Aan: ICS support mailing Onderwerp: Re: [twsocket] Socket flushing Wilfried Mestdagh wrote: Hi Eric, Socket.Send(@Data[0], Length(Data)); Socket.Close; I think this is better: Socket.Send(@Data[0], Length(Data)); Socket.Shutdown(1); This can be dangerous, Shutdown(1) disables sends on the socket, if not all has been sent yet you'll get a socket exception on the next internal send attempt. Best practise is to set a flag and call it from OnDataSent if that flag is set. Well, you could check WSocket.AllSent however what would you do if it returnd False? -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
H Eric, If I keep a loop like this while (FHSocket INVALID_SOCKET) and (not bAllSent) do TryToSend; And TryToSend fails, will it fail everytime if I don´t call the message pump? In this case an infinite loop would happen right? I think so yes. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Hi Eric, If the reason that you call the Flush method is because you want to be sure all is sent before closing the socket then you can better call ShutDown(1) method. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Wilfried Mestdagh wrote: H Eric, If I keep a loop like this while (FHSocket INVALID_SOCKET) and (not bAllSent) do TryToSend; And TryToSend fails, will it fail everytime if I don´t call the message pump? In this case an infinite loop would happen right? I think so yes. Why? Do you have arguments? I agree that Flush generally violates the async paradigm and _might cause problems, however removing the call to MessagePump should not make a difference. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Arno Garrels wrote: Wilfried Mestdagh wrote: H Eric, If I keep a loop like this while (FHSocket INVALID_SOCKET) and (not bAllSent) do TryToSend; And TryToSend fails, will it fail everytime if I don´t call the message pump? In this case an infinite loop would happen right? I think so yes. Why? Do you have arguments? I agree that Flush generally violates the async paradigm and _might cause problems, however removing the call to MessagePump should not make a difference. One could i.e. call the MessagePump when the loop finished _if required to make sure that event OnDataSent is called at once rather than on next application idle. -- Arno Garrels -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Wilfried TryToSend will exit if winsock returns WSAEWOULDBLOCK. I think that is the reason for the message pump call. I never used the Flush method. Ok, I see this point If I keep a loop like this while (FHSocket INVALID_SOCKET) and (not bAllSent) do TryToSend; And TryToSend fails, will it fail everytime if I don´t call the message pump? In this case an infinite loop would happen right? Eric -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Éric Fleming Bonilha Verzonden: maandag 25 juli 2011 14:50 Aan: ICS support mailing Onderwerp: Re: [twsocket] Socket flushing Nobody knows??? Eric -Mensagem Original- From: Éric Fleming Bonilha Sent: Friday, July 22, 2011 5:35 PM To: ICS support mailing Subject: Re: [twsocket] Socket flushing What issues? It is a weird issue... it actually creates a stack overflow because in some parts of my app I need to call flush, and flush calls the messageloop and on messageloop some timer routines are called that enters again on the same routine to flush the socket! it is complicated... and only happened once but it can happen... Good question :) This dates from 1994... Hum, does anybody remember? I was just wondering if this routine could enter on an infinite loop, if there is no way to enter on an infinite loop I will remove the MessageLoop call from my derivate class Best Regards Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Hi Eric, TryToSend will exit if winsock returns WSAEWOULDBLOCK. I think that is the reason for the message pump call. I never used the Flush method. -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Éric Fleming Bonilha Verzonden: maandag 25 juli 2011 14:50 Aan: ICS support mailing Onderwerp: Re: [twsocket] Socket flushing Nobody knows??? Eric -Mensagem Original- From: Éric Fleming Bonilha Sent: Friday, July 22, 2011 5:35 PM To: ICS support mailing Subject: Re: [twsocket] Socket flushing What issues? It is a weird issue... it actually creates a stack overflow because in some parts of my app I need to call flush, and flush calls the messageloop and on messageloop some timer routines are called that enters again on the same routine to flush the socket! it is complicated... and only happened once but it can happen... Good question :) This dates from 1994... Hum, does anybody remember? I was just wondering if this routine could enter on an infinite loop, if there is no way to enter on an infinite loop I will remove the MessageLoop call from my derivate class Best Regards Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Nobody knows??? Eric -Mensagem Original- From: Éric Fleming Bonilha Sent: Friday, July 22, 2011 5:35 PM To: ICS support mailing Subject: Re: [twsocket] Socket flushing What issues? It is a weird issue... it actually creates a stack overflow because in some parts of my app I need to call flush, and flush calls the messageloop and on messageloop some timer routines are called that enters again on the same routine to flush the socket! it is complicated... and only happened once but it can happen... Good question :) This dates from 1994... Hum, does anybody remember? I was just wondering if this routine could enter on an infinite loop, if there is no way to enter on an infinite loop I will remove the MessageLoop call from my derivate class Best Regards Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
Éric Fleming Bonilha wrote: Nobody knows??? I don't know for sure, I don't use that method, in doubt a look at the source code might give an answer. -- Arno Garrels Eric -Mensagem Original- From: Éric Fleming Bonilha Sent: Friday, July 22, 2011 5:35 PM To: ICS support mailing Subject: Re: [twsocket] Socket flushing What issues? It is a weird issue... it actually creates a stack overflow because in some parts of my app I need to call flush, and flush calls the messageloop and on messageloop some timer routines are called that enters again on the same routine to flush the socket! it is complicated... and only happened once but it can happen... Good question :) This dates from 1994... Hum, does anybody remember? I was just wondering if this routine could enter on an infinite loop, if there is no way to enter on an infinite loop I will remove the MessageLoop call from my derivate class Best Regards Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
I´m having some issues with socket flushing due to the messageloop that What issues? What is the purpose of calling MessagePump over here? Good question :) This dates from 1994... -- mvg, Wilfried http://www.mestdagh.biz http://www.comfortsoftware.be http://www.expertsoftware.be -Oorspronkelijk bericht- Van: twsocket-boun...@elists.org [mailto:twsocket-boun...@elists.org] Namens Éric Fleming Bonilha Verzonden: donderdag 21 juli 2011 22:30 Aan: ICS support mailing Onderwerp: [twsocket] Socket flushing Hi I´m having some issues with socket flushing due to the messageloop that it calls: procedure TCustomWSocket.Flush; begin while (FHSocket INVALID_SOCKET) and { No more socket } (not bAllSent) do begin { Nothing to send } { Break; } TryToSend; MessagePump; end; end; If I override the Flush method and remove the messagePump in my derived socket class: procedure TMySocket.Flush; begin while (FHSocket INVALID_SOCKET) and { No more socket } (not bAllSent) do begin { Nothing to send } { Break; } TryToSend; end; end; What consequences I will have? Does this routine has the possibility to enter on a never ending loop without the MessagePump call? What is the purpose of calling MessagePump over here? Thanks Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
Re: [twsocket] Socket flushing
What issues? It is a weird issue... it actually creates a stack overflow because in some parts of my app I need to call flush, and flush calls the messageloop and on messageloop some timer routines are called that enters again on the same routine to flush the socket! it is complicated... and only happened once but it can happen... Good question :) This dates from 1994... Hum, does anybody remember? I was just wondering if this routine could enter on an infinite loop, if there is no way to enter on an infinite loop I will remove the MessageLoop call from my derivate class Best Regards Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be
[twsocket] Socket flushing
Hi I´m having some issues with socket flushing due to the messageloop that it calls: procedure TCustomWSocket.Flush; begin while (FHSocket INVALID_SOCKET) and { No more socket } (not bAllSent) do begin { Nothing to send } { Break; } TryToSend; MessagePump; end; end; If I override the Flush method and remove the messagePump in my derived socket class: procedure TMySocket.Flush; begin while (FHSocket INVALID_SOCKET) and { No more socket } (not bAllSent) do begin { Nothing to send } { Break; } TryToSend; end; end; What consequences I will have? Does this routine has the possibility to enter on a never ending loop without the MessagePump call? What is the purpose of calling MessagePump over here? Thanks Eric -- To unsubscribe or change your settings for TWSocket mailing list please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be