receiver socket

This commit is contained in:
Erik Frojdh
2019-05-15 17:51:48 +02:00
parent 40c2d9f760
commit e252b8e0e9
9 changed files with 440 additions and 342 deletions

View File

@ -0,0 +1,28 @@
#pragma once
#include "DataSocket.h"
namespace sls {
class ServerInterface2;
}
#include "ServerSocket.h"
#include "sls_detector_defs.h"
namespace sls {
class ServerInterface2 : public DataSocket {
using defs = slsDetectorDefs;
public:
ServerInterface2(int socketId) : DataSocket(socketId){}
int sendResult(bool update, int ret, void *retval, int retvalSize,
char *mess = nullptr);
int receiveArg(int &ret, char *mess, void *arg, int sizeofArg);
private:
};
} // namespace sls

View File

@ -1,7 +1,8 @@
#pragma once
#include "DataSocket.h"
#include "ServerInterface2.h"
#include "network_utils.h"
#include <cstdint>
#include <netdb.h>
#include <string>
@ -13,14 +14,18 @@ namespace sls {
class ServerSocket : public DataSocket {
public:
ServerSocket(int port);
DataSocket accept();
const std::string &getLastClient();
ServerInterface2 accept();
constexpr IpAddr getLastClient() noexcept { return lastClient; }
constexpr IpAddr getThisClient() noexcept { return thisClient; }
constexpr IpAddr getLockedBy() noexcept { return lockedBy; }
void setLockedBy(IpAddr addr){ lockedBy = addr; }
int getPort() const;
void SendResult(int &ret, void *retval, int retvalSize, char* mess);
void SendResult(int &ret, void *retval, int retvalSize, char *mess);
private:
std::string lastClient_ = std::string(INET_ADDRSTRLEN, '\0');
std::string thisClient_ = std::string(INET_ADDRSTRLEN, '\0');
IpAddr thisClient;
IpAddr lastClient;
IpAddr lockedBy;
int serverPort;
// char lastClient_[INET_ADDRSTRLEN]{};
};

View File

@ -11,6 +11,7 @@ class IpAddr {
uint32_t addr_{0};
public:
constexpr IpAddr() noexcept{}
constexpr IpAddr(uint32_t address) noexcept : addr_{address} {}
IpAddr(const std::string &address);
IpAddr(const char *address);