File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change 32
32
#include <getopt.h>
33
33
#include <netdb.h>
34
34
#include <netinet/in.h>
35
+ #include <signal.h>
35
36
#include <sys/socket.h>
36
37
37
38
static const char * _simulator_version = "1.0.0" ;
@@ -41,6 +42,8 @@ static const char* _simulator_version = "1.0.0";
41
42
int data_len ;
42
43
int commfd ;
43
44
45
+ static int sockfd ;
46
+
44
47
int get_usb_message_socket (uint8_t * input )
45
48
{
46
49
return read (commfd , input , USB_HID_REPORT_OUT_SIZE );
@@ -67,8 +70,15 @@ void simulate_firmware_execution(const uint8_t* input)
67
70
usb_processing_process (usb_processing_hww ());
68
71
}
69
72
73
+ static void _int_handler (int _signum )
74
+ {
75
+ printf ("\n\nGot Ctrl-C, exiting\n\n" );
76
+ close (sockfd );
77
+ }
78
+
70
79
int main (int argc , char * argv [])
71
80
{
81
+ signal (SIGINT , _int_handler );
72
82
// Default port number
73
83
int portno = 15423 ;
74
84
@@ -124,7 +134,7 @@ int main(int argc, char* argv[])
124
134
idle_workflow_blocking ();
125
135
126
136
// Establish socket connection with client
127
- int sockfd = socket (AF_INET , SOCK_STREAM , 0 );
137
+ sockfd = socket (AF_INET , SOCK_STREAM , 0 );
128
138
if (sockfd < 0 ) {
129
139
perror ("ERROR opening socket" );
130
140
return 1 ;
You can’t perform that action at this time.
0 commit comments