mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-07 23:32:30 +02:00
decode error code
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace sls {
|
||||
|
||||
@@ -24,6 +25,18 @@ std::vector<char> echo_server(uint16_t port, size_t bytes_to_send,
|
||||
std::vector<char> buffer(100, '\0');
|
||||
s.Receive(buffer.data(), buffer.size());
|
||||
|
||||
if (port==1960){
|
||||
struct linger ling = {
|
||||
.l_onoff = 1,
|
||||
.l_linger = 0
|
||||
};
|
||||
|
||||
auto fd = s.getSocketId();
|
||||
setsockopt(fd, SOL_SOCKET, SO_LINGER, &ling, sizeof ling);
|
||||
close(fd);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
if (bytes_to_send > 0) {
|
||||
std::vector<char> to_send(bytes_to_send, '\0');
|
||||
to_send[0] = 'O';
|
||||
@@ -126,4 +139,26 @@ TEST_CASE("Receiving with a socket error throws and reports the error",
|
||||
CHECK_THAT(error_message, Catch::Matchers::Contains("read error:"));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("Socket crash?", "[support]") {
|
||||
std::vector<char> received_message(100, '\0');
|
||||
std::vector<char> sent_message(100, '\0');
|
||||
const char m[]{"some message"};
|
||||
std::copy(std::begin(m), std::end(m), sent_message.data());
|
||||
|
||||
auto s = std::async(std::launch::async, echo_server, 1960, 100,
|
||||
std::chrono::milliseconds(0));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
auto client = DetectorSocket("localhost", 1960);
|
||||
client.Send(sent_message.data(), sent_message.size());
|
||||
|
||||
|
||||
REQUIRE_THROWS(client.Receive(received_message.data(), received_message.size()));
|
||||
// client.close();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // namespace sls
|
||||
|
||||
Reference in New Issue
Block a user