mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-22 09:37:59 +02:00
receiver socket
This commit is contained in:
32
slsSupportLib/src/ServerInterface2.cpp
Normal file
32
slsSupportLib/src/ServerInterface2.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
#include "ServerInterface2.h"
|
||||
|
||||
namespace sls {
|
||||
|
||||
int ServerInterface2::sendResult(bool update, int ret, void *retval,
|
||||
int retvalSize, char *mess) {
|
||||
|
||||
// if (update && ret == defs::OK && server_->DifferentClients()) {
|
||||
// ret = defs::FORCE_UPDATE;
|
||||
// }
|
||||
sendData(&ret, sizeof(ret));
|
||||
if (ret == defs::FAIL) {
|
||||
// send error message
|
||||
if (mess)
|
||||
sendData(mess, MAX_STR_LENGTH);
|
||||
// debugging feature. should not happen.
|
||||
else
|
||||
FILE_LOG(logERROR) << "No error message provided for this "
|
||||
"failure. Will mess up TCP\n";
|
||||
}
|
||||
sendData(retval, retvalSize);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ServerInterface2::receiveArg(int &ret, char *mess, void *arg,
|
||||
int sizeofArg) {
|
||||
if (sizeofArg && receiveData(arg, sizeofArg) < 0)
|
||||
return defs::FAIL;
|
||||
return defs::OK;
|
||||
}
|
||||
|
||||
} // namespace sls
|
@ -1,4 +1,6 @@
|
||||
#include "ServerInterface2.h"
|
||||
#include "ServerSocket.h"
|
||||
|
||||
#include "DataSocket.h"
|
||||
#include "logger.h"
|
||||
#include "sls_detector_defs.h"
|
||||
@ -35,7 +37,8 @@ ServerSocket::ServerSocket(int port)
|
||||
}
|
||||
}
|
||||
|
||||
DataSocket ServerSocket::accept() {
|
||||
ServerInterface2 ServerSocket::accept() {
|
||||
lastClient = thisClient; //update from previous connection
|
||||
struct sockaddr_in clientAddr;
|
||||
socklen_t addr_size = sizeof clientAddr;
|
||||
int newSocket =
|
||||
@ -43,17 +46,15 @@ DataSocket ServerSocket::accept() {
|
||||
if (newSocket == -1) {
|
||||
throw sls::SocketError("Server ERROR: socket accept failed\n");
|
||||
}
|
||||
inet_ntop(AF_INET, &(clientAddr.sin_addr), &thisClient_.front(),
|
||||
INET_ADDRSTRLEN);
|
||||
std::cout << "lastClient: " << lastClient_ << " thisClient: " << thisClient_
|
||||
char tc[INET_ADDRSTRLEN]{};
|
||||
inet_ntop(AF_INET, &(clientAddr.sin_addr), tc, INET_ADDRSTRLEN);
|
||||
thisClient = tc;
|
||||
std::cout << "lastClient: " << lastClient << " thisClient: " << thisClient
|
||||
<< '\n';
|
||||
// Here goes any check for locks etc
|
||||
lastClient_ = thisClient_;
|
||||
|
||||
return DataSocket(newSocket);
|
||||
return ServerInterface2(newSocket);
|
||||
}
|
||||
|
||||
const std::string &ServerSocket::getLastClient() { return lastClient_; }
|
||||
|
||||
int ServerSocket::getPort() const { return serverPort; }
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
namespace sls {
|
||||
|
||||
|
||||
IpAddr::IpAddr(const std::string &address) {
|
||||
inet_pton(AF_INET, address.c_str(), &addr_);
|
||||
}
|
||||
|
Reference in New Issue
Block a user