forked from Helioviewer-Project/hvJP2K
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhv_jpx_mergec.c
47 lines (37 loc) · 1.01 KB
/
hv_jpx_mergec.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static const char *socket_path = "/tmp/hv_jpx_merged_socket";
#define BUF_SIZE 1024
int main(int argc, char **argv)
{
struct sockaddr_un addr;
char buf[BUF_SIZE];
int fd, rc;
if (argc > 1)
socket_path = argv[1];
if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
perror("socket error");
exit(-1);
}
memset(&addr, 0, sizeof addr);
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, socket_path, sizeof addr.sun_path - 1);
if (connect(fd, (struct sockaddr *) &addr, sizeof addr) == -1) {
perror("connect error");
exit(-1);
}
while ((rc = read(STDIN_FILENO, buf, sizeof buf)) > 0)
if (write(fd, buf, rc) != rc) {
if (rc > 0)
fprintf(stderr, "partial write");
else {
perror("write error");
exit(-1);
}
}
return 0;
}