]> git.proxmox.com Git - ceph.git/blame - ceph/src/msg/async/PosixStack.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / msg / async / PosixStack.h
CommitLineData
7c673cae
FG
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
27class PosixWorker : public Worker {
f67539c2 28 ceph::NetHandler net;
7c673cae
FG
29 void initialize() override;
30 public:
31 PosixWorker(CephContext *c, unsigned i)
32 : Worker(c, i), net(c) {}
11fdf7f2
TL
33 int listen(entity_addr_t &sa,
34 unsigned addr_slot,
35 const SocketOptions &opt,
36 ServerSocket *socks) override;
7c673cae
FG
37 int connect(const entity_addr_t &addr, const SocketOptions &opts, ConnectedSocket *socket) override;
38};
39
40class PosixNetworkStack : public NetworkStack {
f67539c2
TL
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 }
7c673cae
FG
46
47 public:
f67539c2 48 explicit PosixNetworkStack(CephContext *c);
7c673cae 49
20effc67
TL
50 void spawn_worker(std::function<void ()> &&func) override {
51 threads.emplace_back(std::move(func));
7c673cae
FG
52 }
53 void join_worker(unsigned i) override {
11fdf7f2 54 ceph_assert(threads.size() > i && threads[i].joinable());
7c673cae
FG
55 threads[i].join();
56 }
57};
58
59#endif //CEPH_MSG_ASYNC_POSIXSTACK_H