Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stop the IdHTTP.Post stream upload without closing the connection
#8
(01-27-2019, 12:07 PM)vladimir Wrote: I use an SSL IOhandler. The main Post and Patch calls are executed in a thread. When I want to interrupt them and terminate the thread I called HTTP.Disconnect from the main thread, which causes AVs almost every time. The call stack shows that probably some SSL object was being freed by the disconnect, while still being used.

Yes, it is a known issue when using an SSLIOHandler, as you discovered.

(01-27-2019, 12:07 PM)vladimir Wrote: In the above SO answer you recommend using Socket.Binding.CloseSocket, instead of Disconnect. Is that still the recommended workaround, considering that the connection might be in a different state (e.g. trying to connect, or transferring)?

Yes. But you are responsible for keeping track of the state.

(01-27-2019, 12:07 PM)vladimir Wrote: This works, but raises EIdSocketError 10053, and I'm not sure whether its safe to ignore those.

Yes. That is just a standard "Connection aborted" error.

(01-27-2019, 12:07 PM)vladimir Wrote: Or maybe EIdNotASocket, if I close it before it has connected.

Closing the connection while it is still connecting can be a bit tricky, as that definitely suffers from race conditions. The socket may not have been allocated yet, or it may not have started connecting yet. Probably best to keep track of the state and not even try to close it until after it has fully connected first, then close it.

(01-28-2019, 09:11 PM)vladimir Wrote: And come to think of it, what is the best way to send a Post/Patch with a stream, not from the beginning of the stream, but from the current stream position.

The IOHandler Write() method has parameters to control that, but the way it is called from TIdHTTP it always resets the stream pos to 0.

Is there any method or property that I have missed that allows control of it from TIdHTTP?

No, you haven't missed anything. The input stream is sent in full each time. If you don't want to make copies of your data in separate streams, you will have to wrap the main stream inside of helper streams that simply expose access to subsets of the main stream's data. There are third party stream classes for that purpose, or you can write your own (not that hard to do). In fact, you might be able to utilize Indy's own TIdHTTPRangeStream class for this, though this is not its primary function (it is meant to be used with TIdHTTPServer instead).

Reply


Messages In This Thread
RE: Stop the IdHTTP.Post stream upload without closing the connection - by rlebeau - 01-30-2019, 12:18 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)