Bredbandskollen CLI  1.2
Asynchronous network task engine
serversocket.h
1 // Copyright (c) 2018 IIS (The Internet Foundation in Sweden)
2 // Written by Göran Andersson <initgoran@gmail.com>
3 
4 #pragma once
5 
6 #include "socket.h"
7 #include "task.h"
8 
9 class SocketConnection;
10 
15 class ServerSocket : public Socket {
16 public:
24  ServerSocket(const std::string &label, Task *task,
25  uint16_t port, const std::string &ip = "127.0.0.1");
26 
29  ServerSocket(int fd, const std::string &label, Task *owner) :
30  Socket(label, owner, fd) {
31  }
32 
33  virtual ~ServerSocket() override;
34 
36  std::string cacheLabel() override {
37  return std::string();
38  }
39 
41  void stopListening() {
42  closeMe();
43  }
44 
46  virtual SocketConnection *incoming();
47 
48 #ifdef USE_GNUTLS
49  void tlsSetKey(unsigned int i) {
50  tlsKeyIndex = i;
51  }
52  unsigned int tlsKey() const {
53  return tlsKeyIndex;
54  }
55 private:
56  unsigned int tlsKeyIndex = 0;
57 #endif
58 };
std::string label() const
Return the object's log label.
Definition: logger.h:251
Listen on a single socket for incoming connections.
Definition: serversocket.h:15
std::string cacheLabel() override
Server sockets shall not be cached.
Definition: serversocket.h:36
ServerSocket(int fd, const std::string &label, Task *owner)
Create a new server to listen on an existing file descriptor.
Definition: serversocket.h:29
virtual SocketConnection * incoming()
Return Connection object if new client available, else return nullptr.
Definition: serversocket.cpp:27
void stopListening()
Schedule listen socket for removal.
Definition: serversocket.h:41
ServerSocket(const std::string &label, Task *task, uint16_t port, const std::string &ip="127.0.0.1")
Create a new server socket.
Definition: serversocket.cpp:19
This class implements low-level socket connection operations. Inherit from it to implement protocols ...
Definition: socketconnection.h:47
This is a slave to the Engine class. You can't use it directly, only through its subclasses,...
Definition: socket.h:18
Task * owner() const
Return task owning the socket.
Definition: socket.h:27
uint16_t port() const
Return port number to which the socket is supposed to connect.
Definition: socket.h:37
void closeMe()
Tell the network engine that the connection should be closed.
Definition: socket.h:178
The purpose of a task is to manage socket connections, and/or to execute timers.
Definition: task.h:39