1 #ifdef HAVE_CONFIG_H
2 # include <config.h>
3 #endif
4
5 #include <process.h>
6
7 #include <Ecore.h>
8
9 #include "Ecore_Con.h"
10 #include "ecore_con_private.h"
11
12 #define BUFSIZE 512
13
14 static int _ecore_con_local_init_count = 0;
15
16 int
ecore_con_local_init(void)17 ecore_con_local_init(void)
18 {
19 if (++_ecore_con_local_init_count != 1)
20 return _ecore_con_local_init_count;
21
22 return _ecore_con_local_init_count;
23 }
24
25 int
ecore_con_local_shutdown(void)26 ecore_con_local_shutdown(void)
27 {
28 if (--_ecore_con_local_init_count != 0)
29 return _ecore_con_local_init_count;
30
31 return _ecore_con_local_init_count;
32 }
33
34 static Eina_Bool
_ecore_con_local_win32_server_read_client_handler(void * data,Ecore_Win32_Handler * wh)35 _ecore_con_local_win32_server_read_client_handler(void *data, Ecore_Win32_Handler *wh)
36 {
37 Ecore_Con_Client *obj = data;
38 Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
39 void *buf;
40 DWORD n;
41 Eina_Bool broken_pipe = EINA_FALSE;
42 Efl_Network_Server_Data *host_svr = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
43
44 if (!ResetEvent(host_svr->event_read))
45 return ECORE_CALLBACK_RENEW;
46
47 buf = malloc(host_svr->nbr_bytes);
48 if (!buf)
49 return ECORE_CALLBACK_RENEW;
50
51 if (ReadFile(host_svr->pipe, buf, host_svr->nbr_bytes, &n, NULL))
52 {
53 if (!cl->delete_me)
54 ecore_con_event_client_data(obj, buf, host_svr->nbr_bytes, EINA_FALSE);
55 host_svr->want_write = 1;
56 }
57 else
58 {
59 if (GetLastError() == ERROR_BROKEN_PIPE)
60 broken_pipe = EINA_TRUE;
61 }
62
63 if (broken_pipe)
64 {
65 #if 0
66 ecore_con_event_client_error(cl, evil_last_error_get());
67 #endif
68 _ecore_con_client_kill(obj);
69 return ECORE_CALLBACK_CANCEL;
70 }
71
72 if (host_svr->want_write)
73 ecore_con_local_win32_client_flush(obj);
74
75 ecore_main_win32_handler_del(wh);
76
77 return ECORE_CALLBACK_DONE;
78 }
79
80 static Eina_Bool
_ecore_con_local_win32_server_peek_client_handler(void * data,Ecore_Win32_Handler * wh)81 _ecore_con_local_win32_server_peek_client_handler(void *data, Ecore_Win32_Handler *wh)
82 {
83 Ecore_Con_Client *obj = data;
84 Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
85 Efl_Network_Server_Data *host_svr = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
86 #if 0
87 char *msg;
88 #endif
89
90 if (!ResetEvent(host_svr->event_peek))
91 return ECORE_CALLBACK_RENEW;
92
93 #if 0
94 ecore_con_event_server_error(host_svr, evil_last_error_get());
95 #endif
96 _ecore_con_server_kill(cl->host_server);
97 return ECORE_CALLBACK_CANCEL;
98
99 ecore_main_win32_handler_del(wh);
100
101 return ECORE_CALLBACK_DONE;
102 }
103
104 static Eina_Bool
_ecore_con_local_win32_client_peek_server_handler(void * data,Ecore_Win32_Handler * wh)105 _ecore_con_local_win32_client_peek_server_handler(void *data, Ecore_Win32_Handler *wh)
106 {
107 Ecore_Con_Server *obj = data;
108 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
109 #if 0
110 char *msg;
111 #endif
112
113 if (!ResetEvent(svr->event_peek))
114 return ECORE_CALLBACK_RENEW;
115 #if 0
116 ecore_con_event_server_error(svr, evil_last_error_get());
117 #endif
118 _ecore_con_server_kill(obj);
119 return ECORE_CALLBACK_CANCEL;
120
121 ecore_main_win32_handler_del(wh);
122
123 return ECORE_CALLBACK_DONE;
124 }
125
126 static Eina_Bool
_ecore_con_local_win32_client_read_server_handler(void * data,Ecore_Win32_Handler * wh)127 _ecore_con_local_win32_client_read_server_handler(void *data, Ecore_Win32_Handler *wh)
128 {
129 Ecore_Con_Server *obj = data;
130 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
131 void *buf;
132 DWORD n;
133 Eina_Bool broken_pipe = EINA_FALSE;
134
135 if (!ResetEvent(svr->event_read))
136 return ECORE_CALLBACK_RENEW;
137
138 buf = malloc(svr->nbr_bytes);
139 if (!buf)
140 return ECORE_CALLBACK_RENEW;
141
142 if (ReadFile(svr->pipe, buf, svr->nbr_bytes, &n, NULL))
143 {
144 if (!svr->delete_me)
145 ecore_con_event_server_data(obj, buf, svr->nbr_bytes, EINA_FALSE);
146 svr->want_write = 1;
147 }
148 else
149 {
150 if (GetLastError() == ERROR_BROKEN_PIPE)
151 broken_pipe = EINA_TRUE;
152 }
153
154 if (broken_pipe)
155 {
156 #if 0
157 ecore_con_event_server_error(svr, evil_last_error_get());
158 #endif
159 _ecore_con_server_kill(obj);
160 return ECORE_CALLBACK_CANCEL;
161 }
162
163 if (svr->want_write)
164 ecore_con_local_win32_server_flush(obj);
165
166 ecore_main_win32_handler_del(wh);
167
168 return ECORE_CALLBACK_DONE;
169 }
170
171 /* thread to read data sent by the server to the client */
172 static unsigned int __stdcall
_ecore_con_local_win32_client_read_server_thread(void * data)173 _ecore_con_local_win32_client_read_server_thread(void *data)
174 {
175 Ecore_Con_Server *obj = data;
176 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
177 DWORD nbr_bytes = 0;
178
179 svr->read_stopped = EINA_FALSE;
180
181 while (!svr->read_stop)
182 {
183 if (PeekNamedPipe(svr->pipe, NULL, 0, NULL, &nbr_bytes, NULL))
184 {
185 if (nbr_bytes <= 0)
186 continue;
187
188 svr->nbr_bytes = nbr_bytes;
189 if (!SetEvent(svr->event_read))
190 continue;
191 }
192 else
193 {
194 if (GetLastError() == ERROR_BROKEN_PIPE)
195 {
196 if (!SetEvent(svr->event_peek))
197 continue;
198 break;
199 }
200 }
201 }
202
203 svr->read_stopped = EINA_TRUE;
204 _endthreadex(0);
205 return 0;
206 }
207
208 /* thread to read data sent by the client to the server */
209 static unsigned int __stdcall
_ecore_con_local_win32_server_read_client_thread(void * data)210 _ecore_con_local_win32_server_read_client_thread(void *data)
211 {
212 Ecore_Con_Client *obj = data;
213 Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
214 Efl_Network_Server_Data *host_svr = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
215 DWORD nbr_bytes = 0;
216
217 host_svr->read_stopped = EINA_FALSE;
218
219 while (!host_svr->read_stop)
220 {
221 if (PeekNamedPipe(host_svr->pipe, NULL, 0, NULL, &nbr_bytes, NULL))
222 {
223 if (nbr_bytes <= 0)
224 continue;
225
226 host_svr->nbr_bytes = nbr_bytes;
227 if (!SetEvent(host_svr->event_read))
228 continue;
229 }
230 else
231 {
232 if (GetLastError() == ERROR_BROKEN_PIPE)
233 {
234 if (!SetEvent(host_svr->event_peek))
235 continue;
236 break;
237 }
238 }
239 }
240
241 host_svr->read_stopped = EINA_TRUE;
242 _endthreadex(0);
243 return 0;
244 }
245
246 static Eina_Bool
_ecore_con_local_win32_client_add(void * data,Ecore_Win32_Handler * wh)247 _ecore_con_local_win32_client_add(void *data, Ecore_Win32_Handler *wh)
248 {
249 Ecore_Con_Server *obj = data;
250 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
251 Ecore_Win32_Handler *handler_read;
252 Ecore_Win32_Handler *handler_peek;
253
254 if (!svr->pipe)
255 return ECORE_CALLBACK_CANCEL;
256
257 if (svr->delete_me)
258 return ECORE_CALLBACK_CANCEL;
259
260 if ((svr->client_limit >= 0) && (!svr->reject_excess_clients) &&
261 (svr->client_count >= (unsigned int)svr->client_limit))
262 return ECORE_CALLBACK_CANCEL;
263
264 Ecore_Con_Client *cl_obj = efl_add(EFL_NETWORK_CLIENT_CLASS, efl_main_loop_get());
265 Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
266 if (!cl)
267 {
268 ERR("allocation failed");
269 return ECORE_CALLBACK_CANCEL;
270 }
271
272 cl->host_server = obj;
273
274 svr->event_read = CreateEvent(NULL, TRUE, FALSE, NULL);
275 if (!svr->event_read)
276 {
277 ERR("Can not create event read");
278 goto free_cl;
279 }
280
281 handler_read = ecore_main_win32_handler_add(svr->event_read,
282 _ecore_con_local_win32_server_read_client_handler,
283 obj);
284 if (!handler_read)
285 {
286 ERR("Can not create handler read");
287 goto close_event_read;
288 }
289
290 svr->event_peek = CreateEvent(NULL, TRUE, FALSE, NULL);
291 if (!svr->event_peek)
292 {
293 ERR("Can not create event peek");
294 goto del_handler_read;
295 }
296
297 handler_peek = ecore_main_win32_handler_add(svr->event_peek,
298 _ecore_con_local_win32_server_peek_client_handler,
299 obj);
300 if (!handler_peek)
301 {
302 ERR("Can not create handler peek");
303 goto close_event_peek;
304 }
305
306 svr->read_stopped = EINA_TRUE;
307 svr->thread_read = (HANDLE)_beginthreadex(NULL, 0, _ecore_con_local_win32_server_read_client_thread, cl, CREATE_SUSPENDED, NULL);
308 if (!svr->thread_read)
309 {
310 ERR("Can not launch thread");
311 goto del_handler_peek;
312 }
313
314 svr->clients = eina_list_append(svr->clients, obj);
315 svr->client_count++;
316
317 if (!cl->delete_me)
318 ecore_con_event_client_add(obj);
319
320 ecore_main_win32_handler_del(wh);
321
322 ResumeThread(svr->thread_read);
323 return ECORE_CALLBACK_DONE;
324
325 del_handler_peek:
326 ecore_main_win32_handler_del(handler_peek);
327 close_event_peek:
328 CloseHandle(svr->event_peek);
329 del_handler_read:
330 ecore_main_win32_handler_del(handler_read);
331 close_event_read:
332 CloseHandle(svr->event_read);
333 free_cl:
334 efl_del(cl_obj);
335
336 return ECORE_CALLBACK_CANCEL;
337 }
338
339 static unsigned int __stdcall
_ecore_con_local_win32_listening(void * data)340 _ecore_con_local_win32_listening(void *data)
341 {
342 Ecore_Con_Server *obj = data;
343 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
344 BOOL res;
345
346 while (1)
347 {
348 res = ConnectNamedPipe(svr->pipe, NULL);
349 if (!res)
350 {
351 ERR("Opening the connection to the client failed");
352 CloseHandle(svr->pipe);
353 svr->pipe = NULL;
354 }
355 break;
356 }
357
358 DBG("Client connected");
359
360 _endthreadex(0);
361 return 0;
362 }
363
364 EAPI char *
ecore_con_local_path_new(Eina_Bool is_system,const char * name,int port)365 ecore_con_local_path_new(Eina_Bool is_system, const char *name, int port)
366 {
367 char buf[256];
368
369 if (!is_system)
370 snprintf(buf, sizeof(buf), "\\\\.\\pipe\\%s%ld", name, GetProcessId(GetCurrentProcess()));
371 else
372 {
373 const char *computername;
374
375 computername = getenv("COMPUTERNAME");
376 snprintf(buf, sizeof(buf), "\\\\%s\\pipe\\%s%ld", computername, name, GetProcessId(GetCurrentProcess()));
377 }
378
379 return strdup(buf);
380 (void)port; // CHECK-ME: shouldn't we use port to be similar to UNIX?
381 }
382
383 Eina_Bool
ecore_con_local_listen(Ecore_Con_Server * obj)384 ecore_con_local_listen(Ecore_Con_Server *obj)
385 {
386 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
387 HANDLE thread_listening;
388 Ecore_Win32_Handler *handler;
389
390 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
391 {
392 ERR("Your system does not support abstract sockets!");
393 return EINA_FALSE;
394 }
395
396 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_USER)
397 svr->path = ecore_con_local_path_new(EINA_FALSE, svr->name, svr->port);
398 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
399 svr->path = ecore_con_local_path_new(EINA_TRUE, svr->name, svr->port);
400
401 if (!svr->path)
402 {
403 ERR("Allocation failed");
404 return EINA_FALSE;
405 }
406
407 /*
408 * synchronuous
409 * block mode
410 * wait mode
411 */
412 svr->pipe = CreateNamedPipe(svr->path,
413 PIPE_ACCESS_DUPLEX,
414 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
415 PIPE_UNLIMITED_INSTANCES,
416 BUFSIZE,
417 BUFSIZE,
418 5000,
419 NULL);
420 if (svr->pipe == INVALID_HANDLE_VALUE)
421 {
422 DBG("Creation of the named pipe '%s' failed", svr->path);
423 goto free_path;
424 }
425
426 /*
427 * We use ConnectNamedPipe() to wait for a client to connect.
428 * As the function is blocking, to let the main loop continuing
429 * its iterations, we call ConnectNamedPipe() in a thread
430 */
431 thread_listening = (HANDLE)_beginthreadex(NULL, 0, _ecore_con_local_win32_listening, obj, CREATE_SUSPENDED, NULL);
432 if (!thread_listening)
433 {
434 ERR("Creation of the listening thread failed");
435 goto close_pipe;
436 }
437
438 handler = ecore_main_win32_handler_add(thread_listening,
439 _ecore_con_local_win32_client_add,
440 obj);
441 if (!handler)
442 {
443 ERR("Creation of the client add handler failed");
444 goto del_handler;
445 }
446
447 svr->read_stopped = EINA_TRUE;
448 ResumeThread(thread_listening);
449
450 return EINA_TRUE;
451
452 del_handler:
453 ecore_main_win32_handler_del(handler);
454 close_pipe:
455 CloseHandle(svr->pipe);
456 free_path:
457 free(svr->path);
458 svr->path = NULL;
459
460 return EINA_FALSE;
461 }
462
463 void
ecore_con_local_win32_server_del(Ecore_Con_Server * obj)464 ecore_con_local_win32_server_del(Ecore_Con_Server *obj)
465 {
466 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
467 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
468 return;
469
470 if (((svr->type & ECORE_CON_TYPE) != ECORE_CON_LOCAL_USER) &&
471 ((svr->type & ECORE_CON_TYPE) != ECORE_CON_LOCAL_SYSTEM))
472 return;
473
474 svr->read_stop = 1;
475 /* FIXME: we should try to stop these thread in one way or another */
476 /* should we use ecore_thread ? */
477 /* while (!svr->read_stopped) */
478 /* Sleep(100); */
479
480 if (svr->event_peek)
481 CloseHandle(svr->event_peek);
482 svr->event_peek = NULL;
483 if (svr->event_read)
484 CloseHandle(svr->event_read);
485 svr->event_read = NULL;
486 free(svr->path);
487 svr->path = NULL;
488 if (svr->pipe)
489 CloseHandle(svr->pipe);
490 svr->pipe = NULL;
491 }
492
493 void
ecore_con_local_win32_client_del(Ecore_Con_Client * obj)494 ecore_con_local_win32_client_del(Ecore_Con_Client *obj)
495 {
496 Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
497 Efl_Network_Server_Data *svr = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
498
499 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
500 return;
501
502 if (((svr->type & ECORE_CON_TYPE) != ECORE_CON_LOCAL_USER) &&
503 ((svr->type & ECORE_CON_TYPE) != ECORE_CON_LOCAL_SYSTEM))
504 return;
505
506 svr->read_stop = 1;
507 while (!svr->read_stopped)
508 Sleep(100);
509
510 if (svr->event_peek)
511 CloseHandle(svr->event_peek);
512 svr->event_peek = NULL;
513 if (svr->event_read)
514 CloseHandle(svr->event_read);
515 svr->event_read = NULL;
516 free(svr->path);
517 svr->path = NULL;
518 if (svr->pipe)
519 CloseHandle(svr->pipe);
520 svr->pipe = NULL;
521 }
522
523 Eina_Bool
ecore_con_local_connect(Ecore_Con_Server * obj,Eina_Bool (* cb_done)(void * data,Ecore_Fd_Handler * fd_handler))524 ecore_con_local_connect(Ecore_Con_Server *obj,
525 Eina_Bool (*cb_done)(void *data,
526 Ecore_Fd_Handler *fd_handler))
527 {
528 #warning "I am pretty sure cb_done should be used."
529 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
530 char *buf = NULL;
531 Ecore_Win32_Handler *handler_read;
532 Ecore_Win32_Handler *handler_peek;
533
534 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
535 {
536 WRN("Your system does not support abstract sockets!");
537 return EINA_FALSE;
538 }
539
540 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_USER)
541 buf = ecore_con_local_path_new(EINA_FALSE, svr->name, svr->port);
542 else if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_SYSTEM)
543 buf = ecore_con_local_path_new(EINA_TRUE, svr->name, svr->port);
544
545 EINA_SAFETY_ON_NULL_RETURN_VAL(buf, EINA_FALSE);
546
547 while (1)
548 {
549 svr->pipe = CreateFile(buf,
550 GENERIC_READ | GENERIC_WRITE,
551 0,
552 NULL,
553 OPEN_EXISTING,
554 0,
555 NULL);
556 if (svr->pipe != INVALID_HANDLE_VALUE)
557 break;
558
559 /* if pipe not busy, we exit */
560 if (GetLastError() != ERROR_PIPE_BUSY)
561 {
562 DBG("Connection to a server failed");
563 free(buf);
564 return EINA_FALSE;
565 }
566
567 /* pipe busy, so we wait for it */
568 if (!WaitNamedPipe(buf, NMPWAIT_WAIT_FOREVER))
569 {
570 DBG("Can not wait for a server");
571 goto close_pipe;
572 }
573 }
574
575 svr->path = buf;
576 buf = NULL;
577
578 svr->event_read = CreateEvent(NULL, TRUE, FALSE, NULL);
579 if (!svr->event_read)
580 {
581 ERR("Can not create event read");
582 goto free_path;
583 }
584
585 handler_read = ecore_main_win32_handler_add(svr->event_read,
586 _ecore_con_local_win32_client_read_server_handler,
587 obj);
588 if (!handler_read)
589 {
590 ERR("Can not create handler read");
591 goto close_event_read;
592 }
593
594 svr->event_peek = CreateEvent(NULL, TRUE, FALSE, NULL);
595 if (!svr->event_peek)
596 {
597 ERR("Can not create event peek");
598 goto del_handler_read;
599 }
600
601 handler_peek = ecore_main_win32_handler_add(svr->event_peek,
602 _ecore_con_local_win32_client_peek_server_handler,
603 obj);
604 if (!handler_peek)
605 {
606 ERR("Can not create handler peek");
607 goto close_event_peek;
608 }
609
610 svr->thread_read = (HANDLE)_beginthreadex(NULL, 0, _ecore_con_local_win32_client_read_server_thread, obj, CREATE_SUSPENDED, NULL);
611 if (!svr->thread_read)
612 {
613 ERR("Can not launch thread");
614 goto del_handler_peek;
615 }
616
617 if (!svr->delete_me) ecore_con_event_server_add(obj);
618
619 ResumeThread(svr->thread_read);
620 free(buf);
621
622 return EINA_TRUE;
623
624 del_handler_peek:
625 ecore_main_win32_handler_del(handler_peek);
626 close_event_peek:
627 CloseHandle(svr->event_peek);
628 del_handler_read:
629 ecore_main_win32_handler_del(handler_read);
630 close_event_read:
631 CloseHandle(svr->event_read);
632 free_path:
633 free(svr->path);
634 svr->path = NULL;
635 close_pipe:
636 CloseHandle(svr->pipe);
637 free(buf);
638
639 return EINA_FALSE;
640 }
641
642 Eina_Bool
ecore_con_local_win32_server_flush(Ecore_Con_Server * obj)643 ecore_con_local_win32_server_flush(Ecore_Con_Server *obj)
644 {
645 Efl_Network_Server_Data *svr = efl_data_scope_get(obj, EFL_NETWORK_SERVER_CLASS);
646 size_t num;
647 BOOL res;
648 DWORD written;
649
650 /* This check should never be true */
651 if ((svr->type & ECORE_CON_TYPE) == ECORE_CON_LOCAL_ABSTRACT)
652 return EINA_TRUE;
653
654 if (((svr->type & ECORE_CON_TYPE) != ECORE_CON_LOCAL_USER) &&
655 ((svr->type & ECORE_CON_TYPE) != ECORE_CON_LOCAL_SYSTEM))
656 return EINA_FALSE;
657
658 num = eina_binbuf_length_get(svr->buf) - svr->write_buf_offset;
659 if (num == 0) return EINA_TRUE;
660
661 res = WriteFile(svr->pipe, eina_binbuf_string_get(svr->buf) + svr->write_buf_offset, num, &written, NULL);
662 if (!res)
663 {
664 ecore_con_event_server_error(obj, evil_last_error_get());
665 _ecore_con_server_kill(obj);
666 }
667
668 svr->write_buf_offset += written;
669 if (svr->write_buf_offset >= eina_binbuf_length_get(svr->buf))
670 {
671 svr->write_buf_offset = 0;
672 eina_binbuf_free(svr->buf);
673 svr->buf = NULL;
674 svr->want_write = 0;
675 }
676 else if (written < (DWORD)num)
677 svr->want_write = 1;
678
679 return EINA_TRUE;
680 }
681
682 Eina_Bool
ecore_con_local_win32_client_flush(Ecore_Con_Client * obj)683 ecore_con_local_win32_client_flush(Ecore_Con_Client *obj)
684 {
685 Efl_Network_Client_Data *cl = efl_data_scope_get(obj, EFL_NETWORK_CLIENT_CLASS);
686 Ecore_Con_Type type;
687 size_t num;
688 BOOL res;
689 DWORD written;
690 Efl_Network_Server_Data *svr = efl_data_scope_get(cl->host_server, EFL_NETWORK_SERVER_CLASS);
691
692 type = svr->type & ECORE_CON_TYPE;
693
694 /* This check should never be true */
695 if (type == ECORE_CON_LOCAL_ABSTRACT)
696 return EINA_TRUE;
697
698 if ((type != ECORE_CON_LOCAL_USER) &&
699 (type != ECORE_CON_LOCAL_SYSTEM))
700 return EINA_FALSE;
701
702 num = eina_binbuf_length_get(cl->buf) - cl->buf_offset;
703 if (num == 0) return EINA_TRUE;
704
705 res = WriteFile(svr->pipe, eina_binbuf_string_get(cl->buf) + cl->buf_offset, num, &written, NULL);
706 if (!res)
707 {
708 ecore_con_event_client_error(obj, evil_last_error_get());
709 _ecore_con_client_kill(obj);
710 }
711
712 cl->buf_offset += written;
713 if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
714 {
715 cl->buf_offset = 0;
716 eina_binbuf_free(cl->buf);
717 cl->buf = NULL;
718 svr->want_write = 0;
719 }
720 else if (written < (DWORD)num)
721 svr->want_write = 1;
722
723 return EINA_TRUE;
724 }
725
726