Skip to content

Commit

Permalink
simulator: clean shutdown of socket
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeZ committed Dec 19, 2024
1 parent 02c8a76 commit 0d8b5de
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion test/simulator/simulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <getopt.h>
#include <netdb.h>
#include <netinet/in.h>
#include <signal.h>
#include <sys/socket.h>

static const char* _simulator_version = "1.0.0";
Expand All @@ -41,6 +42,8 @@ static const char* _simulator_version = "1.0.0";
int data_len;
int commfd;

static int sockfd;

int get_usb_message_socket(uint8_t* input)
{
return read(commfd, input, USB_HID_REPORT_OUT_SIZE);
Expand All @@ -67,8 +70,15 @@ void simulate_firmware_execution(const uint8_t* input)
usb_processing_process(usb_processing_hww());
}

static void _int_handler(int _signum)
{
printf("\n\nGot Ctrl-C, exiting\n\n");
close(sockfd);
}

int main(int argc, char* argv[])
{
signal(SIGINT, _int_handler);
// Default port number
int portno = 15423;

Expand Down Expand Up @@ -124,7 +134,7 @@ int main(int argc, char* argv[])
idle_workflow_blocking();

// Establish socket connection with client
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("ERROR opening socket");
return 1;
Expand Down

0 comments on commit 0d8b5de

Please sign in to comment.