test-socket-signal: add sender debug messages
authorRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Thu, 11 Nov 2010 15:46:13 +0000 (17:46 +0200)
committerRazvan Deaconescu <razvan.deaconescu@cs.pub.ro>
Thu, 11 Nov 2010 15:46:13 +0000 (17:46 +0200)
Utils/test-socket-signal/sender.c

index 1b265b9..09efe11 100644 (file)
@@ -94,7 +94,17 @@ static void fill_send_buffer(void)
 
 static ssize_t send_buffer(int sockfd)
 {
-       return send(sockfd, snd_buf, PACKET_SIZE, 0);
+       ssize_t n;
+
+       printf("before send\n");
+       n = send(sockfd, snd_buf, PACKET_SIZE, 0);
+       printf("after send\n");
+       if (n < 0)
+               perror("send");
+
+       printf ("n = %ld, send\n", n);
+
+       return n;
 }
 
 static ssize_t receive_buffer(int sockfd)
@@ -203,18 +213,34 @@ int main(int argc, char **argv)
 {
        parse_args(argc, argv);
 
+       init();
+
+try_connect:
+       sleep(1);
+
+       printf("ready to connect\n");
+
        connectfd = tcp_connect_to_server(cmd_args.server_host,
                        cmd_args.server_port);
-       DIE(connectfd < 0, "tcp_connect_to_server");
+       if (connectfd < 0) {
+               perror("tcp_connect_to_server");
+               goto try_connect;
+       }
 
-       init();
+       printf("connected\n");
 
        while (1) {
                ssize_t nbytes;
 
                fill_send_buffer();
                nbytes = send_buffer(connectfd);
+               printf("nbytes: %lu\n", nbytes);
                DIE(nbytes < 0, "send_buffer");
+               if (nbytes == 0) {
+                       printf("Connection closed\n");
+                       close(connectfd);
+                       goto try_connect;
+               }
                delay_packet();
        }