server.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017, 2018 Simon Rasmussen (refactor)
3  *
4  * Copyright 2015, 2016 Thomas Timm Andersen (original version)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #pragma once
20 #include <netdb.h>
21 #include <sys/socket.h>
22 #include <sys/types.h>
23 #include <atomic>
24 #include <cstdlib>
25 #include <mutex>
26 #include <string>
28 
29 #define MAX_SERVER_BUF_LEN 50
30 
31 class URServer : private TCPSocket
32 {
33 private:
34  int port_;
36 
37 protected:
38  virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len);
39 
40 public:
41  URServer(int port);
42  ~URServer();
43  std::string getIP();
44  bool bind();
45  bool accept();
46  void disconnectClient();
47  bool readLine(char *buffer, size_t buf_len);
48  bool write(const uint8_t *buf, size_t buf_len, size_t &written);
49 };
bool accept()
Definition: server.cpp:75
virtual bool open(int socket_fd, struct sockaddr *address, size_t address_len)
Definition: server.cpp:54
bool bind()
Definition: server.cpp:61
bool readLine(char *buffer, size_t buf_len)
Definition: server.cpp:110
std::string getIP()
Definition: server.cpp:37
int port_
Definition: server.h:34
bool write(const uint8_t *buf, size_t buf_len, size_t &written)
Definition: server.cpp:105
TCPSocket client_
Definition: server.h:35
void disconnectClient()
Definition: server.cpp:97
~URServer()
Definition: server.cpp:32
URServer(int port)
Definition: server.cpp:28


ur_modern_driver
Author(s): Thomas Timm Andersen, Simon Rasmussen
autogenerated on Fri Jun 26 2020 03:37:00