split into src and lib and socket changes
* libanthracite files are now all in lib/ * anthracite-bin + anthracite-api-bin files are now all in src/ * socket split into header and source properly
This commit is contained in:
parent
fba87f3fbb
commit
71be773d49
24 changed files with 49 additions and 121 deletions
34
lib/socket/socket.hpp
Normal file
34
lib/socket/socket.hpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <malloc.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace anthracite::socket {
|
||||
|
||||
|
||||
class anthracite_socket {
|
||||
static const int MAX_QUEUE_LENGTH = 100;
|
||||
private:
|
||||
int server_socket;
|
||||
int client_socket {};
|
||||
std::string client_ip;
|
||||
struct sockaddr_in client_addr {};
|
||||
socklen_t client_addr_len {};
|
||||
static constexpr struct timeval timeout_tv {
|
||||
.tv_sec = 5, .tv_usec = 0
|
||||
};
|
||||
|
||||
public:
|
||||
anthracite_socket(int port, int max_queue = MAX_QUEUE_LENGTH);
|
||||
|
||||
void wait_for_conn();
|
||||
const std::string& get_client_ip();
|
||||
void close_conn();
|
||||
void send_message(std::string& msg);
|
||||
std::string recv_message(int buffer_size);
|
||||
};
|
||||
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue