#include #include #include #include #include #include int sendall(int s, const char *buf, int len); const char* rpc_data = "\003"; int rpc_len; int main() { int sock; struct sockaddr_in dest_addr; rpc_len = strlen(rpc_data); sock = socket(PF_INET, SOCK_STREAM, 0); if (sock < 0) { perror("socket"); return 1; } dest_addr.sin_family = AF_INET; dest_addr.sin_port = htons(31416); dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); memset(dest_addr.sin_zero, 0, sizeof dest_addr.sin_zero); printf("connecting\n"); if (connect(sock, (struct sockaddr *) &dest_addr, sizeof dest_addr) < 0) { perror("connect"); return 1; } printf("connected\n"); printf("Sending a single get_state RPC to get reply size\n"); printf("(this is used to guess when the client hangs)\n"); sendall(sock, rpc_data, rpc_len); //receive it all and calculate size char buf[1024]; char* ptr = NULL; int bytes_recv = 0, reply_size = 0; do { bytes_recv = recv(sock, buf, sizeof(buf), 0); ptr = memchr(buf, '\003', bytes_recv); if (ptr == NULL) { reply_size += bytes_recv; } else { reply_size += ptr - buf; } } while(ptr == NULL); printf("RPC reply was %d bytes long\n", reply_size); int i, sleeptime; for(i=1; i<1000; i++) { sendall(sock, rpc_data, rpc_len); printf("sent RPC #%d, ~%d bytes on network buffer", i, i*reply_size); //this number found by testing; definitely not accurate if (i*reply_size < 144000) { sleeptime = 1; sleep(1); } else { sleeptime = 4; printf(" - BOINC must be hanged by now"); } printf("\r"); fflush(stdout); sleep(sleeptime); } return 0; } int sendall(int s, const char *buf, int len) { int bytesleft = len; int n; while (bytesleft > 0) { n = send(s, buf, bytesleft, 0); if (n == -1) { break; } buf += n; bytesleft -= n; } return n==-1?-1:0; // return -1 on failure, 0 on success } /* vim: set ts=4 sw=4 et cino+=g0: */