diff options
| author | Vijay Bellur <vijay@gluster.com> | 2009-06-24 12:54:51 +0000 | 
|---|---|---|
| committer | Anand V. Avati <avati@dev.gluster.com> | 2009-06-24 17:13:36 -0700 | 
| commit | 7a797746b9276493a0891da63124092ddc98f01b (patch) | |
| tree | f5c437e61bad10e5355653f80629beb2e625dd64 | |
| parent | 992130efe4d74dd0b69b8e899c620e5dd4786856 (diff) | |
Added a new option transport.socket.nodelay.
Release 2.0 compatible patch for optionally setting NODELAY.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
| -rw-r--r-- | transport/socket/src/socket.c | 50 | ||||
| -rw-r--r-- | transport/socket/src/socket.h | 1 | 
2 files changed, 51 insertions, 0 deletions
diff --git a/transport/socket/src/socket.c b/transport/socket/src/socket.c index 65c17763d..cae6fb1d8 100644 --- a/transport/socket/src/socket.c +++ b/transport/socket/src/socket.c @@ -34,6 +34,7 @@  #include "compat-errno.h"  #include <fcntl.h> +#include <netinet/tcp.h>  #include <errno.h> @@ -945,6 +946,7 @@ socket_connect (transport_t *this)          struct sockaddr_storage  sockaddr = {0, };          socklen_t                sockaddr_len = 0;  	glusterfs_ctx_t         *ctx = NULL; +        int                      on = 1;          priv = this->private;  	ctx = this->xl->ctx; @@ -1017,6 +1019,18 @@ socket_connect (transport_t *this)                                  strerror (errno));                  } +	 +                if (priv->nodelay) { +                        ret = setsockopt(priv->sock, IPPROTO_TCP,  +                                         TCP_NODELAY, &on, sizeof(on)); +                        if (ret == -1) { +                                gf_log (this->xl->name, GF_LOG_ERROR, +                                        "setsockopt() failed for NODELAY (%s)", +                                        strerror (errno)); +                        } +                } + +                  if (!priv->bio) {                          ret = __socket_nonblock (priv->sock); @@ -1082,6 +1096,7 @@ socket_listen (transport_t *this)          socklen_t                sockaddr_len;          peer_info_t             *myinfo = NULL;  	glusterfs_ctx_t         *ctx = NULL; +        int                      on = 1;  	priv   = this->private;  	myinfo = &this->myinfo; @@ -1148,6 +1163,18 @@ socket_listen (transport_t *this)                                  strerror (errno));                  } + +                if (priv->nodelay) { +                        ret = setsockopt(priv->sock, IPPROTO_TCP,  +                                         TCP_NODELAY, &on, sizeof(on)); + +                        if (ret == -1) { +                                gf_log (this->xl->name, GF_LOG_ERROR, +                                        "setsockopt() failed for NODELAY (%s)", +                                        strerror (errno)); +                        } +                } +                  if (!priv->bio) {                          ret = __socket_nonblock (priv->sock); @@ -1321,6 +1348,7 @@ socket_init (transport_t *this)          socket_private_t *priv = NULL;          gf_boolean_t      tmp_bool = 0;          char             *nb_connect = NULL; +        char             *optstr     = NULL;          uint64_t          windowsize = GF_DEFAULT_SOCKET_WINDOW_SIZE;          char             *wsizestr = NULL; @@ -1364,6 +1392,25 @@ socket_init (transport_t *this)                  }          } +        if (dict_get (this->xl->options, "transport.socket.nodelay")) { +                optstr = data_to_str (dict_get (this->xl->options, +                                                "transport.socket.nodelay")); +        +                if (gf_string2boolean (optstr, &tmp_bool) == -1) { +                        gf_log (this->xl->name, GF_LOG_ERROR, +                                "'transport.socket.nodelay' takes only " +                                 "boolean options, not taking any action"); +                        tmp_bool = 0; +                } +                // By default we do not enable NODELAY +                priv->nodelay = 0; +                if (tmp_bool) { +                        priv->nodelay = 1; +                        gf_log (this->xl->name, GF_LOG_DEBUG, +                                "enabling nodelay"); +                } +        } +           if (dict_get_str (this->xl->options, "window-size", &wsizestr) == 0) {                  if (gf_string2bytesize (wsizestr, &windowsize) != 0) {                          gf_log (this->xl->name, GF_LOG_ERROR, @@ -1437,6 +1484,9 @@ struct volume_options options[] = {            .min   = GF_MIN_SOCKET_WINDOW_SIZE,            .max   = GF_MAX_SOCKET_WINDOW_SIZE,          }, +        { .key   = {"transport.socket.nodelay"},  +          .type  = GF_OPTION_TYPE_BOOL +        },          { .key = {NULL} }  }; diff --git a/transport/socket/src/socket.h b/transport/socket/src/socket.h index 50d7d0303..27640ea83 100644 --- a/transport/socket/src/socket.h +++ b/transport/socket/src/socket.h @@ -94,6 +94,7 @@ typedef struct {          char                   bio;          char                   connect_finish_log;          char                   submit_log; +        char                   nodelay;          union {                  struct list_head     ioq;                  struct {  | 
