#include "net.h"
#include "irc.h"
+#ifndef _WIN32
+#include <signal.h>
+static sig_atomic_t is_running = 1;
+static void on_sigint(int signum)
+{
+ (void)signum;
+ is_running = 0;
+}
+static void set_handler()
+{
+ struct sigaction sa;
+ sa.sa_handler = on_sigint;
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = SA_RESETHAND; // only run it once
+ if (sigaction(SIGINT, &sa, NULL) == -1)
+ perror("sigaction");
+}
+#else
+#define is_running 1
+#define set_handler()
+#endif
+
// Client linked list
struct client_data *clients[CLIENTS];
// FDSET List
#endif
int main() {
+ set_handler();
int opt = 1;
SOCKET serverSocketV4 = 0;
SOCKET serverSocketV6 = 0;
// Main loop
- while(1){
+ while(is_running){
FD_ZERO(&readfds);
// Add listening SOCKETS to FDSET
#ifdef SUPPORT_IPV4
// Wait until activity on sockets
if(select(highestFD+1,&readfds,NULL,NULL,NULL) == -1) {
+#ifndef _WIN32
+ if (errno == EINTR)
+ continue;
+#endif
net_perror("ERROR SELECT");
}