test-socket: add basic timer functions
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 15 Oct 2010 16:29:41 +0000 (19:29 +0300)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Fri, 15 Oct 2010 16:29:41 +0000 (19:29 +0300)
Utils/test-socket-signal/client.c

index da1b491..9efc4f2 100644 (file)
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/socket.h>
+#include <signal.h>
 
 #include "sock_util.h"
 
 #define DEFAULT_SERVER_LISTEN_PORT     43210
 #define DEFAULT_SERVER_HOST            "localhost"
 
-#define DATA_SIZE              120
+#define DATA_SIZE                      120
+#define PACKET_INDEX_SIZE              8
 
+static char data[DATA_SIZE+PACKET_INDEX_SIZE];
 
-static char data[DATA_SIZE];
+/* connection socket */
+static int connectfd;
 
 static void init_buffer(void)
 {
@@ -42,9 +46,21 @@ static int send_buffer(int sockfd)
        return send(sockfd, data, DATA_SIZE, 0);
 }
 
+static void timer_handler(int sig, siginfo_t *si, void *uc)
+{
+       if (send_buffer(connectfd) < 0) {
+               perror("send_buffer");
+               exit(EXIT_FAILURE);
+       }
+}
+
+static void schedule_timer(void)
+{
+}
+
 int main(void)
 {
-       int connectfd;
+       sigset_t mask;
 
        connectfd = tcp_connect_to_server(DEFAULT_SERVER_HOST,
                        DEFAULT_SERVER_LISTEN_PORT);
@@ -53,10 +69,11 @@ int main(void)
        }
 
        init_buffer();
-       print_buffer();
-       if (send_buffer(connectfd) < 0) {
-               perror("send_buffer");
-               exit(EXIT_FAILURE);
+       schedule_timer();
+
+       sigemptyset(&mask);
+       while (1) {
+               sigsuspend(&mask);
        }
 
        printf("\n--- data sent!\n");