summaryrefslogtreecommitdiff
path: root/src/lib/ecore/efl_io_buffered_stream.c
diff options
context:
space:
mode:
authorGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-12-07 17:39:01 -0200
committerGustavo Sverzut Barbieri <barbieri@profusion.mobi>2016-12-08 11:40:45 -0200
commit994d66513f69b2feb506970d6e6fb7d204cb8f1e (patch)
tree54a424f206b3a3282f4fbd47948557ec3db37a4a /src/lib/ecore/efl_io_buffered_stream.c
parentc33ed61e1735020953b67f1049c11cedd51950dc (diff)
efl_io_buffered_stream: better detection of 'finished' state.
When used with sockets, if it's EOS (ie: remote peer terminated the connection), but not closed, then it would not emit 'finished' event. Now it does.
Diffstat (limited to '')
-rw-r--r--src/lib/ecore/efl_io_buffered_stream.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/lib/ecore/efl_io_buffered_stream.c b/src/lib/ecore/efl_io_buffered_stream.c
index 69ea69c35e..6d58e67395 100644
--- a/src/lib/ecore/efl_io_buffered_stream.c
+++ b/src/lib/ecore/efl_io_buffered_stream.c
@@ -21,6 +21,7 @@ typedef struct
21 Eina_Bool can_read; 21 Eina_Bool can_read;
22 Eina_Bool can_write; 22 Eina_Bool can_write;
23 Eina_Bool is_closer; 23 Eina_Bool is_closer;
24 Eina_Bool is_finished;
24} Efl_Io_Buffered_Stream_Data; 25} Efl_Io_Buffered_Stream_Data;
25 26
26#define MY_CLASS EFL_IO_BUFFERED_STREAM_CLASS 27#define MY_CLASS EFL_IO_BUFFERED_STREAM_CLASS
@@ -98,11 +99,21 @@ _efl_io_buffered_stream_sender_done(void *data, const Efl_Event *event EINA_UNUS
98{ 99{
99 Eo *o = data; 100 Eo *o = data;
100 Efl_Io_Buffered_Stream_Data *pd = efl_data_scope_get(o, MY_CLASS); 101 Efl_Io_Buffered_Stream_Data *pd = efl_data_scope_get(o, MY_CLASS);
102 size_t pending = pd->receiver ? efl_io_copier_pending_size_get(pd->receiver) : 0;
103
101 efl_ref(o); 104 efl_ref(o);
102 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL); 105 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL);
103 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_WRITE_FINISHED, NULL); 106 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_WRITE_FINISHED, NULL);
104 if (efl_io_copier_done_get(pd->receiver)) 107 if ((pending == 0) || efl_io_copier_done_get(pd->receiver))
105 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, NULL); 108 {
109 if (!pd->is_finished)
110 {
111 pd->is_finished = EINA_TRUE;
112 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, NULL);
113 }
114 }
115 else
116 DBG("%p sender done, waiting for receiver to process %zd to call it 'finished'", o, pending);
106 efl_unref(o); 117 efl_unref(o);
107} 118}
108 119
@@ -269,6 +280,8 @@ _efl_io_buffered_stream_efl_io_reader_eos_get(Eo *o EINA_UNUSED, Efl_Io_Buffered
269EOLIAN static void 280EOLIAN static void
270_efl_io_buffered_stream_efl_io_reader_eos_set(Eo *o, Efl_Io_Buffered_Stream_Data *pd, Eina_Bool is_eos) 281_efl_io_buffered_stream_efl_io_reader_eos_set(Eo *o, Efl_Io_Buffered_Stream_Data *pd, Eina_Bool is_eos)
271{ 282{
283 size_t pending = pd->sender ? efl_io_copier_pending_size_get(pd->sender) : 0;
284
272 EINA_SAFETY_ON_TRUE_RETURN(efl_io_closer_closed_get(o)); 285 EINA_SAFETY_ON_TRUE_RETURN(efl_io_closer_closed_get(o));
273 if (pd->eos == is_eos) return; 286 if (pd->eos == is_eos) return;
274 pd->eos = is_eos; 287 pd->eos = is_eos;
@@ -278,8 +291,16 @@ _efl_io_buffered_stream_efl_io_reader_eos_set(Eo *o, Efl_Io_Buffered_Stream_Data
278 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL); 291 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_PROGRESS, NULL);
279 efl_event_callback_call(o, EFL_IO_READER_EVENT_EOS, NULL); 292 efl_event_callback_call(o, EFL_IO_READER_EVENT_EOS, NULL);
280 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_READ_FINISHED, NULL); 293 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_READ_FINISHED, NULL);
281 if (efl_io_copier_done_get(pd->sender)) 294 if ((pending == 0) || efl_io_copier_done_get(pd->sender))
282 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, NULL); 295 {
296 if (!pd->is_finished)
297 {
298 pd->is_finished = EINA_TRUE;
299 efl_event_callback_call(o, EFL_IO_BUFFERED_STREAM_EVENT_FINISHED, NULL);
300 }
301 }
302 else
303 DBG("%p eos, waiting for sender process %zd to call 'finished'", o, pending);
283 efl_unref(o); 304 efl_unref(o);
284} 305}
285 306