]> git.proxmox.com Git - ceph.git/blob - ceph/src/msg/async/PosixStack.h
update sources to ceph Nautilus 14.2.1
[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 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 vector<std::thread> threads;
42
43 public:
44 explicit PosixNetworkStack(CephContext *c, const string &t);
45
46 void spawn_worker(unsigned i, std::function<void ()> &&func) override {
47 threads.resize(i+1);
48 threads[i] = std::thread(func);
49 }
50 void join_worker(unsigned i) override {
51 ceph_assert(threads.size() > i && threads[i].joinable());
52 threads[i].join();
53 }
54 };
55
56 #endif //CEPH_MSG_ASYNC_POSIXSTACK_H