moonbridge

changeset 124:61a2f55b3538

Do not announce socket/listener type when communicating with the child process
(unnecessary because pointer to listener struct is passed)
author jbe
date Sun Apr 12 00:33:08 2015 +0200 (2015-04-12)
parents 20e0d4f51381
children d9cc81641175
files moonbridge.c
line diff
     1.1 --- a/moonbridge.c	Sat Apr 11 00:20:33 2015 +0200
     1.2 +++ b/moonbridge.c	Sun Apr 12 00:33:08 2015 +0200
     1.3 @@ -97,12 +97,10 @@
     1.4  #define MOONBR_MAXSTRERRORLEN 80
     1.5  
     1.6  /* Status bytes exchanged between master and child processes */
     1.7 -#define MOONBR_SOCKETTYPE_INTERVAL 'I'
     1.8 -#define MOONBR_SOCKETTYPE_LOCAL 'L'
     1.9 -#define MOONBR_SOCKETTYPE_NETWORK 'N'
    1.10 -#define MOONBR_STATUS_IDLE '1'
    1.11 -#define MOONBR_COMMAND_TERMINATE '2'
    1.12 -#define MOONBR_STATUS_GOODBYE '3'
    1.13 +#define MOONBR_STATUS_IDLE 'I'
    1.14 +#define MOONBR_COMMAND_CONNECT 'C'
    1.15 +#define MOONBR_COMMAND_TERMINATE 'T'
    1.16 +#define MOONBR_STATUS_GOODBYE 'B'
    1.17  
    1.18  /* Constant file descriptors */
    1.19  #define MOONBR_FD_STDERR 2
    1.20 @@ -832,15 +830,18 @@
    1.21      }
    1.22      moonbr_child_receive_control_message(MOONBR_FD_CONTROL, &controlmsg, &fd);
    1.23      if (!(
    1.24 -      (controlmsg == MOONBR_COMMAND_TERMINATE   && fd == -1) ||
    1.25 -      (controlmsg == MOONBR_SOCKETTYPE_INTERVAL && fd == -1) ||
    1.26 -      (controlmsg == MOONBR_SOCKETTYPE_LOCAL    && fd != -1) ||
    1.27 -      (controlmsg == MOONBR_SOCKETTYPE_NETWORK  && fd != -1)
    1.28 +      (controlmsg == MOONBR_COMMAND_TERMINATE && fd == -1) ||
    1.29 +      (controlmsg == MOONBR_COMMAND_CONNECT)
    1.30      )) {
    1.31        moonbr_child_log_fatal("Received illegal control message from parent process");
    1.32      }
    1.33      if (controlmsg == MOONBR_COMMAND_TERMINATE) break;
    1.34      listener = moonbr_child_receive_pointer(MOONBR_FD_CONTROL);
    1.35 +    if (listener->proto == MOONBR_PROTO_INTERVAL && fd >= 0) {
    1.36 +      moonbr_child_log_fatal("Received unexpected file descriptor from parent process");
    1.37 +    } else if (listener->proto != MOONBR_PROTO_INTERVAL && fd < 0) {
    1.38 +      moonbr_child_log_fatal("Missing file descriptor from parent process");
    1.39 +    }
    1.40      if (fd >= 0) moonbr_io_pushhandle(L, fd);
    1.41      lua_rawgetp(L, LUA_REGISTRYINDEX, moonbr_luakey_connect_func(pool));
    1.42      if (fd < 0) {
    1.43 @@ -1468,7 +1469,7 @@
    1.44        moonbr_log(LOG_INFO, "Dispatching interval timer \"%s\" of pool #%i to PID %i", listener->proto_specific.interval.name, listener->pool->poolnum, (int)worker->pid);
    1.45      }
    1.46      worker->restart_interval_listener = listener;
    1.47 -    moonbr_send_control_message(worker, MOONBR_SOCKETTYPE_INTERVAL, -1, listener);
    1.48 +    moonbr_send_control_message(worker, MOONBR_COMMAND_CONNECT, -1, listener);
    1.49      /* do not push listener to queue of idle listeners yet */
    1.50      break;
    1.51    case MOONBR_PROTO_LOCAL:
    1.52 @@ -1497,7 +1498,7 @@
    1.53          if (moonbr_stat) {
    1.54            moonbr_log(LOG_INFO, "Dispatching local socket connection on path \"%s\" for pool #%i to PID %i", listener->proto_specific.local.path, listener->pool->poolnum, (int)worker->pid);
    1.55          }
    1.56 -        moonbr_send_control_message(worker, MOONBR_SOCKETTYPE_LOCAL, peerfd, listener);
    1.57 +        moonbr_send_control_message(worker, MOONBR_COMMAND_CONNECT, peerfd, listener);
    1.58          if (close(peerfd) && errno != EINTR) {
    1.59            moonbr_log(LOG_ERR, "Could not close incoming socket connection in parent process: %s", strerror(errno));
    1.60            moonbr_terminate_error();
    1.61 @@ -1532,7 +1533,7 @@
    1.62          if (moonbr_stat) {
    1.63            moonbr_log(LOG_INFO, "Dispatching TCP/IPv6 connection for pool #%i on port %i to PID %i", listener->pool->poolnum, listener->proto_specific.tcp.port, (int)worker->pid);
    1.64          }
    1.65 -        moonbr_send_control_message(worker, MOONBR_SOCKETTYPE_NETWORK, peerfd, listener);
    1.66 +        moonbr_send_control_message(worker, MOONBR_COMMAND_CONNECT, peerfd, listener);
    1.67          if (close(peerfd) && errno != EINTR) {
    1.68            moonbr_log(LOG_ERR, "Could not close incoming socket connection in parent process: %s", strerror(errno));
    1.69            moonbr_terminate_error();
    1.70 @@ -1567,7 +1568,7 @@
    1.71          if (moonbr_stat) {
    1.72            moonbr_log(LOG_INFO, "Dispatching TCP/IPv4 connection for pool #%i on port %i to PID %i", listener->pool->poolnum, listener->proto_specific.tcp.port, (int)worker->pid);
    1.73          }
    1.74 -        moonbr_send_control_message(worker, MOONBR_SOCKETTYPE_NETWORK, peerfd, listener);
    1.75 +        moonbr_send_control_message(worker, MOONBR_COMMAND_CONNECT, peerfd, listener);
    1.76          if (close(peerfd) && errno != EINTR) {
    1.77            moonbr_log(LOG_ERR, "Could not close incoming socket connection in parent process: %s", strerror(errno));
    1.78            moonbr_terminate_error();

Impressum / About Us