1 #ifndef _STREAM_HANDLER_H
2 #define _STREAM_HANDLER_H
14 #include <condition_variable>
17 #include <sys/epoll.h>
18 #include <reading_stream.h>
21 #define MAX_EVENTS 40 // Number of epoll events in one epoll_wait call
22 #define RDS_BLOCK 10000 // Number of readings to insert in each call to the storage plugin
23 #define BLOCK_POOL_SIZES 512 // Increments of block sizes in a block pool
38 uint32_t create(
int epollfd, uint32_t *token);
39 void handleEvent(
int epollfd,
StorageApi *api, uint32_t events);
49 MemoryPool(
size_t blkIncr) : m_blkIncr(blkIncr) {};
51 void *allocate(
size_t size);
52 void release(
void *handle);
54 size_t rndSize(
size_t size)
56 return m_blkIncr * ((size + m_blkIncr - 1)
59 void createPool(
size_t size);
60 void growPool(std::vector<void *>*,
size_t);
62 std::map<size_t, std::vector<void *>* >
65 void setNonBlocking(
int fd);
66 unsigned int available(
int fd);
67 void queueInsert(
StorageApi *api,
unsigned int nReadings,
bool commit);
69 enum { Closed, Listen, AwaitingToken, Connected }
75 enum { BlkHdr, RdHdr, RdBody }
84 MemoryPool *m_blockPool;
85 std::string m_lastAsset;
89 std::thread m_handlerThread;
91 std::condition_variable m_streamsCV;
92 std::mutex m_streamsMutex;
93 std::vector<Stream *> m_streams;