]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/async/PosixStack.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / msg / async / PosixStack.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2016 XSKY <haomai@xsky.com>
7 *
8 * Author: Haomai Wang <haomaiwang@gmail.com>
9 *
10 * This is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License version 2.1, as published by the Free Software
13 * Foundation. See file COPYING.
14 *
15 */
16
17 #ifndef CEPH_MSG_ASYNC_POSIXSTACK_H
18 #define CEPH_MSG_ASYNC_POSIXSTACK_H
19
20 #include <thread>
21
22 #include "msg/msg_types.h"
23 #include "msg/async/net_handler.h"
24
25 #include "Stack.h"
26
27 class PosixWorker : public Worker {
28 ceph::NetHandler net;
29 void initialize() override;
30 public:
31 PosixWorker(CephContext *c, unsigned i)
32 : Worker(c, i), net(c) {}
33 int listen(entity_addr_t &sa,
34 unsigned addr_slot,
35 const SocketOptions &opt,
36 ServerSocket *socks) override;
37 int connect(const entity_addr_t &addr, const SocketOptions &opts, ConnectedSocket *socket) override;
38 };
39
40 class PosixNetworkStack : public NetworkStack {
41 std::vector<std::thread> threads;
42
43 virtual Worker* create_worker(CephContext *c, unsigned worker_id) override {
44 return new PosixWorker(c, worker_id);
45 }
46
47 public:
48 explicit PosixNetworkStack(CephContext *c);
49
50 void spawn_worker(unsigned i, std::function<void ()> &&func) override {
51 threads.resize(i+1);
52 threads[i] = std::thread(func);
53 }
54 void join_worker(unsigned i) override {
55 ceph_assert(threads.size() > i && threads[i].joinable());
56 threads[i].join();
57 }
58 };
59
60 #endif //CEPH_MSG_ASYNC_POSIXSTACK_H