...
 
Commits (5)
#pragma once
#include "Common.hpp"
#include "Socket.hpp"
#include <thread>
#include <mutex>
#include <condition_variable>
#include <cstddef>
#include <functional>
#include <mutex>
#include <thread>
#include "jbus/Common.hpp"
#include "jbus/Socket.hpp"
namespace jbus {
......
#pragma once
#include "Common.hpp"
#include "Socket.hpp"
#include <thread>
#include <queue>
#include <cstdint>
#include <memory>
#include <mutex>
#include <queue>
#include <thread>
#include "jbus/Socket.hpp"
namespace jbus {
class Endpoint;
/** Server interface for accepting incoming connections from GBA emulator instances. */
class Listener {
......@@ -33,6 +36,7 @@ public:
* @return Endpoint instance, ready to issue commands. */
std::unique_ptr<Endpoint> accept();
Listener();
~Listener();
};
......
#pragma once
#include <sys/types.h>
#include <fcntl.h>
#include <cstddef>
#include <cstdint>
#include <string>
#include <memory.h>
#ifdef _WIN32
#include <BaseTsd.h>
typedef UINT_PTR SOCKET;
using SOCKET = UINT_PTR;
#endif
#include "Common.hpp"
struct sockaddr_in;
namespace jbus::net {
......
#include "jbus/Endpoint.hpp"
#include <cstring>
#define LOG_TRANSFER 0
#if LOG_TRANSFER
#include <cstdio>
#endif
namespace jbus {
#define ROUND_UP_8(val) (((val) + 7) & ~7)
......
#include "jbus/Listener.hpp"
#include "jbus/Common.hpp"
#include "jbus/Endpoint.hpp"
#define LOG_LISTENER 0
#if LOG_LISTENER
#include <cstdio>
#endif
namespace jbus {
void Listener::listenerProc() {
......@@ -94,6 +100,8 @@ std::unique_ptr<Endpoint> Listener::accept() {
return {};
}
Listener::Listener() = default;
Listener::~Listener() { stop(); }
} // namespace jbus
#include "jbus/Socket.hpp"
#include <cstdio>
#include <cstring>
#ifndef _WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <cerrno>
#include <arpa/inet.h>
#include <fcntl.h>
#include <netdb.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <cerrno>
#else
#include <WinSock2.h>
#include <Ws2tcpip.h>
......@@ -42,11 +48,10 @@ void IPAddress::resolve(const std::string& address) noexcept {
m_valid = true;
} else {
/* Not a valid address, try to convert it as a host name */
addrinfo hints;
memset(&hints, 0, sizeof(hints));
addrinfo hints = {};
hints.ai_family = AF_INET;
addrinfo* result = NULL;
if (getaddrinfo(address.c_str(), NULL, &hints, &result) == 0) {
addrinfo* result = nullptr;
if (getaddrinfo(address.c_str(), nullptr, &hints, &result) == 0) {
if (result) {
addr = reinterpret_cast<sockaddr_in*>(result->ai_addr)->sin_addr;
freeaddrinfo(result);
......@@ -61,8 +66,7 @@ void IPAddress::resolve(const std::string& address) noexcept {
uint32_t IPAddress::toInteger() const noexcept { return ntohl(m_address); }
static sockaddr_in createAddress(uint32_t address, unsigned short port) {
sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
sockaddr_in addr = {};
addr.sin_addr.s_addr = htonl(address);
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
......@@ -102,7 +106,7 @@ void Socket::setRemoteSocket(int remSocket) noexcept {
}
#ifdef _WIN32
Socket::EResult Socket::LastWSAError() {
Socket::EResult Socket::LastWSAError() noexcept {
switch (WSAGetLastError()) {
case WSAEWOULDBLOCK:
case WSAEALREADY:
......