├── NetWork_Disk ├── BusyThreadContainer.cpp ├── BusyThreadContainer.h ├── File.cpp ├── File.h ├── IdleThreadContainer.cpp ├── IdleThreadContainer.h ├── MyTask.cpp ├── MyTask.h ├── MyThread.cpp ├── MyThread.h ├── MyThreadPool.cpp ├── MyThreadPool.h ├── Task.h ├── TaskContainer.cpp ├── TaskContainer.h ├── main ├── main.cpp └── tags ├── README.md ├── server └── server.cpp /NetWork_Disk/BusyThreadContainer.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: BusyThreadContainer.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时32分34秒 6 | ************************************************************************/ 7 | #include "BusyThreadContainer.h" 8 | #include"MyThread.h" 9 | #include 10 | 11 | BusyThreadContainer::BusyThreadContainer() 12 | { 13 | } 14 | BusyThreadContainer::~BusyThreadContainer() 15 | { 16 | } 17 | 18 | void BusyThreadContainer::push(MyThread *m) 19 | { 20 | //尾部插入线程 21 | busy_thread_container_.push_back(m); 22 | } 23 | 24 | void BusyThreadContainer::erase(MyThread *m) 25 | { 26 | busy_thread_container_.erase(find(busy_thread_container_.begin(),busy_thread_container_.end(),m)); 27 | } 28 | 29 | 30 | std::list::size_type BusyThreadContainer::size() 31 | { 32 | return busy_thread_container_.size(); 33 | } 34 | 35 | -------------------------------------------------------------------------------- /NetWork_Disk/BusyThreadContainer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: BusyThreadContainer.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时41分29秒 6 | ************************************************************************/ 7 | 8 | #ifndef _BUSYTHREADCONTAINER_H 9 | #define _BUSYTHREADCONTAINER_H 10 | #include 11 | 12 | /* 13 | * 工作容器类 14 | */ 15 | 16 | class MyThread; 17 | 18 | class BusyThreadContainer 19 | { 20 | public: 21 | BusyThreadContainer(); 22 | ~BusyThreadContainer(); 23 | 24 | /* 25 | * 将一个线程加入工作容器 26 | */ 27 | void push(MyThread *m); 28 | 29 | /* 30 | *返回工作容器大小 31 | */ 32 | std::list::size_type size(); 33 | 34 | /* 35 | * 删除一个制定线程 36 | */ 37 | void erase(MyThread *m); 38 | 39 | private: 40 | std::list busy_thread_container_; 41 | typedef std::list Container; 42 | typedef Container::iterator Iterator; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /NetWork_Disk/File.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: File.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月10日 星期三 18时51分36秒 6 | ************************************************************************/ 7 | 8 | #include"File.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | File::File(const std::string &fileName) 14 | { 15 | this->file.open(fileName, std::ios::binary); 16 | if(this->file.is_open()) 17 | { 18 | std::cout << "File get!" << std::endl; 19 | } 20 | else 21 | { 22 | std::cout << "File unget!" << std::endl; 23 | } 24 | this->file.seekg(0, std::ios::end); 25 | fileSize = file.tellg(); 26 | std::cout << "File Size : " << fileSize << std::endl; 27 | blockNum = ceil(static_cast(fileSize) / (1024 * 1024 * 4)); 28 | std::cout << "Block Count: " << blockNum <file).close(); 33 | } 34 | int File::getBlockNum() 35 | { 36 | return this->blockNum; 37 | } 38 | 39 | -------------------------------------------------------------------------------- /NetWork_Disk/File.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: File.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月10日 星期三 18时44分26秒 6 | ************************************************************************/ 7 | 8 | #ifndef _FILE_H 9 | #define _FILE_H 10 | #include 11 | 12 | class File 13 | { 14 | public: 15 | File(const std::string &fileName); 16 | ~File(){} 17 | long getSize(); 18 | void Close(); 19 | int getBlockNum(); 20 | 21 | std::ifstream file; 22 | private: 23 | int blockNum; 24 | long fileSize; 25 | 26 | }; 27 | 28 | 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /NetWork_Disk/IdleThreadContainer.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: IdleThreadContainer.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时35分01秒 6 | ************************************************************************/ 7 | 8 | #include "IdleThreadContainer.h" 9 | #include "MyThread.h" 10 | #include 11 | #include 12 | 13 | using std::cout; 14 | using std::endl; 15 | IdleThreadContainer::IdleThreadContainer() 16 | { 17 | } 18 | 19 | 20 | IdleThreadContainer::~IdleThreadContainer() 21 | { 22 | int i = 0; 23 | for (Iterator it = idle_thread_container_.begin(); it != idle_thread_container_.end(); it++) 24 | { 25 | cout << i++ << endl; 26 | delete *it; 27 | } 28 | } 29 | 30 | std::vector::size_type IdleThreadContainer::size() 31 | { 32 | return idle_thread_container_.size(); 33 | } 34 | 35 | 36 | void IdleThreadContainer::push(MyThread *m) 37 | { 38 | idle_thread_container_.push_back(m); 39 | } 40 | 41 | 42 | void IdleThreadContainer::pop() 43 | { 44 | idle_thread_container_.pop_back(); 45 | } 46 | 47 | 48 | void IdleThreadContainer::erase(MyThread *m) 49 | { 50 | idle_thread_container_.erase(find(idle_thread_container_.begin(), idle_thread_container_.end(), m)); 51 | } 52 | 53 | 54 | void IdleThreadContainer::assign(int number, MyThreadPool *m) 55 | { 56 | for (int i = 0; i < number; i++) 57 | { 58 | MyThread *p = new MyThread(m); 59 | idle_thread_container_.push_back(p); 60 | } 61 | } 62 | 63 | 64 | MyThread* IdleThreadContainer::top() 65 | { 66 | 67 | return idle_thread_container_.back(); 68 | } 69 | -------------------------------------------------------------------------------- /NetWork_Disk/IdleThreadContainer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: IdleThreadContainer.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时41分56秒 6 | ************************************************************************/ 7 | 8 | #ifndef _IDLETHREADCONTAINER_H 9 | #define _IDLETHREADCONTAINER_H 10 | #include 11 | 12 | class MyThread; 13 | class MyThreadPool; 14 | class IdleThreadContainer 15 | { 16 | 17 | public: 18 | IdleThreadContainer(); 19 | ~IdleThreadContainer(); 20 | std::vector::size_type size(); 21 | 22 | /* 23 | * 将一个线程放入空闲容器 24 | */ 25 | void push(MyThread *m); 26 | 27 | /* 28 | * 创建n个线程 与 线程池m 相关联的线程放入 29 | * 空闲容器。 30 | * 初始化。 31 | */ 32 | void assign(int n,MyThreadPool* m); 33 | 34 | /* 35 | * 返回容器顶端的线程 36 | */ 37 | MyThread* top(); 38 | 39 | /* 40 | * 弹出容器顶端的线程 41 | */ 42 | void pop(); 43 | 44 | /* 45 | * 删除一个指定的线程 46 | */ 47 | void erase(MyThread *m); 48 | private: 49 | std::vector idle_thread_container_; 50 | typedef std::vector Container; 51 | typedef Container::iterator Iterator; 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /NetWork_Disk/MyTask.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: MyTask.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时42分24秒 6 | ************************************************************************/ 7 | 8 | #include 9 | #include"MyTask.h" 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | using std::string; 18 | using std::cout; 19 | using std::endl; 20 | void MyTask::Run() 21 | { 22 | cout << this->blockID << "Run: "; 23 | void *pCtx = NULL; 24 | void *pSock = NULL; 25 | const char * pAddr = "tcp://127.0.0.1:7766"; 26 | 27 | if((pCtx = zmq_ctx_new()) == NULL) 28 | { 29 | return ; 30 | } 31 | 32 | if((pSock = zmq_socket(pCtx, ZMQ_DEALER)) == NULL) 33 | { 34 | zmq_ctx_destroy(pCtx); 35 | return ; 36 | } 37 | 38 | int iSndTimeOut = 5000; 39 | 40 | if(zmq_setsockopt(pSock, ZMQ_RCVTIMEO, &iSndTimeOut, sizeof(iSndTimeOut)) < 0) 41 | { 42 | zmq_close(pSock); 43 | zmq_ctx_destroy(pCtx); 44 | return ; 45 | } 46 | 47 | if(zmq_connect(pSock, pAddr) < 0) 48 | { 49 | zmq_close(pSock); 50 | zmq_ctx_destroy(pCtx); 51 | } 52 | 53 | 54 | char block[1024 * 1024 * 4]; 55 | this->file->file.seekg((blockID - 1) * 1024 * 1024 * 4, std::ios::beg); 56 | this->file->file.read(block, sizeof(block)); 57 | 58 | 59 | if(zmq_send(pSock, block, sizeof(block), 0) < 0) 60 | { 61 | std::cout<<"Send message error!!"<blockID << " Send" << std::endl; 66 | 67 | } 68 | 69 | 70 | std::this_thread::sleep_for(std::chrono::seconds(1)); 71 | } 72 | 73 | -------------------------------------------------------------------------------- /NetWork_Disk/MyTask.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: MyTask.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时35分52秒 6 | ************************************************************************/ 7 | 8 | #ifndef _MYTASK_H 9 | #define _MYTASK_H 10 | 11 | #include "Task.h" 12 | #include"File.h" 13 | 14 | 15 | class MyTask : public Task 16 | { 17 | public: 18 | MyTask(int id, File *file1):blockID(id) 19 | , file(file1) 20 | {} 21 | ~MyTask(){} 22 | virtual void Run(); 23 | 24 | 25 | private: 26 | int blockID; 27 | File *file; 28 | }; 29 | 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /NetWork_Disk/MyThread.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: MyThread.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时44分02秒 6 | ************************************************************************/ 7 | 8 | #include "MyThread.h" 9 | #include "MyThreadPool.h" 10 | #include 11 | 12 | using std::cout; 13 | using std::thread; 14 | 15 | int MyThread::s_threadnumber = 0; 16 | MyThread::MyThread(MyThreadPool *pool):mythreadpool_(pool), isdetach_(true) 17 | { 18 | //加锁? 19 | s_threadnumber++; 20 | threadid_ = s_threadnumber; 21 | } 22 | 23 | 24 | void MyThread::setisdetach(bool detach) 25 | { 26 | isdetach_ = detach; 27 | } 28 | 29 | 30 | void MyThread::Assign(Task *t) 31 | { 32 | task_ =t; 33 | } 34 | 35 | 36 | 37 | void MyThread::Run() 38 | { 39 | cout <<"Thread:"<< threadid_ << " run "; 40 | //执行任务 41 | task_->Run(); 42 | 43 | //从Busy中移除 44 | this->mythreadpool_->RemoveThreadFromBusy(this); 45 | } 46 | 47 | 48 | int MyThread::getthreadid() 49 | { 50 | return this->threadid_; 51 | } 52 | 53 | 54 | void MyThread::StartThread() 55 | { 56 | //设置thread,开始执行 57 | this->thread_ = thread(&MyThread::Run, this); 58 | if (isdetach_ == true) 59 | thread_.detach(); 60 | else 61 | thread_.join(); 62 | } 63 | 64 | bool operator==(MyThread my1, MyThread my2) 65 | { 66 | return my1.threadid_ == my2.threadid_; 67 | } 68 | bool operator!=(MyThread my1, MyThread my2) 69 | { 70 | return !(my1.threadid_ == my2.threadid_); 71 | } 72 | -------------------------------------------------------------------------------- /NetWork_Disk/MyThread.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: MyThread.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时37分02秒 6 | ************************************************************************/ 7 | 8 | #ifndef _MYTHREAD_H 9 | #define _MYTHREAD_H 10 | 11 | #include "Task.h" 12 | #include 13 | 14 | class MyThreadPool; 15 | class Task; 16 | 17 | class MyThread 18 | { 19 | 20 | friend bool operator==(MyThread my1, MyThread my2); 21 | friend bool operator!=(MyThread my1, MyThread my2); 22 | public: 23 | //构造函数,将与一个 线程池 关联 24 | MyThread(MyThreadPool *pool); 25 | 26 | //将线程与一个 任务 关联 27 | void Assign(Task *Task); 28 | 29 | /* 30 | * 调用task 的 run方法,同时在Task的Run()方法结束后将自己 31 | * 从工作工作容器 移会 空闲容器 32 | */ 33 | void Run(); 34 | 35 | /* 36 | * 执行线程的Run方法,即执行任务的Run方法 37 | */ 38 | void StartThread(); 39 | 40 | /* 41 | * 获取线程的id号 42 | */ 43 | int getthreadid(); 44 | 45 | /* 46 | * 设置线程在运行时是join还是detach 47 | */ 48 | void setisdetach(bool isdetach); 49 | private: 50 | MyThreadPool *mythreadpool_; //指向关联的线程池 51 | static int s_threadnumber; 52 | bool isdetach_; 53 | Task *task_; //关联的任务 54 | int threadid_; //线程id 55 | std::thread thread_; 56 | }; 57 | 58 | 59 | 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /NetWork_Disk/MyThreadPool.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: MyThreadPool.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时44分44秒 6 | ************************************************************************/ 7 | 8 | #include "MyThreadPool.h" 9 | #include 10 | using namespace std; 11 | MyThreadPool::MyThreadPool(int number) 12 | { 13 | issurvive_ = true; 14 | number_of_thread_ = number; 15 | //创建线程 到 空闲容器 16 | idle_thread_container_.assign(number, this); 17 | thread_this_ = thread(&MyThreadPool::Start, this); 18 | thread_this_.detach(); 19 | } 20 | MyThreadPool::~MyThreadPool() 21 | { 22 | 23 | } 24 | void MyThreadPool::EndMyThreadPool() 25 | { 26 | issurvive_ =false; 27 | } 28 | 29 | void MyThreadPool::AddIdleThread(int n) 30 | { 31 | idle_mutex_.lock(); 32 | idle_thread_container_.assign(n, this); 33 | number_of_thread_ += n; 34 | idle_mutex_.unlock(); 35 | } 36 | void MyThreadPool::Start() 37 | { 38 | cout<<"Main Thread Run"<Assign(newTask); 78 | idle_mutex_.unlock(); 79 | 80 | busy_mutex_.lock(); 81 | busy_thread_container_.push(topIdleThread); 82 | busy_mutex_.unlock(); 83 | topIdleThread->StartThread(); 84 | } 85 | } 86 | void MyThreadPool::AddTask(Task *Task, int priority = (PRIORITY::NORMAL)) 87 | { 88 | 89 | Task->SetPriority(priority); 90 | task_mutex_.lock(); 91 | task_container_.push(Task); 92 | task_mutex_.unlock(); 93 | } 94 | void MyThreadPool::RemoveThreadFromBusy(MyThread *myThread) 95 | { 96 | 97 | busy_mutex_.lock(); 98 | cout << "Thread:" << myThread->getthreadid()<< " remove from busylist" << endl; 99 | busy_thread_container_.erase(myThread); 100 | busy_mutex_.unlock(); 101 | 102 | idle_mutex_.lock(); 103 | idle_thread_container_.push(myThread); 104 | idle_mutex_.unlock(); 105 | } 106 | -------------------------------------------------------------------------------- /NetWork_Disk/MyThreadPool.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: MyThreadPool.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时39分00秒 6 | ************************************************************************/ 7 | 8 | #ifndef _MYTHREADPOOL_H 9 | #define _MYTHREADPOOL_H 10 | 11 | #include 12 | #include 13 | #include "Task.h" 14 | #include "MyThread.h" 15 | #include "BusyThreadContainer.h" 16 | #include "IdleThreadContainer.h" 17 | #include "TaskContainer.h" 18 | 19 | class MyThread; 20 | class MyThreadPool 21 | { 22 | public: 23 | 24 | MyThreadPool() = delete; 25 | 26 | /* 27 | * 构造包含number个线程的空闲容器 28 | */ 29 | MyThreadPool(int number); 30 | 31 | ~MyThreadPool(); 32 | 33 | /* 34 | * 添加一个 优先级为priority 的任务 到任务队列 35 | */ 36 | void AddTask(Task *Task,int priority); 37 | 38 | /* 39 | * 创建并加入n个线程 到 空闲容器 40 | */ 41 | void AddIdleThread(int n); 42 | 43 | /* 44 | * 将指定线程从 工作容器中删除 45 | */ 46 | void RemoveThreadFromBusy(MyThread *myThread); 47 | 48 | /* 49 | * 判断是否有空闲线程,如果有,将任务从任务容器 50 | * 中提出,放入空闲容器中,等待执行 51 | */ 52 | void Start(); 53 | 54 | /* 55 | * 结束线程池运行 56 | */ 57 | void EndMyThreadPool(); 58 | private: 59 | BusyThreadContainer busy_thread_container_; 60 | IdleThreadContainer idle_thread_container_; 61 | bool issurvive_; 62 | TaskContainer task_container_; 63 | std::thread thread_this_; //线程池运行线程 64 | std::mutex busy_mutex_; 65 | std::mutex idle_mutex_; 66 | std::mutex task_mutex_; 67 | int number_of_thread_; 68 | }; 69 | 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /NetWork_Disk/Task.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Task.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时40分51秒 6 | ************************************************************************/ 7 | 8 | #ifndef _TASK_H 9 | #define _TASK_H 10 | 11 | namespace 12 | { 13 | enum PRIORITY 14 | { 15 | 16 | MIN = 1, NORMAL = 25, MAX = 50 17 | }; 18 | } 19 | 20 | class Task 21 | { 22 | 23 | public: 24 | Task() 25 | { 26 | 27 | } 28 | void SetPriority(int priority) 29 | { 30 | if (priority > (PRIORITY::MAX)) 31 | { 32 | this->priority_ = (PRIORITY::MAX); 33 | } 34 | else if (priority < (PRIORITY::MIN)) 35 | { 36 | this->priority_ = (PRIORITY::MIN); 37 | } 38 | } 39 | virtual void Run() = 0; 40 | protected: 41 | int priority_; 42 | }; 43 | #endif 44 | -------------------------------------------------------------------------------- /NetWork_Disk/TaskContainer.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: TaskContainer.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时45分21秒 6 | ************************************************************************/ 7 | 8 | #include "TaskContainer.h" 9 | 10 | 11 | TaskContainer::TaskContainer() 12 | { 13 | } 14 | 15 | 16 | TaskContainer::~TaskContainer() 17 | { 18 | } 19 | void TaskContainer::push(Task* t) 20 | { 21 | task_container_.push(t); 22 | } 23 | Task* TaskContainer::top() 24 | { 25 | return task_container_.top(); 26 | } 27 | void TaskContainer::pop() 28 | { 29 | task_container_.pop(); 30 | } 31 | std::priority_queue::size_type TaskContainer::size() 32 | { 33 | return task_container_.size(); 34 | } 35 | -------------------------------------------------------------------------------- /NetWork_Disk/TaskContainer.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: TaskContainer.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时39分59秒 6 | ************************************************************************/ 7 | 8 | #ifndef _TASKCONTAINER_H 9 | #define _TASKCONTAINER_H 10 | #include 11 | class Task; 12 | class TaskContainer 13 | { 14 | public: 15 | TaskContainer(); 16 | ~TaskContainer(); 17 | void push(Task *); 18 | Task* top(); 19 | void pop(); 20 | std::priority_queue::size_type size(); 21 | private: 22 | std::priority_queue task_container_; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /NetWork_Disk/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foshougua/network-dash/d32c0bcd60273df555bfecfb150f139ebf9f1f7e/NetWork_Disk/main -------------------------------------------------------------------------------- /NetWork_Disk/main.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: main.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月09日 星期二 09时47分21秒 6 | ************************************************************************/ 7 | 8 | #include "MyThreadPool.h" 9 | #include "MyTask.h" 10 | #include 11 | #include 12 | #include 13 | using namespace std; 14 | 15 | 16 | 17 | 18 | 19 | 20 | int main() 21 | { 22 | MyThreadPool mythreadPool(10); 23 | 24 | string filename = "./MyThreadPool.cpp"; 25 | File file(filename); 26 | int blockNum = file.getBlockNum(); 27 | vector vec; 28 | for(int i = 0; i < blockNum; i++) 29 | { 30 | MyTask *block = new MyTask(i + 1, &file); 31 | vec.push_back(block); 32 | } 33 | for (int i = 0; i < blockNum; i++) 34 | { 35 | mythreadPool.AddTask(vec[i], 0); 36 | } 37 | 38 | sleep(10); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /NetWork_Disk/tags: -------------------------------------------------------------------------------- 1 | !_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/ 2 | !_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/ 3 | !_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/ 4 | !_TAG_PROGRAM_NAME Exuberant Ctags // 5 | !_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/ 6 | !_TAG_PROGRAM_VERSION 5.9~svn20110310 // 7 | AddIdleThread MyThreadPool.cpp /^void MyThreadPool::AddIdleThread(int n)$/;" f class:MyThreadPool 8 | AddTask MyThreadPool.cpp /^void MyThreadPool::AddTask(Task *Task, int priority = (PRIORITY::NORMAL))$/;" f class:MyThreadPool 9 | Assign MyThread.cpp /^void MyThread::Assign(Task *t)$/;" f class:MyThread 10 | BusyThreadContainer BusyThreadContainer.cpp /^BusyThreadContainer::BusyThreadContainer()$/;" f class:BusyThreadContainer 11 | BusyThreadContainer BusyThreadContainer.h /^class BusyThreadContainer$/;" c 12 | Close File.cpp /^void File::Close()$/;" f class:File 13 | Container BusyThreadContainer.h /^ typedef std::list Container;$/;" t class:BusyThreadContainer 14 | Container IdleThreadContainer.h /^ typedef std::vector Container;$/;" t class:IdleThreadContainer 15 | EndMyThreadPool MyThreadPool.cpp /^void MyThreadPool::EndMyThreadPool()$/;" f class:MyThreadPool 16 | File File.cpp /^File::File(const std::string &fileName)$/;" f class:File 17 | File File.h /^class File$/;" c 18 | File MyTask.h /^class File$/;" c 19 | IdleThreadContainer IdleThreadContainer.cpp /^IdleThreadContainer::IdleThreadContainer()$/;" f class:IdleThreadContainer 20 | IdleThreadContainer IdleThreadContainer.h /^class IdleThreadContainer$/;" c 21 | Iterator BusyThreadContainer.h /^ typedef Container::iterator Iterator;$/;" t class:BusyThreadContainer 22 | Iterator IdleThreadContainer.h /^ typedef Container::iterator Iterator;$/;" t class:IdleThreadContainer 23 | MAX Task.h /^ MIN = 1, NORMAL = 25, MAX = 50$/;" e enum:__anon1::PRIORITY 24 | MIN Task.h /^ MIN = 1, NORMAL = 25, MAX = 50$/;" e enum:__anon1::PRIORITY 25 | MyTask MyTask.h /^ MyTask(int id, File *file1):blockID(id)$/;" f class:MyTask 26 | MyTask MyTask.h /^class MyTask : public Task$/;" c 27 | MyThread MyThread.cpp /^MyThread::MyThread(MyThreadPool *pool):mythreadpool_(pool), isdetach_(true)$/;" f class:MyThread 28 | MyThread MyThread.h /^class MyThread$/;" c 29 | MyThreadPool MyThreadPool.cpp /^MyThreadPool::MyThreadPool(int number)$/;" f class:MyThreadPool 30 | MyThreadPool MyThreadPool.h /^class MyThreadPool$/;" c 31 | NORMAL Task.h /^ MIN = 1, NORMAL = 25, MAX = 50$/;" e enum:__anon1::PRIORITY 32 | PRIORITY Task.h /^ enum PRIORITY$/;" g namespace:__anon1 33 | RemoveThreadFromBusy MyThreadPool.cpp /^void MyThreadPool::RemoveThreadFromBusy(MyThread *myThread)$/;" f class:MyThreadPool 34 | Run MyTask.cpp /^void MyTask::Run()$/;" f class:MyTask 35 | Run MyThread.cpp /^void MyThread::Run()$/;" f class:MyThread 36 | SetPriority Task.h /^ void SetPriority(int priority)$/;" f class:Task 37 | Start MyThreadPool.cpp /^void MyThreadPool::Start()$/;" f class:MyThreadPool 38 | StartThread MyThread.cpp /^void MyThread::StartThread()$/;" f class:MyThread 39 | Task Task.h /^ Task()$/;" f class:Task 40 | Task Task.h /^class Task$/;" c 41 | TaskContainer TaskContainer.cpp /^TaskContainer::TaskContainer()$/;" f class:TaskContainer 42 | TaskContainer TaskContainer.h /^class TaskContainer$/;" c 43 | _BUSYTHREADCONTAINER_H BusyThreadContainer.h 9;" d 44 | _FILE_H File.h 9;" d 45 | _IDLETHREADCONTAINER_H IdleThreadContainer.h 9;" d 46 | _MYTASK_H MyTask.h 9;" d 47 | _MYTHREADPOOL_H MyThreadPool.h 9;" d 48 | _MYTHREAD_H MyThread.h 9;" d 49 | _TASKCONTAINER_H TaskContainer.h 9;" d 50 | _TASK_H Task.h 9;" d 51 | assign IdleThreadContainer.cpp /^void IdleThreadContainer::assign(int number, MyThreadPool *m)$/;" f class:IdleThreadContainer 52 | blockID MyTask.h /^ int blockID;$/;" m class:MyTask 53 | blockNum File.h /^ int blockNum;$/;" m class:File 54 | blockNum MyTask.h /^ int blockNum;$/;" m class:File 55 | busy_mutex_ MyThreadPool.h /^ std::mutex busy_mutex_;$/;" m class:MyThreadPool 56 | busy_thread_container_ BusyThreadContainer.h /^ std::list busy_thread_container_;$/;" m class:BusyThreadContainer 57 | busy_thread_container_ MyThreadPool.h /^ BusyThreadContainer busy_thread_container_;$/;" m class:MyThreadPool 58 | erase BusyThreadContainer.cpp /^void BusyThreadContainer::erase(MyThread *m)$/;" f class:BusyThreadContainer 59 | erase IdleThreadContainer.cpp /^void IdleThreadContainer::erase(MyThread *m)$/;" f class:IdleThreadContainer 60 | file File.h /^ fstream file;$/;" m class:File 61 | file MyTask.h /^ File *file;$/;" m class:MyTask 62 | file MyTask.h /^ fstream file;$/;" m class:File 63 | fileSize File.h /^ long fileSize;$/;" m class:File 64 | fileSize MyTask.h /^ long fileSize;$/;" m class:File 65 | getBlockNum File.cpp /^int File::getBlockNum()$/;" f class:File 66 | getFilestream File.cpp /^const fstream & File::getFilestream()$/;" f class:File 67 | getthreadid MyThread.cpp /^int MyThread::getthreadid()$/;" f class:MyThread 68 | idle_mutex_ MyThreadPool.h /^ std::mutex idle_mutex_;$/;" m class:MyThreadPool 69 | idle_thread_container_ IdleThreadContainer.h /^ std::vector idle_thread_container_;$/;" m class:IdleThreadContainer 70 | idle_thread_container_ MyThreadPool.h /^ IdleThreadContainer idle_thread_container_;$/;" m class:MyThreadPool 71 | isdetach_ MyThread.h /^ bool isdetach_;$/;" m class:MyThread 72 | issurvive_ MyThreadPool.h /^ bool issurvive_;$/;" m class:MyThreadPool 73 | main main.cpp /^int main()$/;" f 74 | mythreadpool_ MyThread.h /^ MyThreadPool *mythreadpool_; \/\/指向关联的线程池$/;" m class:MyThread 75 | number_of_thread_ MyThreadPool.h /^ int number_of_thread_;$/;" m class:MyThreadPool 76 | operator != MyThread.cpp /^bool operator!=(MyThread my1, MyThread my2)$/;" f 77 | operator == MyThread.cpp /^bool operator==(MyThread my1, MyThread my2)$/;" f 78 | pop IdleThreadContainer.cpp /^void IdleThreadContainer::pop()$/;" f class:IdleThreadContainer 79 | pop TaskContainer.cpp /^void TaskContainer::pop()$/;" f class:TaskContainer 80 | priority_ Task.h /^ int priority_;$/;" m class:Task 81 | push BusyThreadContainer.cpp /^void BusyThreadContainer::push(MyThread *m)$/;" f class:BusyThreadContainer 82 | push IdleThreadContainer.cpp /^void IdleThreadContainer::push(MyThread *m)$/;" f class:IdleThreadContainer 83 | push TaskContainer.cpp /^void TaskContainer::push(Task* t)$/;" f class:TaskContainer 84 | s_threadnumber MyThread.cpp /^int MyThread::s_threadnumber = 0;$/;" m class:MyThread file: 85 | s_threadnumber MyThread.h /^ static int s_threadnumber; $/;" m class:MyThread 86 | setisdetach MyThread.cpp /^void MyThread::setisdetach(bool detach)$/;" f class:MyThread 87 | size BusyThreadContainer.cpp /^std::list::size_type BusyThreadContainer::size()$/;" f class:BusyThreadContainer 88 | size IdleThreadContainer.cpp /^std::vector::size_type IdleThreadContainer::size()$/;" f class:IdleThreadContainer 89 | size TaskContainer.cpp /^std::priority_queue::size_type TaskContainer::size()$/;" f class:TaskContainer 90 | task_ MyThread.h /^ Task *task_; \/\/关联的任务$/;" m class:MyThread 91 | task_container_ MyThreadPool.h /^ TaskContainer task_container_;$/;" m class:MyThreadPool 92 | task_container_ TaskContainer.h /^ std::priority_queue task_container_;$/;" m class:TaskContainer 93 | task_mutex_ MyThreadPool.h /^ std::mutex task_mutex_;$/;" m class:MyThreadPool 94 | thread_ MyThread.h /^ std::thread thread_;$/;" m class:MyThread 95 | thread_this_ MyThreadPool.h /^ std::thread thread_this_; \/\/线程池运行线程$/;" m class:MyThreadPool 96 | threadid_ MyThread.h /^ int threadid_; \/\/线程id$/;" m class:MyThread 97 | top IdleThreadContainer.cpp /^MyThread* IdleThreadContainer::top()$/;" f class:IdleThreadContainer 98 | top TaskContainer.cpp /^Task* TaskContainer::top()$/;" f class:TaskContainer 99 | ~BusyThreadContainer BusyThreadContainer.cpp /^BusyThreadContainer::~BusyThreadContainer()$/;" f class:BusyThreadContainer 100 | ~File File.h /^ ~File()$/;" f class:File 101 | ~File MyTask.h /^ ~File()$/;" f class:File 102 | ~IdleThreadContainer IdleThreadContainer.cpp /^IdleThreadContainer::~IdleThreadContainer()$/;" f class:IdleThreadContainer 103 | ~MyTask MyTask.h /^ ~MyTask()$/;" f class:MyTask 104 | ~MyThreadPool MyThreadPool.cpp /^MyThreadPool::~MyThreadPool()$/;" f class:MyThreadPool 105 | ~TaskContainer TaskContainer.cpp /^TaskContainer::~TaskContainer()$/;" f class:TaskContainer 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # network-dash 2 | 模拟百度网盘实现的一个简单文件传输和下载的c/s模式的项目: 3 | 4 | 一、实现安全登录 5 | 二、实现大文件的快速上传和下载 6 | 三、实现大文件的秒传功能 7 | 四、实现文件的增量上传 8 | 五、实现文件时光机功能 9 | -------------------------------------------------------------------------------- /server: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/foshougua/network-dash/d32c0bcd60273df555bfecfb150f139ebf9f1f7e/server -------------------------------------------------------------------------------- /server.cpp: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: server.cpp 3 | > Author: 4 | > Mail: 5 | > Created Time: 2017年05月07日 星期日 10时08分05秒 6 | ************************************************************************/ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace std; 17 | 18 | int main() 19 | { 20 | void *pCtx = NULL; 21 | void *pSock = NULL; 22 | const char * pAddr = "tcp://*:7766"; 23 | 24 | if((pCtx = zmq_ctx_new()) == NULL) 25 | { 26 | return 0; 27 | } 28 | 29 | if((pSock = zmq_socket(pCtx, ZMQ_DEALER)) == NULL) 30 | { 31 | zmq_ctx_destroy(pCtx); 32 | return 0; 33 | } 34 | 35 | int iRvcTimeOut = 5000; 36 | 37 | if(zmq_setsockopt(pSock, ZMQ_RCVTIMEO, &iRvcTimeOut, sizeof(iRvcTimeOut)) < 0) 38 | { 39 | zmq_close(pSock); 40 | zmq_ctx_destroy(pCtx); 41 | return 0; 42 | } 43 | 44 | if(zmq_bind(pSock, pAddr) < 0) 45 | { 46 | zmq_close(pSock); 47 | zmq_ctx_destroy(pCtx); 48 | return 0; 49 | } 50 | 51 | 52 | 53 | 54 | std::cout<<"receive"<