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)
{
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();
}