Delphi-Cross-Socket icon indicating copy to clipboard operation
Delphi-Cross-Socket copied to clipboard

Received data corruption with EPoll on Android and Linux

Open allendrennan opened this issue 7 years ago • 3 comments

It is possible to corrupt the recv data stream on Android and Linux using the Epoll because more than one I/O thread could be processing a Read operation simultaneously. This is because a call to [TIoEvent.Read, TIoEvent.Write] is issued. This can cause OpenSSL to fail with a corrupted datastream because the order of calls to TriggerReceived() may be different than the order of calls to _HandleRead because 2 threads are processing a Read at the same time. A workaround is to have a special ReadLock in the Epoll class for _HandleRead so that a one-to-one match between calls to _HandleRead and TriggerReceived happens.

allendrennan avatar Nov 30 '17 19:11 allendrennan

EPOLLONESHOT can guarantee that there will never be two threads simultaneously trigger _HandleRead

winddriver avatar Feb 08 '18 01:02 winddriver

Due to the architectural problem of this framework, out-of-order reception occurs when a large number of packets are received, which is difficult to avoid. Unless each thread has its own Epoll or iocp or kqueue. Moreover, each Socket is bound in an io queue (that is, all IOs of a socket are processed by only one thread) to avoid this sticking.

HeZiHang avatar Aug 28 '18 14:08 HeZiHang

由于此框架的架构问题,大量包接收时会出现乱序接收现象,这是很难避免。 除非每个线程有各自的Epoll或iocp或kqueue。而且每个Socket绑定在一个io队列(即一个socket所有的IO仅由某一个线程来处理)才能避免粘包现象。

HeZiHang avatar Aug 28 '18 14:08 HeZiHang