mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
cleaning up socket
This commit is contained in:
@ -1,18 +1,20 @@
|
||||
#include "ClientSocket.h"
|
||||
#include "sls_detector_exceptions.h"
|
||||
#include "clara.hpp"
|
||||
#include "tests/testenum.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "container_utils.h"
|
||||
#include <iostream>
|
||||
|
||||
bool help = false;
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int main(int argc, char **argv) {
|
||||
std::cout << "Test client\n";
|
||||
std::string hostname{"localhost"};
|
||||
int port = 2345;
|
||||
auto cli =
|
||||
clara::Opt(hostname, "hostname")["-hn"]["--hostname"]("Hostname") |
|
||||
clara::Help(help) |
|
||||
clara::Opt(hostname, "hostname")["-n"]["--hostname"]("Hostname") |
|
||||
clara::Opt(port, "port")["-p"]["--port"]("Port to send to");
|
||||
|
||||
auto result = cli.parse(clara::Args(argc, argv));
|
||||
@ -21,25 +23,58 @@ int main(int argc, char** argv) {
|
||||
<< std::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (help) {
|
||||
std::cout << cli << std::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::cout << "Sending to: " << hostname << ":" << port << "\n";
|
||||
|
||||
|
||||
|
||||
auto data = sls::make_unique<char[]>(DATA_SIZE);
|
||||
|
||||
for (int64_t i = 0; i!=50; ++i){
|
||||
// Many connections sending small amounts
|
||||
for (int i = 0; i != 100; ++i) {
|
||||
std::cout << "Sending: " << i << "\n";
|
||||
auto socket = sls::ClientSocket("test", hostname, port);
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_int) << " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_int)
|
||||
<< " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(i) << " bytes\n";
|
||||
}
|
||||
|
||||
for (int64_t i = 0; i!=5; ++i){
|
||||
// Sending larger blocks
|
||||
for (int i = 0; i != 5; ++i) {
|
||||
std::cout << "Sending data\n";
|
||||
auto socket = sls::ClientSocket("test", hostname, port);
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_data) << " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE) << " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_data)
|
||||
<< " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE)
|
||||
<< " bytes\n";
|
||||
}
|
||||
|
||||
|
||||
// Send too little data
|
||||
{
|
||||
auto socket = sls::ClientSocket("test", hostname, port);
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_data)
|
||||
<< " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE / 2)
|
||||
<< " bytes\n";
|
||||
}
|
||||
// Send too much data
|
||||
try{
|
||||
auto socket = sls::ClientSocket("test", hostname, port);
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_half_data)
|
||||
<< " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(data.get(), DATA_SIZE)
|
||||
<< " bytes\n";
|
||||
}catch(const sls::SocketError& e){
|
||||
|
||||
}
|
||||
// Some ints again
|
||||
for (int i = 0; i != 10; ++i) {
|
||||
std::cout << "Sending: " << i << "\n";
|
||||
auto socket = sls::ClientSocket("test", hostname, port);
|
||||
std::cout << "Sent: " << socket.sendData(func_id::read_int)
|
||||
<< " bytes\n";
|
||||
std::cout << "Sent: " << socket.sendData(i) << " bytes\n";
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user