IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 32583


Ignore:
Timestamp:
Oct 27, 2011, 9:06:45 PM (15 years ago)
Author:
eugene
Message:

pantasks_server ports can be specified in the config file

Location:
branches/eam_branches/ipp-20110906/Ohana/src/opihi
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20110906/Ohana/src/opihi/include/shell.h

    r32569 r32583  
    184184
    185185/* socket functions */
    186 int InitServerSocket (SockAddress *Address);
     186int InitServerSocket (SockAddress *Address, char *hostname, char *portinfo);
    187187int WaitServerSocket (int InitSocket, SockAddress *Address);
    188188int GetClientSocket (char *hostname, char *portinfo);
  • branches/eam_branches/ipp-20110906/Ohana/src/opihi/lib.shell/SocketOps.c

    r32569 r32583  
    11# include "shell.h"
     2# include <unistd.h>
     3# define HOST_NAME_MAX 256
    24
    35# define MY_PORT 2000
     
    1113static int *VALID;
    1214
    13 int InitServerSocket (SockAddress *Address) {
    14 
     15int GetPortRange (int *start, int *stop, char *portinfo);
     16
     17int InitServerSocket (SockAddress *Address, char *hostname, char *portinfo) {
     18
     19  int start, stop;
    1520  int status, InitSocket, length;
    16 
    17 # if (0)
    18   struct hostent  *host;
    19   char tmpline[80], hostip[80];
    20 
    21   host = gethostbyname (hostname);
    22   bzero (hostip, 80);
    23   for (i = 0; i < host[0].h_length; i++) {
    24     sprintf (tmpline, "%u", (0xff & host[0].h_addr[i]));
    25     strcat (hostip, tmpline);
    26     if (i < host[0].h_length - 1) strcat (hostip, ".");
    27   }
    28 # endif
    29  
     21  char myHostname[HOST_NAME_MAX];
     22
     23  status = gethostname (myHostname, HOST_NAME_MAX);
     24
     25  fprintf (stderr, "target host: %s, real host: %s\n", hostname, myHostname);
     26
     27  GetPortRange (&start, &stop, portinfo);
     28
     29  fprintf (stderr, "using port range %d - %d\n", start, stop);
     30
    3031  Address[0].sin_family = AF_INET;
    31   Address[0].sin_port   = MY_PORT;
     32  Address[0].sin_port   = start;
    3233  Address[0].sin_addr.s_addr = INADDR_ANY; // use this line to bind any address / port?
    3334
    3435retry_server:
    35 
    36 # if (0) 
    37   status = inet_aton (hostip, &Address[0].sin_addr);
    38   if (!status) {
    39     gprint (GP_ERR, "invalid address\n");
    40     exit (4);
    41   }
    42 # endif
    4336
    4437  length = sizeof(Address[0]);
     
    7467    if (errno == EADDRINUSE) {
    7568        Address[0].sin_port ++;
    76         if (Address[0].sin_port > MY_PORT + 10) {
     69        if (Address[0].sin_port > stop) {
    7770          fprintf (stderr, "failed to find a usable port\n");
    7871          exit (6);
     
    154147}
    155148
     149int GetPortRange (int *start, int *stop, char *portinfo) {
     150
     151  // portinfo is a port or port range of the form NN or NN:MM
     152  *start = MY_PORT;
     153  *stop = *start + 10;
     154  if (!portinfo) return TRUE;
     155  if (*portinfo == 0) return TRUE;
     156
     157  char *endptr;
     158  *start = strtol (portinfo, &endptr, 0);
     159  *stop = *start + 10; // default range of 10
     160  if (!endptr) {
     161    gprint (GP_ERR, "error in port range parsing : %s\n", portinfo);
     162    exit (20);
     163  }
     164  if (endptr == portinfo) {
     165    gprint (GP_ERR, "error in port range (%s), must be in form NN:MM or NN\n", portinfo);
     166    exit (20);
     167  }
     168  if (*endptr == 0) return TRUE;
     169
     170  if (*endptr != ':') {
     171    gprint (GP_ERR, "error in port range %s (wrong range separator, must be in form NN:MM)\n", portinfo);
     172    exit (20);
     173  }
     174  char *ptr = endptr + 1;
     175  *stop = strtol (ptr, &endptr, 0);
     176  if (endptr == ptr)  {
     177    gprint (GP_ERR, "error in port range (%s), must be in form NN:MM or NN\n", portinfo);
     178    exit (20);
     179  }
     180  if (*stop - *start > 20) {
     181    gprint (GP_ERR, "error in port range (%s), range must be 20 or less\n", portinfo);
     182    exit (20);
     183  }
     184  if (*stop < *start) {
     185    gprint (GP_ERR, "error in port range (%s), stop must >= start\n", portinfo);
     186    exit (20);
     187  }
     188  return TRUE;
     189}
     190
    156191int GetClientSocket (char *hostname, char *portinfo) {
    157192
    158   int i, status, InitSocket, length;
     193  int i, status, InitSocket, length, start, stop;
    159194  SockAddress Address;
    160195  struct hostent  *host;
     
    169204  }
    170205
    171   // portinfo is a port or port range of the form NN or NN:MM
    172   int start = MY_PORT;
    173   int stop = start + 10;
    174   if (portinfo[0]) {
    175       char *endptr;
    176       start = strtol (portinfo, &endptr, 0);
    177       stop = start + 10; // default range of 10
    178       if (!endptr) {
    179           gprint (GP_ERR, "error in port range parsing\n");
    180           exit (20);
    181       }
    182       if (endptr == portinfo) {
    183           gprint (GP_ERR, "error in port range, must be in form NN:MM or NN\n");
    184           exit (20);
    185       }
    186       if (*endptr) {
    187           if (*endptr != ":") {
    188               gprint (GP_ERR, "error in port range (wrong range separator, must be in form NN:MM)\n");
    189               exit (20);
    190           }
    191           char *ptr = endptr + 1;
    192           stop = strtol (ptr, &endptr, 0);
    193           if (endptr == ptr)  {
    194               gprint (GP_ERR, "error in port range, must be in form NN:MM or NN\n");
    195               exit (20);
    196           }
    197       }
    198   }     
     206  GetPortRange (&start, &stop, portinfo);
    199207
    200208  if (DEBUG) {
  • branches/eam_branches/ipp-20110906/Ohana/src/opihi/pantasks/pantasks_server.c.in

    r27999 r32583  
    1818int main (int argc, char **argv) {
    1919 
     20  char hostname[256], portinfo[256];
    2021  char log_stdout[1024], log_stderr[1024];
    2122  pthread_t JobsAndTasksThread;
     
    100101     pass them to the ListenClient thread */
    101102
     103  /* find the defined server hostname */
     104  if (VarConfig ("PANTASKS_SERVER", "%s", hostname) == NULL) {
     105    gprint (GP_ERR, "pantasks server host undefined\n");
     106    exit (31);
     107  }
     108
     109  /* is a port range defined? otherwise use the default */
     110  memset (portinfo, 0, 256);
     111  VarConfig ("PANTASKS_SERVER_PORT", "%s", portinfo);
     112
    102113  /* create the listening socket */
    103   InitSocket = InitServerSocket (&Address);
     114  InitSocket = InitServerSocket (&Address, hostname, portinfo);
    104115 
    105116  InitPassword ();
Note: See TracChangeset for help on using the changeset viewer.