| 1 |
// |
| 2 |
// Created by philip on 9/28/15. |
| 3 |
// |
| 4 |
|
| 5 |
#ifndef V4_0_QUEUE_HPP |
| 6 |
#define V4_0_QUEUE_HPP |
| 7 |
//#define __GXX_EXPERIMENTAL_CXX0X__ |
| 8 |
#include <iostream> |
| 9 |
#include <thread> |
| 10 |
#include <mutex> |
| 11 |
#include <condition_variable> |
| 12 |
#include <deque> |
| 13 |
#include <queue> |
| 14 |
|
| 15 |
template <typename T> |
| 16 |
class Queue { |
| 17 |
private: |
| 18 |
std::mutex d_mutex; |
| 19 |
std::condition_variable d_condition; |
| 20 |
std::queue<T> Q; |
| 21 |
public: |
| 22 |
// void push(T const& value) { |
| 23 |
void push(T value) { |
| 24 |
std::lock_guard<std::mutex> lock(d_mutex); |
| 25 |
Q.push(value); |
| 26 |
d_condition.notify_one(); |
| 27 |
}; |
| 28 |
T pop(void) { |
| 29 |
std::unique_lock<std::mutex> lock(d_mutex); |
| 30 |
d_condition.wait(lock, [=] { return !Q.empty(); }); |
| 31 |
T rc = Q.front(); |
| 32 |
Q.pop(); |
| 33 |
return rc; |
| 34 |
}; |
| 35 |
int size() { |
| 36 |
std::lock_guard<std::mutex> lock(d_mutex); |
| 37 |
return Q.size(); |
| 38 |
} |
| 39 |
}; |
| 40 |
|
| 41 |
struct LQ_rec { |
| 42 |
Socket *sock; |
| 43 |
unsigned int ct_type; |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
// CT_TYPE DEFS |
| 48 |
#define CT_PROXY 1 // Normal proxy connection also handles tranpartent http |
| 49 |
#define CT_THTTPS 2 // Transparent https connection |
| 50 |
#define CT_ICAP 4 // ICAP connection |
| 51 |
#define CT_PROXY_TLS 8 // Normal proxy connection over https |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
#endif //V4_0_QUEUE_HPP |