]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2016 XSKY <haomai@xsky.com>
8 * Author: Haomai Wang <haomaiwang@gmail.com>
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.
17 #ifndef CEPH_MSG_ASYNC_POSIXSTACK_H
18 #define CEPH_MSG_ASYNC_POSIXSTACK_H
22 #include "msg/msg_types.h"
23 #include "msg/async/net_handler.h"
27 class PosixWorker
: public Worker
{
29 void initialize() override
;
31 PosixWorker(CephContext
*c
, unsigned i
)
32 : Worker(c
, i
), net(c
) {}
33 int listen(entity_addr_t
&sa
, const SocketOptions
&opt
,
34 ServerSocket
*socks
) override
;
35 int connect(const entity_addr_t
&addr
, const SocketOptions
&opts
, ConnectedSocket
*socket
) override
;
38 class PosixNetworkStack
: public NetworkStack
{
40 vector
<std::thread
> threads
;
43 explicit PosixNetworkStack(CephContext
*c
, const string
&t
);
45 int get_cpuid(int id
) const {
48 return coreids
[id
% coreids
.size()];
50 void spawn_worker(unsigned i
, std::function
<void ()> &&func
) override
{
52 threads
[i
] = std::thread(func
);
54 void join_worker(unsigned i
) override
{
55 assert(threads
.size() > i
&& threads
[i
].joinable());
60 #endif //CEPH_MSG_ASYNC_POSIXSTACK_H