V71+: #268 obey host name setting with env vars

This commit is contained in:
joan2937 2019-11-27 21:25:35 +00:00
parent adf7caeff5
commit 6b770ad810
2 changed files with 23 additions and 31 deletions

View File

@ -30,7 +30,7 @@ For more information, please refer to <http://unlicense.org/>
#include <stdint.h> #include <stdint.h>
#include <pthread.h> #include <pthread.h>
#define PIGPIO_VERSION 7103 #define PIGPIO_VERSION 7104
/*TEXT /*TEXT
@ -6491,7 +6491,7 @@ after this command is issued.
#define PI_DEFAULT_DMA_NOT_SET 15 #define PI_DEFAULT_DMA_NOT_SET 15
#define PI_DEFAULT_SOCKET_PORT 8888 #define PI_DEFAULT_SOCKET_PORT 8888
#define PI_DEFAULT_SOCKET_PORT_STR "8888" #define PI_DEFAULT_SOCKET_PORT_STR "8888"
#define PI_DEFAULT_SOCKET_ADDR_STR "127.0.0.1" #define PI_DEFAULT_SOCKET_ADDR_STR "localhost"
#define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL #define PI_DEFAULT_UPDATE_MASK_UNKNOWN 0x0000000FFFFFFCLL
#define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93 #define PI_DEFAULT_UPDATE_MASK_B1 0x03E7CF93
#define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C #define PI_DEFAULT_UPDATE_MASK_A_B2 0xFBC7CF9C

View File

@ -234,33 +234,10 @@ static int pigpio_command_ext
return cmd.res; return cmd.res;
} }
static int pigpioOpenSocket(char *addr, char *port) static int pigpioOpenSocket(char *addrStr, char *portStr)
{ {
int sock, err, opt; int sock, err, opt;
struct addrinfo hints, *res, *rp; struct addrinfo hints, *res, *rp;
const char *addrStr, *portStr;
if (!addr)
{
addrStr = getenv(PI_ENVADDR);
if ((!addrStr) || (!strlen(addrStr)))
{
addrStr = PI_DEFAULT_SOCKET_ADDR_STR;
}
}
else addrStr = addr;
if (!port)
{
portStr = getenv(PI_ENVPORT);
if ((!portStr) || (!strlen(portStr)))
{
portStr = PI_DEFAULT_SOCKET_PORT_STR;
}
}
else portStr = port;
memset (&hints, 0, sizeof (hints)); memset (&hints, 0, sizeof (hints));
@ -713,11 +690,6 @@ int pigpio_start(char *addrStr, char *portStr)
int pi; int pi;
int *userdata; int *userdata;
if ((!addrStr) || (strlen(addrStr) == 0))
{
addrStr = "localhost";
}
for (pi=0; pi<MAX_PI; pi++) for (pi=0; pi<MAX_PI; pi++)
{ {
if (!gPiInUse[pi]) break; if (!gPiInUse[pi]) break;
@ -727,6 +699,26 @@ int pigpio_start(char *addrStr, char *portStr)
gPiInUse[pi] = 1; gPiInUse[pi] = 1;
if ((!addrStr) || (!strlen(addrStr)))
{
addrStr = getenv(PI_ENVADDR);
if ((!addrStr) || (!strlen(addrStr)))
{
addrStr = PI_DEFAULT_SOCKET_ADDR_STR;
}
}
if ((!portStr) || (!strlen(portStr)))
{
portStr = getenv(PI_ENVPORT);
if ((!portStr) || (!strlen(portStr)))
{
portStr = PI_DEFAULT_SOCKET_PORT_STR;
}
}
pthread_mutex_init(&gCmdMutex[pi], NULL); pthread_mutex_init(&gCmdMutex[pi], NULL);
gPigCommand[pi] = pigpioOpenSocket(addrStr, portStr); gPigCommand[pi] = pigpioOpenSocket(addrStr, portStr);