Changeset 4dd8a488802d75bd0661c3e90912b84d7cf3bf7b

Show
Ignore:
Timestamp:
09/25/09 13:44:24 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253886264 +0000
git-parent:

[643d55510eb48b83ce36de906c7f703b857f07b4]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1253886264 +0000
Message:

Add TCP KEEPALIVE to the outbound jlog connections (fix display errors on the noit statistics due to inplace ntohl() calls. refs #58

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/stratcon_jlog_streamer.c

    r7666f79 r4dd8a48  
    301301  noit_connection_ctx_t *nctx = closure; 
    302302  jlog_streamer_ctx_t *ctx = nctx->consumer_ctx; 
     303  jlog_streamer_ctx_t dummy; 
    303304  int len; 
    304305  jlog_id n_chkpt; 
     
    340341      case JLOG_STREAMER_WANT_COUNT: 
    341342        FULLREAD(e, ctx, sizeof(u_int32_t)); 
    342         memcpy(&ctx->count, ctx->buffer, sizeof(u_int32_t)); 
    343         ctx->count = ntohl(ctx->count); 
     343        memcpy(&dummy.count, ctx->buffer, sizeof(u_int32_t)); 
     344        ctx->count = ntohl(dummy.count); 
    344345        free(ctx->buffer); ctx->buffer = NULL; 
    345346        ctx->state = JLOG_STREAMER_WANT_HEADER; 
     
    352353        } 
    353354        FULLREAD(e, ctx, sizeof(ctx->header)); 
    354         memcpy(&ctx->header, ctx->buffer, sizeof(ctx->header)); 
    355         ctx->header.chkpt.log = ntohl(ctx->header.chkpt.log); 
    356         ctx->header.chkpt.marker = ntohl(ctx->header.chkpt.marker); 
    357         ctx->header.tv_sec = ntohl(ctx->header.tv_sec); 
    358         ctx->header.tv_usec = ntohl(ctx->header.tv_usec); 
    359         ctx->header.message_len = ntohl(ctx->header.message_len); 
     355        memcpy(&dummy.header, ctx->buffer, sizeof(ctx->header)); 
     356        ctx->header.chkpt.log = ntohl(dummy.header.chkpt.log); 
     357        ctx->header.chkpt.marker = ntohl(dummy.header.chkpt.marker); 
     358        ctx->header.tv_sec = ntohl(dummy.header.tv_sec); 
     359        ctx->header.tv_usec = ntohl(dummy.header.tv_usec); 
     360        ctx->header.message_len = ntohl(dummy.header.message_len); 
    360361        free(ctx->buffer); ctx->buffer = NULL; 
    361362        ctx->state = JLOG_STREAMER_WANT_BODY; 
     
    517518  eventer_t e; 
    518519  int rv, fd = -1; 
     520#ifdef SO_KEEPALIVE 
     521  int optval; 
     522  socklen_t optlen = sizeof(optval); 
     523#endif 
    519524 
    520525  if(nctx->wants_permanent_shutdown) { 
     
    528533  /* Make it non-blocking */ 
    529534  if(eventer_set_fd_nonblocking(fd)) goto reschedule; 
     535#define set_or_bail(type, opt, val) do { \ 
     536  optval = val; \ 
     537  optlen = sizeof(optval); \ 
     538  if(setsockopt(fd, type, opt, &optval, optlen) < 0) { \ 
     539    noitL(noit_error, "Cannot set " #type "/" #opt " on jlog socket: %s\n", \ 
     540          strerror(errno)); \ 
     541    goto reschedule; \ 
     542  } \ 
     543} while(0) 
     544#ifdef SO_KEEPALIVE 
     545  set_or_bail(SOL_SOCKET, SO_KEEPALIVE, 1); 
     546#endif 
     547#ifdef TCP_KEEPALIVE_THRESHOLD 
     548  set_or_bail(IPPROTO_TCP, TCP_KEEPALIVE_THRESHOLD, 10 * 1000); 
     549#endif 
     550#ifdef TCP_KEEPALIVE_ABORT_THRESHOLD 
     551  set_or_bail(IPPROTO_TCP, TCP_KEEPALIVE_ABORT_THRESHOLD, 30 * 1000); 
     552#endif 
     553#ifdef TCP_CONN_NOTIFY_THRESHOLD 
     554  set_or_bail(IPPROTO_TCP, TCP_CONN_NOTIFY_THRESHOLD, 10 * 1000); 
     555#endif 
     556#ifdef TCP_CONN_ABORT_THRESHOLD 
     557  set_or_bail(IPPROTO_TCP, TCP_CONN_ABORT_THRESHOLD, 30 * 1000); 
     558#endif 
    530559 
    531560  /* Initiate a connection */