48 lines
851 B
C
48 lines
851 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/un.h>
|
|
|
|
#include <time.h>
|
|
|
|
#define FILENAME "cachesync.sock"
|
|
|
|
int main(int argc, char *argv[])
|
|
{
|
|
if (argc != 2) {
|
|
printf("$ testclient <cmd>\n");
|
|
exit(0);
|
|
}
|
|
|
|
int sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
|
if (sockfd == -1) {
|
|
perror("socket()");
|
|
exit(-1);
|
|
}
|
|
|
|
struct sockaddr_un addr;
|
|
addr.sun_family = AF_UNIX;
|
|
strncpy(addr.sun_path, FILENAME, sizeof(addr.sun_path));
|
|
int len = sizeof(addr.sun_family) + strlen(addr.sun_path);
|
|
|
|
if (connect(sockfd, (struct sockaddr *)&addr, len) < 0) {
|
|
perror("connect()");
|
|
exit(-1);
|
|
}
|
|
|
|
srandom(time(NULL));
|
|
usleep((random() % 100) * 10000);
|
|
|
|
write(sockfd, argv[1], strlen(argv[1]) +1);
|
|
|
|
usleep((random() % 100) * 10000);
|
|
|
|
close(sockfd);
|
|
|
|
return 0;
|
|
}
|