mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-23 10:07:59 +02:00
starting to add new Socket interface
This commit is contained in:
17
slsSupportLib/include/ClientSocket.h
Normal file
17
slsSupportLib/include/ClientSocket.h
Normal file
@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
#include "DataSocket.h"
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <netdb.h>
|
||||
#include <string>
|
||||
|
||||
namespace sls{
|
||||
|
||||
class ClientSocket: public DataSocket{
|
||||
public:
|
||||
ClientSocket(const std::string& hostname, uint16_t port_number);
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
}; //namespace sls
|
23
slsSupportLib/include/DataSocket.h
Normal file
23
slsSupportLib/include/DataSocket.h
Normal file
@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
namespace sls {
|
||||
|
||||
class DataSocket {
|
||||
public:
|
||||
DataSocket(int socketId);
|
||||
|
||||
int getSocketId() const{
|
||||
return socketId_;
|
||||
}
|
||||
size_t sendData(char *buffer, size_t size);
|
||||
size_t receiveData(char * buffer, size_t size);
|
||||
|
||||
void close();
|
||||
|
||||
private:
|
||||
int socketId_ = -1;
|
||||
};
|
||||
|
||||
}; // namespace sls
|
25
slsSupportLib/include/ServerSocket.h
Normal file
25
slsSupportLib/include/ServerSocket.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "DataSocket.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <netdb.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
namespace sls {
|
||||
|
||||
class ServerSocket : public DataSocket {
|
||||
public:
|
||||
ServerSocket(int port);
|
||||
DataSocket accept();
|
||||
const std::string &getLastClient() { return lastClient_; }
|
||||
|
||||
private:
|
||||
std::string lastClient_ = std::string(INET_ADDRSTRLEN, '\0');
|
||||
std::string thisClient_ = std::string(INET_ADDRSTRLEN, '\0');
|
||||
// char lastClient_[INET_ADDRSTRLEN]{};
|
||||
};
|
||||
|
||||
}; //namespace sls
|
Reference in New Issue
Block a user