|
|
@@ -93,25 +93,27 @@ static int init_socket(const char *server_addr) {
|
|
|
|
|
|
|
|
|
static int send_msg(const char *msg) {
|
|
|
- char *buf;
|
|
|
+ struct vcc_request req;
|
|
|
|
|
|
- if (unlikely(!(buf = malloc(REQ_SIZE)))) {
|
|
|
- fprintf(stderr, "*** malloc() failed\n");
|
|
|
-
|
|
|
- exit(1);
|
|
|
- }
|
|
|
-
|
|
|
- strcpy(buf, msg);
|
|
|
- write(fd, buf, REQ_SIZE);
|
|
|
-
|
|
|
- free(buf);
|
|
|
+ strcpy(req.msg, msg);
|
|
|
+ write(fd, &req, REQ_SIZE);
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
static int read_msg(char *buf) {
|
|
|
- return read(fd, buf, REQ_SIZE);
|
|
|
+ struct vcc_request req;
|
|
|
+ int n;
|
|
|
+
|
|
|
+ n = read(fd, &req, REQ_SIZE);
|
|
|
+
|
|
|
+ if (n < 0)
|
|
|
+ return n;
|
|
|
+
|
|
|
+ memcpy(buf, req.msg, MSG_SIZE);
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -151,7 +153,7 @@ int main(int argc, const char **argv) {
|
|
|
|
|
|
printf("Connected to server. \n");
|
|
|
|
|
|
- if (!(pid = fork())) {
|
|
|
+ if ((pid = fork())) {
|
|
|
/* receive messages */
|
|
|
|
|
|
setup_alarm();
|