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

Reply via email to