HP Rp7410 BSD Sockets Interface Programmer's Guide - Page 143
msec = 1000*floatsecs
View all HP Rp7410 manuals
Add to My Manuals
Save this manual to your list of manuals |
Page 143 highlights
Using UNIX Domain Stream Sockets Example Using UNIX Domain Stream Sockets */ send_data(ns, &bullet, sizeof(struct bullet)); cc = 0; if (counter_pid) kill(counter_pid, SIGUSR1); if (gettimeofday(&tp1, &tzp) == -1) { perror("catch time of day failed"); exit(0); } /* * Receive data from the client */ total = 0; i = bytes; while (i > 0) { cc = recvsize < i ? recvsize : i; recv_data(ns, buffer, cc); total += cc; i -= cc; } /* * Calculate throughput */ if (gettimeofday(&tp2, &tzp) == -1) { perror("catch time of day failed"); exit(0); } if (counter_pid) kill(counter_pid, SIGUSR2); secs = tp2.tv_sec - tp1.tv_sec; usec = tp2.tv_usec - tp1.tv_usec; if (usec < 0) { secs ; usec += 1000000; } msec = 1000*(float)secs; msec += (float)usec/1000; bullet.throughput = bytes/msec; /* * Send back the bullet with throughput info, then close the * server socket */ if ((cc = send(ns, &bullet, sizeof(struct bullet), 0)) == -1) { perror("catch - send end bullet failed"); exit(0); } close(ns); } timeout() { printf( "alarm went off -- stopping the catch process\n"); fprintf(stderr, "stopping the catch process\n"); unlink(SOCKNAME); close(s); exit(6); } /* * Sample Program : AF_UNIX stream sockets, client process * Chapter 6 143