add ECORE_CON_EVENT_SERVER_WRITE ECORE_CON_EVENT_CLIENT_WRITE
authordiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 13 Sep 2011 23:03:26 +0000 (23:03 +0000)
committerdiscomfitor <discomfitor@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 13 Sep 2011 23:03:26 +0000 (23:03 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/ecore@63364 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

ChangeLog
src/lib/ecore_con/Ecore_Con.h
src/lib/ecore_con/ecore_con.c

index 87d5b96..c6be25d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
 
         * Add ecore_con_server_fd_get, ecore_con_client_fd_get for manipulating
           server file descriptors.
+
+2011-09-13  Mike Blumenkrantz
+
+        * Add ECORE_CON_EVENT_CLIENT_WRITE, ECORE_CON_EVENT_SERVER_WRITE for
+          obtaining progress of socket writes
index 2dff134..eb30f96 100644 (file)
@@ -311,6 +311,20 @@ typedef struct _Ecore_Con_Event_Client_Data Ecore_Con_Event_Client_Data;
 typedef struct _Ecore_Con_Event_Server_Data Ecore_Con_Event_Server_Data;
 
 /**
+ * @typedef Ecore_Con_Event_Client_Write
+ * Used as the @p data param for the corresponding event
+ * @since 1.1
+ */
+typedef struct _Ecore_Con_Event_Client_Write Ecore_Con_Event_Client_Write;
+
+/**
+ * @typedef Ecore_Con_Event_Server_Write
+ * Used as the @p data param for the corresponding event
+ * @since 1.1
+ */
+typedef struct _Ecore_Con_Event_Server_Write Ecore_Con_Event_Server_Write;
+
+/**
  * @typedef Ecore_Con_Event_Url_Data
  * Used as the @p data param for the corresponding event
  * @ingroup Ecore_Con_Url_Group
@@ -430,6 +444,26 @@ struct _Ecore_Con_Event_Server_Data
 };
 
 /**
+ * @struct _Ecore_Con_Event_Client_Write
+ * Used as the @p data param for the @ref ECORE_CON_EVENT_CLIENT_WRITE event
+ */
+struct _Ecore_Con_Event_Client_Write
+{
+   Ecore_Con_Client *client; /**< the client that connected */
+   int size;                 /**< the length of the data sent */
+};
+
+/**
+ * @struct _Ecore_Con_Event_Server_Write
+ * Used as the @p data param for the @ref ECORE_CON_EVENT_SERVER_WRITE event
+ */
+struct _Ecore_Con_Event_Server_Write
+{
+   Ecore_Con_Server *server; /**< the server that was connected to */
+   int size;                 /**< the length of the data sent */
+};
+
+/**
  * @struct _Ecore_Con_Event_Url_Data
  * Used as the @p data param for the @ref ECORE_CON_EVENT_URL_DATA event
  * @ingroup Ecore_Con_Url_Group
@@ -492,6 +526,14 @@ EAPI extern int ECORE_CON_EVENT_SERVER_ERROR;
  * @since 1.1
  */
 EAPI extern int ECORE_CON_EVENT_SERVER_UPGRADE;
+/** A server connection has sent data to its client
+ * @since 1.1
+ */
+EAPI extern int ECORE_CON_EVENT_CLIENT_WRITE;
+/** A server connection object has sent data
+ * @since 1.1
+ */
+EAPI extern int ECORE_CON_EVENT_SERVER_WRITE;
 /** A client connected to the server has sent data */
 EAPI extern int ECORE_CON_EVENT_CLIENT_DATA;
 /** A server connection object has data */
index 0d2657e..221368e 100644 (file)
@@ -94,6 +94,10 @@ static void _ecore_con_event_server_error_free(void *data,
                                                Ecore_Con_Event_Server_Error *e);
 static void _ecore_con_event_client_error_free(Ecore_Con_Server *svr,
                                                Ecore_Con_Event_Client_Error *e);
+static void _ecore_con_event_server_write_free(void *data,
+                                               Ecore_Con_Event_Server_Write *e);
+static void _ecore_con_event_client_write_free(Ecore_Con_Server *svr,
+                                               Ecore_Con_Event_Client_Write *e);
 
 static void _ecore_con_lookup_done(void           *data,
                                    Ecore_Con_Info *infos);
@@ -108,6 +112,8 @@ EAPI int ECORE_CON_EVENT_SERVER_ADD = 0;
 EAPI int ECORE_CON_EVENT_SERVER_DEL = 0;
 EAPI int ECORE_CON_EVENT_CLIENT_DATA = 0;
 EAPI int ECORE_CON_EVENT_SERVER_DATA = 0;
+EAPI int ECORE_CON_EVENT_CLIENT_WRITE = 0;
+EAPI int ECORE_CON_EVENT_SERVER_WRITE = 0;
 EAPI int ECORE_CON_EVENT_CLIENT_ERROR = 0;
 EAPI int ECORE_CON_EVENT_SERVER_ERROR = 0;
 
@@ -145,6 +151,8 @@ ecore_con_init(void)
    ECORE_CON_EVENT_SERVER_DEL = ecore_event_type_new();
    ECORE_CON_EVENT_CLIENT_DATA = ecore_event_type_new();
    ECORE_CON_EVENT_SERVER_DATA = ecore_event_type_new();
+   ECORE_CON_EVENT_CLIENT_WRITE = ecore_event_type_new();
+   ECORE_CON_EVENT_SERVER_WRITE = ecore_event_type_new();
    ECORE_CON_EVENT_CLIENT_ERROR = ecore_event_type_new();
    ECORE_CON_EVENT_SERVER_ERROR = ecore_event_type_new();
 
@@ -949,6 +957,22 @@ ecore_con_event_server_del(Ecore_Con_Server *svr)
 }
 
 void
+ecore_con_event_server_write(Ecore_Con_Server *svr, int num)
+{
+   Ecore_Con_Event_Server_Write *e;
+
+   e = malloc(sizeof(Ecore_Con_Event_Server_Write));
+   EINA_SAFETY_ON_NULL_RETURN(e);
+
+   svr->event_count++;
+   e->server = svr;
+   e->size = num;
+   ecore_event_add(ECORE_CON_EVENT_SERVER_WRITE, e,
+                   (Ecore_End_Cb)_ecore_con_event_server_write_free, NULL);
+
+}
+
+void
 ecore_con_event_server_data(Ecore_Con_Server *svr, unsigned char *buf, int num, Eina_Bool duplicate)
 {
    Ecore_Con_Event_Server_Data *e;
@@ -1016,6 +1040,21 @@ ecore_con_event_client_del(Ecore_Con_Client *cl)
 }
 
 void
+ecore_con_event_client_write(Ecore_Con_Client *cl, int num)
+{
+   Ecore_Con_Event_Client_Write *e;
+   e = malloc(sizeof(Ecore_Con_Event_Client_Write));
+   EINA_SAFETY_ON_NULL_RETURN(e);
+
+   cl->host_server->event_count++;
+   cl->event_count++;
+   e->client = cl;
+   e->size = num;
+   ecore_event_add(ECORE_CON_EVENT_CLIENT_WRITE, e,
+                   (Ecore_End_Cb)_ecore_con_event_client_write_free, cl->host_server);
+}
+
+void
 ecore_con_event_client_data(Ecore_Con_Client *cl, unsigned char *buf, int num, Eina_Bool duplicate)
 {
    Ecore_Con_Event_Client_Data *e;
@@ -2198,6 +2237,7 @@ _ecore_con_server_flush(Ecore_Con_Server *svr)
          return;
      }
 
+   if (count) ecore_con_event_server_write(svr, count);
    svr->write_buf_offset += count;
    if (svr->write_buf_offset >= eina_binbuf_length_get(svr->buf))
      {
@@ -2262,6 +2302,7 @@ _ecore_con_client_flush(Ecore_Con_Client *cl)
         return;
      }
 
+   if (count) ecore_con_event_client_write(cl, count);
    cl->buf_offset += count;
    if (cl->buf_offset >= eina_binbuf_length_get(cl->buf))
      {
@@ -2312,6 +2353,24 @@ _ecore_con_event_client_del_free(Ecore_Con_Server *svr,
 }
 
 static void
+_ecore_con_event_client_write_free(Ecore_Con_Server *svr,
+                                   Ecore_Con_Event_Client_Write *e)
+{
+   e->client->event_count--;
+   e->client->host_server->event_count--;
+
+   if (((e->client->event_count <= 0) && (e->client->delete_me)) ||
+       ((e->client->host_server &&
+         ((e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_UDP ||
+          (e->client->host_server->type & ECORE_CON_TYPE) == ECORE_CON_REMOTE_MCAST))))
+     ecore_con_client_del(e->client);
+   if ((svr->event_count <= 0) && (svr->delete_me))
+     _ecore_con_server_free(svr);
+
+   free(e);
+}
+
+static void
 _ecore_con_event_client_data_free(Ecore_Con_Server *svr,
                                   void      *ev)
 {
@@ -2363,6 +2422,18 @@ _ecore_con_event_server_del_free(void *data __UNUSED__,
 }
 
 static void
+_ecore_con_event_server_write_free(void *data __UNUSED__,
+                                   Ecore_Con_Event_Server_Write *e)
+{
+   e->server->event_count--;
+
+   if ((e->server->event_count <= 0) && (e->server->delete_me))
+     _ecore_con_server_free(e->server);
+
+   free(e);
+}
+
+static void
 _ecore_con_event_server_data_free(void *data __UNUSED__,
                                   void      *ev)
 {