* ecore_con: Add support for TCP_NODELAY.
authorcedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 20 Nov 2009 10:58:19 +0000 (10:58 +0000)
committercedric <cedric@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Fri, 20 Nov 2009 10:58:19 +0000 (10:58 +0000)
git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/ecore@43818 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

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

index a62a36e..020de4e 100644 (file)
@@ -86,6 +86,7 @@ extern "C" {
        ECORE_CON_REMOTE_MCAST,
        ECORE_CON_REMOTE_UDP,
        ECORE_CON_REMOTE_BROADCAST,
+       ECORE_CON_REMOTE_NODELAY,
        ECORE_CON_USE_SSL2 = (1 << 4),
        ECORE_CON_USE_SSL3 = (1 << 5),
        ECORE_CON_USE_TLS  = (1 << 6)
index e119ac3..2c2b1df 100644 (file)
@@ -6,8 +6,10 @@
 # include <config.h>
 #endif
 
+#include <sys/types.h>
 #include <sys/stat.h>
 #include <arpa/inet.h>
+#include <netinet/tcp.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <errno.h>
@@ -278,7 +280,7 @@ ecore_con_server_add(Ecore_Con_Type compl_type, const char *name, int port,
        if (!svr->fd_handler) goto error;
      }
 
-   if (type == ECORE_CON_REMOTE_TCP)
+   if (type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_NODELAY)
      {
         /* TCP */
         if (!ecore_con_info_tcp_listen(svr, _ecore_con_cb_tcp_listen, svr)) goto error;
@@ -365,7 +367,8 @@ ecore_con_server_connect(Ecore_Con_Type compl_type, const char *name, int port,
 
    type = compl_type & ECORE_CON_TYPE;
 
-   if ((type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_UDP || ECORE_CON_REMOTE_BROADCAST) && (port < 0)) return NULL;
+   if ((type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_NODELAY
+       || type == ECORE_CON_REMOTE_UDP || ECORE_CON_REMOTE_BROADCAST) && (port < 0)) return NULL;
 
    if ((type == ECORE_CON_LOCAL_USER) || (type == ECORE_CON_LOCAL_SYSTEM) ||
        (type == ECORE_CON_LOCAL_ABSTRACT))
@@ -456,7 +459,7 @@ ecore_con_server_connect(Ecore_Con_Type compl_type, const char *name, int port,
          }
      }
 
-   if (type == ECORE_CON_REMOTE_TCP)
+   if (type == ECORE_CON_REMOTE_TCP || type == ECORE_CON_REMOTE_NODELAY)
      {
         /* TCP */
         if (!ecore_con_info_tcp_connect(svr, _ecore_con_cb_tcp_connect, svr)) goto error;
@@ -972,6 +975,13 @@ _ecore_con_cb_tcp_listen(void *data, Ecore_Con_Info *net_info)
    lin.l_onoff = 1;
    lin.l_linger = 0;
    if (setsockopt(svr->fd, SOL_SOCKET, SO_LINGER, &lin, sizeof(struct linger)) < 0) goto error;
+   if (svr->type == ECORE_CON_REMOTE_NODELAY)
+     {
+       int flag = 1;
+
+       if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) < 0)
+         goto error;
+     }
    if (bind(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0) goto error;
    if (listen(svr->fd, 4096) < 0) goto error;
    svr->fd_handler =
@@ -1052,6 +1062,13 @@ _ecore_con_cb_tcp_connect(void *data, Ecore_Con_Info *net_info)
    if (fcntl(svr->fd, F_SETFD, FD_CLOEXEC) < 0) goto error;
    if (setsockopt(svr->fd, SOL_SOCKET, SO_REUSEADDR, &curstate, sizeof(curstate)) < 0)
      goto error;
+   if (svr->type == ECORE_CON_REMOTE_NODELAY)
+     {
+       int flag = 1;
+
+       if (setsockopt(svr->fd, IPPROTO_TCP, TCP_NODELAY, (char *) &flag, sizeof(int)) < 0)
+         goto error;
+     }
    if (connect(svr->fd, net_info->info.ai_addr, net_info->info.ai_addrlen) < 0)
      {
        if (errno != EINPROGRESS)