File: group_server.cpp

package info (click to toggle)
actor-framework 0.17.6-2.1
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 8,948 kB
  • sloc: cpp: 77,682; sh: 674; python: 309; makefile: 13
file content (44 lines) | stat: -rw-r--r-- 1,001 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// This example program represents a minimal IRC-like group communication
// server.
//
// Setup for a minimal chat between "alice" and "bob":
// - ./build/bin/group_server -p 4242
// - ./build/bin/group_chat -g remote:chatroom@localhost:4242 -n alice
// - ./build/bin/group_chat -g remote:chatroom@localhost:4242 -n bob

#include <string>
#include <cstdlib>
#include <iostream>

#include "caf/all.hpp"
#include "caf/io/all.hpp"

using namespace std;
using namespace caf;

namespace {

class config : public actor_system_config {
public:
  uint16_t port = 0;

  config() {
    opt_group{custom_options_, "global"}
    .add(port, "port,p", "set port");
  }
};

void caf_main(actor_system& system, const config& cfg) {
  system.middleman().publish_local_groups(cfg.port);
  cout << "type 'quit' to shutdown the server" << endl;
  string line;
  while (getline(cin, line))
    if (line == "quit")
      return;
    else
      cerr << "illegal command" << endl;
}

} // namespace

CAF_MAIN(io::middleman)