renamed tcp socket server
This commit is contained in:
parent
7ae8bc4bcc
commit
abdf3eeb23
4 changed files with 18 additions and 18 deletions
|
@ -29,7 +29,7 @@ add_executable(
|
||||||
bus.cpp
|
bus.cpp
|
||||||
comm.cpp
|
comm.cpp
|
||||||
comm_posix_tty.cpp
|
comm_posix_tty.cpp
|
||||||
comm_tcp_socket.cpp
|
comm_tcp_socket_server.cpp
|
||||||
console.cpp
|
console.cpp
|
||||||
console_ncurses.cpp
|
console_ncurses.cpp
|
||||||
console_posix.cpp
|
console_posix.cpp
|
||||||
|
@ -80,7 +80,7 @@ add_executable(
|
||||||
bus.cpp
|
bus.cpp
|
||||||
comm.cpp
|
comm.cpp
|
||||||
comm_posix_tty.cpp
|
comm_posix_tty.cpp
|
||||||
comm_tcp_socket.cpp
|
comm_tcp_socket_server.cpp
|
||||||
console.cpp
|
console.cpp
|
||||||
console_posix.cpp
|
console_posix.cpp
|
||||||
cpu.cpp
|
cpu.cpp
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "comm_tcp_socket.h"
|
#include "comm_tcp_socket_server.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
@ -68,12 +68,12 @@ static bool setup_telnet_session(const int fd)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
comm_tcp_socket::comm_tcp_socket(const int port) : port(port)
|
comm_tcp_socket_server::comm_tcp_socket_server(const int port) : port(port)
|
||||||
{
|
{
|
||||||
th = new std::thread(std::ref(*this));
|
th = new std::thread(std::ref(*this));
|
||||||
}
|
}
|
||||||
|
|
||||||
comm_tcp_socket::~comm_tcp_socket()
|
comm_tcp_socket_server::~comm_tcp_socket_server()
|
||||||
{
|
{
|
||||||
stop_flag = true;
|
stop_flag = true;
|
||||||
|
|
||||||
|
@ -83,14 +83,14 @@ comm_tcp_socket::~comm_tcp_socket()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool comm_tcp_socket::is_connected()
|
bool comm_tcp_socket_server::is_connected()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lck(cfd_lock);
|
std::unique_lock<std::mutex> lck(cfd_lock);
|
||||||
|
|
||||||
return cfd != INVALID_SOCKET;
|
return cfd != INVALID_SOCKET;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool comm_tcp_socket::has_data()
|
bool comm_tcp_socket_server::has_data()
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lck(cfd_lock);
|
std::unique_lock<std::mutex> lck(cfd_lock);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
|
@ -104,7 +104,7 @@ bool comm_tcp_socket::has_data()
|
||||||
return rc == 1;
|
return rc == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t comm_tcp_socket::get_byte()
|
uint8_t comm_tcp_socket_server::get_byte()
|
||||||
{
|
{
|
||||||
int use_fd = -1;
|
int use_fd = -1;
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ uint8_t comm_tcp_socket::get_byte()
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
void comm_tcp_socket::send_data(const uint8_t *const in, const size_t n)
|
void comm_tcp_socket_server::send_data(const uint8_t *const in, const size_t n)
|
||||||
{
|
{
|
||||||
const uint8_t *p = in;
|
const uint8_t *p = in;
|
||||||
size_t len = n;
|
size_t len = n;
|
||||||
|
@ -142,7 +142,7 @@ void comm_tcp_socket::send_data(const uint8_t *const in, const size_t n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void comm_tcp_socket::operator()()
|
void comm_tcp_socket_server::operator()()
|
||||||
{
|
{
|
||||||
set_thread_name("kek:COMMTCP");
|
set_thread_name("kek:COMMTCP");
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ void comm_tcp_socket::operator()()
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = INVALID_SOCKET;
|
fd = INVALID_SOCKET;
|
||||||
|
|
||||||
DOLOG(warning, true, "Cannot set reuseaddress for port %d (comm_tcp_socket)", port);
|
DOLOG(warning, true, "Cannot set reuseaddress for port %d (comm_tcp_socket_server)", port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ void comm_tcp_socket::operator()()
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = INVALID_SOCKET;
|
fd = INVALID_SOCKET;
|
||||||
|
|
||||||
DOLOG(warning, true, "Cannot bind to port %d (comm_tcp_socket)", port);
|
DOLOG(warning, true, "Cannot bind to port %d (comm_tcp_socket_server)", port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ void comm_tcp_socket::operator()()
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = INVALID_SOCKET;
|
fd = INVALID_SOCKET;
|
||||||
|
|
||||||
DOLOG(warning, true, "Cannot listen on port %d (comm_tcp_socket)", port);
|
DOLOG(warning, true, "Cannot listen on port %d (comm_tcp_socket_server)", port);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
class comm_tcp_socket: public comm
|
class comm_tcp_socket_server: public comm
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const int port { -1 };
|
const int port { -1 };
|
||||||
|
@ -27,8 +27,8 @@ private:
|
||||||
std::thread *th { nullptr };
|
std::thread *th { nullptr };
|
||||||
|
|
||||||
public:
|
public:
|
||||||
comm_tcp_socket(const int port);
|
comm_tcp_socket_server(const int port);
|
||||||
virtual ~comm_tcp_socket();
|
virtual ~comm_tcp_socket_server();
|
||||||
|
|
||||||
bool is_connected() override;
|
bool is_connected() override;
|
||||||
|
|
4
main.cpp
4
main.cpp
|
@ -13,7 +13,7 @@
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "comm.h"
|
#include "comm.h"
|
||||||
#include "comm_posix_tty.h"
|
#include "comm_posix_tty.h"
|
||||||
#include "comm_tcp_socket.h"
|
#include "comm_tcp_socket_server.h"
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
#include "console_ncurses.h"
|
#include "console_ncurses.h"
|
||||||
#endif
|
#endif
|
||||||
|
@ -616,7 +616,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
for(size_t i=comm_interfaces.size(); i<4; i++) {
|
for(size_t i=comm_interfaces.size(); i<4; i++) {
|
||||||
int port = 1100 + i;
|
int port = 1100 + i;
|
||||||
comm_interfaces.push_back(new comm_tcp_socket(port));
|
comm_interfaces.push_back(new comm_tcp_socket_server(port));
|
||||||
DOLOG(info, false, "Configuring DC11 device for TCP socket on port %d", port);
|
DOLOG(info, false, "Configuring DC11 device for TCP socket on port %d", port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue