summaryrefslogtreecommitdiff
path: root/src/bin/ethumb_client
diff options
context:
space:
mode:
authorAndrii Kroitor <an.kroitor@samsung.com>2016-12-22 13:15:42 +0200
committerAndrii Kroitor <an.kroitor@samsung.com>2016-12-22 14:13:40 +0200
commit9f6d773fcea57e4863c8286b5aaab7128dee92e8 (patch)
treedf148c7bed419ff20474d83e1906412ed1652b53 /src/bin/ethumb_client
parent053613db5277708f81de5b4e088155c127ba8ec9 (diff)
ethumb: rewrite slave input/output
Using stdio instead of low-level read and write because low-level API has different behaviour on Linux and Windows.
Diffstat (limited to 'src/bin/ethumb_client')
-rw-r--r--src/bin/ethumb_client/ethumbd_slave.c143
1 files changed, 60 insertions, 83 deletions
diff --git a/src/bin/ethumb_client/ethumbd_slave.c b/src/bin/ethumb_client/ethumbd_slave.c
index 09efff52f3..d7b7ff6680 100644
--- a/src/bin/ethumb_client/ethumbd_slave.c
+++ b/src/bin/ethumb_client/ethumbd_slave.c
@@ -25,6 +25,7 @@
25#endif 25#endif
26 26
27#include <stdlib.h> 27#include <stdlib.h>
28#include <stdio.h>
28#include <unistd.h> 29#include <unistd.h>
29#include <limits.h> 30#include <limits.h>
30#include <string.h> 31#include <string.h>
@@ -57,74 +58,49 @@ struct _Ethumbd_Child
57}; 58};
58 59
59 60
60int 61static int
61_ec_read_safe(int fd, void *buf, ssize_t size) 62_ec_read_safe(FILE* stream, void *buf, ssize_t size)
62{ 63{
63 ssize_t todo; 64 ssize_t todo;
64 char *p; 65 unsigned char *p;
66 int c;
65 67
66 todo = size; 68 todo = size;
67 p = buf; 69 p = buf;
68 70
69 while (todo > 0) 71 while (todo > 0)
70 { 72 {
71 ssize_t r; 73 c = getc(stream);
72 74 if (c == EOF)
73 r = read(fd, p, todo); 75 {
74 if (r > 0) 76 ERR("could not read from stream %p", stream);
75 { 77 return 0;
76 todo -= r; 78 }
77 p += r; 79 *p = c;
78 } 80 ++p;
79 else if (r == 0) 81 --todo;
80 return 0;
81 else
82 {
83 if (errno == EINTR || errno == EAGAIN)
84 continue;
85 else
86 {
87 ERR("could not read from fd %d: %s",
88 fd, strerror(errno));
89 return 0;
90 }
91 }
92 } 82 }
93
94 return 1; 83 return 1;
95} 84}
96 85
97int 86static int
98_ec_write_safe(int fd, const void *buf, ssize_t size) 87_ec_write_safe(FILE *stream, const void *buf, ssize_t size)
99{ 88{
100 ssize_t todo; 89 ssize_t todo;
101 const char *p; 90 const unsigned char *p;
102 91
103 todo = size; 92 todo = size;
104 p = buf; 93 p = buf;
105 94
106 while (todo > 0) 95 while (todo > 0)
107 { 96 {
108 ssize_t r; 97 if (putc(*p, stream) == EOF)
109 98 {
110 r = write(fd, p, todo); 99 ERR("could not write to stream %p", stream);
111 if (r > 0) 100 return 0;
112 { 101 }
113 todo -= r; 102 ++p;
114 p += r; 103 --todo;
115 }
116 else if (r == 0)
117 return 0;
118 else
119 {
120 if (errno == EINTR || errno == EAGAIN)
121 continue;
122 else
123 {
124 ERR("could not write to fd %d: %s", fd, strerror(errno));
125 return 0;
126 }
127 }
128 } 104 }
129 105
130 return 1; 106 return 1;
@@ -137,7 +113,7 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec EINA_UNUSED, char **str)
137 int r; 113 int r;
138 char buf[PATH_MAX] = { '\0' }; 114 char buf[PATH_MAX] = { '\0' };
139 115
140 r = _ec_read_safe(STDIN_FILENO, &size, sizeof(size)); 116 r = _ec_read_safe(stdin, &size, sizeof(size));
141 if (!r) 117 if (!r)
142 { 118 {
143 *str = NULL; 119 *str = NULL;
@@ -150,7 +126,7 @@ _ec_pipe_str_read(struct _Ethumbd_Child *ec EINA_UNUSED, char **str)
150 return 1; 126 return 1;
151 } 127 }
152 128
153 r = _ec_read_safe(STDIN_FILENO, buf, size); 129 r = _ec_read_safe(stdin, buf, size);
154 if (!r) 130 if (!r)
155 { 131 {
156 *str = NULL; 132 *str = NULL;
@@ -199,7 +175,7 @@ _ec_op_new(struct _Ethumbd_Child *ec)
199 int r; 175 int r;
200 int idx; 176 int idx;
201 177
202 r = _ec_read_safe(STDIN_FILENO, &idx, sizeof(idx)); 178 r = _ec_read_safe(stdin, &idx, sizeof(idx));
203 if (!r) 179 if (!r)
204 return 0; 180 return 0;
205 181
@@ -215,7 +191,7 @@ _ec_op_del(struct _Ethumbd_Child *ec)
215 int r; 191 int r;
216 int idx; 192 int idx;
217 193
218 r = _ec_read_safe(STDIN_FILENO, &idx, sizeof(idx)); 194 r = _ec_read_safe(stdin, &idx, sizeof(idx));
219 if (!r) 195 if (!r)
220 return 0; 196 return 0;
221 197
@@ -248,14 +224,15 @@ _ec_op_generated_cb(void *data EINA_UNUSED, Ethumb *e, Eina_Bool success)
248 size_cmd = sizeof(success) + sizeof(size_path) + size_path + 224 size_cmd = sizeof(success) + sizeof(size_path) + size_path +
249 sizeof(size_key) + size_key; 225 sizeof(size_key) + size_key;
250 226
251 _ec_write_safe(STDOUT_FILENO, &size_cmd, sizeof(size_cmd)); 227 _ec_write_safe(stdout, &size_cmd, sizeof(size_cmd));
252 _ec_write_safe(STDOUT_FILENO, &success, sizeof(success)); 228 _ec_write_safe(stdout, &success, sizeof(success));
253 229
254 _ec_write_safe(STDOUT_FILENO, &size_path, sizeof(size_path)); 230 _ec_write_safe(stdout, &size_path, sizeof(size_path));
255 _ec_write_safe(STDOUT_FILENO, thumb_path, size_path); 231 _ec_write_safe(stdout, thumb_path, size_path);
256 232
257 _ec_write_safe(STDOUT_FILENO, &size_key, sizeof(size_key)); 233 _ec_write_safe(stdout, &size_key, sizeof(size_key));
258 _ec_write_safe(STDOUT_FILENO, thumb_key, size_key); 234 _ec_write_safe(stdout, thumb_key, size_key);
235 fflush(stdout);
259} 236}
260 237
261static int 238static int
@@ -265,7 +242,7 @@ _ec_op_generate(struct _Ethumbd_Child *ec)
265 char *path, *key, *thumb_path, *thumb_key; 242 char *path, *key, *thumb_path, *thumb_key;
266 int r; 243 int r;
267 244
268 r = _ec_read_safe(STDIN_FILENO, &idx, sizeof(idx)); 245 r = _ec_read_safe(stdin, &idx, sizeof(idx));
269 if (!r) 246 if (!r)
270 return 0; 247 return 0;
271 248
@@ -320,7 +297,7 @@ _ec_fdo_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
320 int r; 297 int r;
321 int value; 298 int value;
322 299
323 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 300 r = _ec_read_safe(stdin, &value, sizeof(value));
324 if (!r) 301 if (!r)
325 return 0; 302 return 0;
326 ethumb_thumb_fdo_set(e, value); 303 ethumb_thumb_fdo_set(e, value);
@@ -336,13 +313,13 @@ _ec_size_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
336 int w, h; 313 int w, h;
337 int type; 314 int type;
338 315
339 r = _ec_read_safe(STDIN_FILENO, &w, sizeof(w)); 316 r = _ec_read_safe(stdin, &w, sizeof(w));
340 if (!r) 317 if (!r)
341 return 0; 318 return 0;
342 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); 319 r = _ec_read_safe(stdin, &type, sizeof(type));
343 if (!r) 320 if (!r)
344 return 0; 321 return 0;
345 r = _ec_read_safe(STDIN_FILENO, &h, sizeof(h)); 322 r = _ec_read_safe(stdin, &h, sizeof(h));
346 if (!r) 323 if (!r)
347 return 0; 324 return 0;
348 ethumb_thumb_size_set(e, w, h); 325 ethumb_thumb_size_set(e, w, h);
@@ -357,7 +334,7 @@ _ec_format_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
357 int r; 334 int r;
358 int value; 335 int value;
359 336
360 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 337 r = _ec_read_safe(stdin, &value, sizeof(value));
361 if (!r) 338 if (!r)
362 return 0; 339 return 0;
363 ethumb_thumb_format_set(e, value); 340 ethumb_thumb_format_set(e, value);
@@ -372,7 +349,7 @@ _ec_aspect_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
372 int r; 349 int r;
373 int value; 350 int value;
374 351
375 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 352 r = _ec_read_safe(stdin, &value, sizeof(value));
376 if (!r) 353 if (!r)
377 return 0; 354 return 0;
378 ethumb_thumb_aspect_set(e, value); 355 ethumb_thumb_aspect_set(e, value);
@@ -387,7 +364,7 @@ _ec_orientation_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
387 int r; 364 int r;
388 int value; 365 int value;
389 366
390 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 367 r = _ec_read_safe(stdin, &value, sizeof(value));
391 if (!r) 368 if (!r)
392 return 0; 369 return 0;
393 ethumb_thumb_orientation_set(e, value); 370 ethumb_thumb_orientation_set(e, value);
@@ -403,13 +380,13 @@ _ec_crop_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
403 float x, y; 380 float x, y;
404 int type; 381 int type;
405 382
406 r = _ec_read_safe(STDIN_FILENO, &x, sizeof(x)); 383 r = _ec_read_safe(stdin, &x, sizeof(x));
407 if (!r) 384 if (!r)
408 return 0; 385 return 0;
409 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); 386 r = _ec_read_safe(stdin, &type, sizeof(type));
410 if (!r) 387 if (!r)
411 return 0; 388 return 0;
412 r = _ec_read_safe(STDIN_FILENO, &y, sizeof(y)); 389 r = _ec_read_safe(stdin, &y, sizeof(y));
413 if (!r) 390 if (!r)
414 return 0; 391 return 0;
415 ethumb_thumb_crop_align_set(e, x, y); 392 ethumb_thumb_crop_align_set(e, x, y);
@@ -424,7 +401,7 @@ _ec_quality_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
424 int r; 401 int r;
425 int value; 402 int value;
426 403
427 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 404 r = _ec_read_safe(stdin, &value, sizeof(value));
428 if (!r) 405 if (!r)
429 return 0; 406 return 0;
430 ethumb_thumb_quality_set(e, value); 407 ethumb_thumb_quality_set(e, value);
@@ -439,7 +416,7 @@ _ec_compress_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
439 int r; 416 int r;
440 int value; 417 int value;
441 418
442 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 419 r = _ec_read_safe(stdin, &value, sizeof(value));
443 if (!r) 420 if (!r)
444 return 0; 421 return 0;
445 ethumb_thumb_compress_set(e, value); 422 ethumb_thumb_compress_set(e, value);
@@ -458,7 +435,7 @@ _ec_frame_set(struct _Ethumbd_Child *ec, Ethumb *e)
458 r = _ec_pipe_str_read(ec, &theme_file); 435 r = _ec_pipe_str_read(ec, &theme_file);
459 if (!r) 436 if (!r)
460 return 0; 437 return 0;
461 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); 438 r = _ec_read_safe(stdin, &type, sizeof(type));
462 if (!r) 439 if (!r)
463 { 440 {
464 free(theme_file); 441 free(theme_file);
@@ -470,7 +447,7 @@ _ec_frame_set(struct _Ethumbd_Child *ec, Ethumb *e)
470 free(theme_file); 447 free(theme_file);
471 return 0; 448 return 0;
472 } 449 }
473 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); 450 r = _ec_read_safe(stdin, &type, sizeof(type));
474 if (!r) 451 if (!r)
475 { 452 {
476 free(theme_file); 453 free(theme_file);
@@ -531,7 +508,7 @@ _ec_video_time_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
531 int r; 508 int r;
532 float value; 509 float value;
533 510
534 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 511 r = _ec_read_safe(stdin, &value, sizeof(value));
535 if (!r) 512 if (!r)
536 return 0; 513 return 0;
537 ethumb_video_time_set(e, value); 514 ethumb_video_time_set(e, value);
@@ -546,7 +523,7 @@ _ec_video_start_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
546 int r; 523 int r;
547 float value; 524 float value;
548 525
549 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 526 r = _ec_read_safe(stdin, &value, sizeof(value));
550 if (!r) 527 if (!r)
551 return 0; 528 return 0;
552 ethumb_video_start_set(e, value); 529 ethumb_video_start_set(e, value);
@@ -561,7 +538,7 @@ _ec_video_interval_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
561 int r; 538 int r;
562 float value; 539 float value;
563 540
564 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 541 r = _ec_read_safe(stdin, &value, sizeof(value));
565 if (!r) 542 if (!r)
566 return 0; 543 return 0;
567 ethumb_video_interval_set(e, value); 544 ethumb_video_interval_set(e, value);
@@ -576,7 +553,7 @@ _ec_video_ntimes_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
576 int r; 553 int r;
577 int value; 554 int value;
578 555
579 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 556 r = _ec_read_safe(stdin, &value, sizeof(value));
580 if (!r) 557 if (!r)
581 return 0; 558 return 0;
582 ethumb_video_ntimes_set(e, value); 559 ethumb_video_ntimes_set(e, value);
@@ -591,7 +568,7 @@ _ec_video_fps_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
591 int r; 568 int r;
592 int value; 569 int value;
593 570
594 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 571 r = _ec_read_safe(stdin, &value, sizeof(value));
595 if (!r) 572 if (!r)
596 return 0; 573 return 0;
597 ethumb_video_fps_set(e, value); 574 ethumb_video_fps_set(e, value);
@@ -606,7 +583,7 @@ _ec_document_page_set(struct _Ethumbd_Child *ec EINA_UNUSED, Ethumb *e)
606 int r; 583 int r;
607 int value; 584 int value;
608 585
609 r = _ec_read_safe(STDIN_FILENO, &value, sizeof(value)); 586 r = _ec_read_safe(stdin, &value, sizeof(value));
610 if (!r) 587 if (!r)
611 return 0; 588 return 0;
612 ethumb_document_page_set(e, value); 589 ethumb_document_page_set(e, value);
@@ -687,17 +664,17 @@ _ec_op_setup(struct _Ethumbd_Child *ec)
687 int idx; 664 int idx;
688 int type; 665 int type;
689 666
690 r = _ec_read_safe(STDIN_FILENO, &idx, sizeof(idx)); 667 r = _ec_read_safe(stdin, &idx, sizeof(idx));
691 if (!r) 668 if (!r)
692 return 0; 669 return 0;
693 670
694 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); 671 r = _ec_read_safe(stdin, &type, sizeof(type));
695 if (!r) 672 if (!r)
696 return 0; 673 return 0;
697 while (type != ETHUMBD_SETUP_FINISHED) 674 while (type != ETHUMBD_SETUP_FINISHED)
698 { 675 {
699 _ec_setup_process(ec, idx, type); 676 _ec_setup_process(ec, idx, type);
700 r = _ec_read_safe(STDIN_FILENO, &type, sizeof(type)); 677 r = _ec_read_safe(stdin, &type, sizeof(type));
701 if (!r) 678 if (!r)
702 return 0; 679 return 0;
703 } 680 }
@@ -727,7 +704,7 @@ _ec_fd_handler(void *data, Ecore_Win32_Handler *fd_handler EINA_UNUSED)
727 } 704 }
728#endif 705#endif
729 706
730 r = _ec_read_safe(STDIN_FILENO, &op_id, sizeof(op_id)); 707 r = _ec_read_safe(stdin, &op_id, sizeof(op_id));
731 if (!r) 708 if (!r)
732 { 709 {
733 DBG("ethumbd exited! child exiting..."); 710 DBG("ethumbd exited! child exiting...");