source: filezilla/trunk/fuentes/src/engine/iothread.h @ 3185

Last change on this file since 3185 was 3185, checked in by jrpelegrina, 3 years ago

Update new version: 3.15.02

File size: 2.1 KB
Line 
1#ifndef __IOTHREAD_H__
2#define __IOTHREAD_H__
3
4#include <libfilezilla/event.hpp>
5
6#define BUFFERCOUNT 5
7#define BUFFERSIZE 128*1024
8
9// Does not actually read from or write to file
10// Useful for benchmarks to avoid IO bottleneck
11// skewing results
12//#define SIMULATE_IO
13
14struct io_thread_event_type{};
15typedef fz::simple_event<io_thread_event_type> CIOThreadEvent;
16
17enum IORet
18{
19        IO_Success = 0,
20        IO_Error = -2,
21        IO_Again = -1
22};
23
24namespace fz {
25class file;
26}
27
28class CIOThread final : protected fz::thread
29{
30public:
31        CIOThread();
32        virtual ~CIOThread();
33
34        bool Create(std::unique_ptr<fz::file> && pFile, bool read, bool binary);
35        virtual void Destroy(); // Only call that might be blocking
36
37        // Call before first call to one of the GetNext*Buffer functions
38        // This handler will receive the CIOThreadEvent events. The events
39        // get triggerd iff a buffer is available after a call to the
40        // GetNext*Buffer functions returned IO_Again
41        void SetEventHandler(fz::event_handler* handler);
42
43        // Gets next buffer
44        // Return value:  IO_Success on EOF
45        //                IO_Again if it would block
46        //                IO_Error on error
47        //                buffersize else
48        int GetNextReadBuffer(char** pBuffer);
49
50        // Gets next write buffer
51        // Return value: IO_Again if it would block
52        //               IO_Error on error
53        //               IO_Success else
54        int GetNextWriteBuffer(char** pBuffer);
55
56        bool Finalize(int len);
57
58        wxString GetError();
59
60private:
61        void Close();
62
63        virtual void entry();
64
65        int64_t ReadFromFile(char* pBuffer, int64_t maxLen);
66        bool WriteToFile(char* pBuffer, int64_t len);
67        bool DoWrite(const char* pBuffer, int64_t len);
68
69        fz::event_handler* m_evtHandler{};
70
71        bool m_read{};
72        bool m_binary{};
73        std::unique_ptr<fz::file> m_pFile;
74
75        char* m_buffers[BUFFERCOUNT];
76        unsigned int m_bufferLens[BUFFERCOUNT];
77
78        fz::mutex m_mutex;
79        fz::condition m_condition;
80
81        int m_curAppBuf{};
82        int m_curThreadBuf{};
83
84        bool m_error{};
85        bool m_running{};
86        bool m_threadWaiting{};
87        bool m_appWaiting{};
88
89        bool m_wasCarriageReturn{};
90
91        wxString m_error_description;
92
93#ifdef SIMULATE_IO
94        int64_t size_{};
95#endif
96};
97
98#endif //__IOTHREAD_H__
Note: See TracBrowser for help on using the repository browser.