mirror of
https://github.com/eddyem/small_tel.git
synced 2026-03-22 01:31:01 +03:00
force to new usefull_macros lib
This commit is contained in:
@@ -28,7 +28,6 @@
|
||||
#include <unistd.h> // daemon
|
||||
#include <usefull_macros.h>
|
||||
|
||||
#include "cmdlnopts.h" // glob_pars
|
||||
#include "socket.h"
|
||||
#include "stat.h"
|
||||
#include "term.h"
|
||||
@@ -38,8 +37,6 @@
|
||||
// Max amount of connections
|
||||
#define BACKLOG (30)
|
||||
|
||||
extern glob_pars *GP;
|
||||
|
||||
static weather_t lastweather = {0};
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
static weatherstat_t wstat;
|
||||
@@ -72,7 +69,7 @@ static int send_data(int sock, int webquery, format_t format){
|
||||
if(format == FORMAT_CURDFULL){ // full format
|
||||
Len = snprintf(databuf, BUFSIZ,
|
||||
"Wind=%.1f%sDir=%.1f%sPressure=%.1f%sTemperature=%.1f%sHumidity=%.1f%s"
|
||||
"Rain=%.1f%sTime=%.3f%s",
|
||||
"Rain=%.1f%sTime=%.1f%s",
|
||||
lastweather.windspeed, eol, lastweather.winddir, eol, lastweather.pressure, eol,
|
||||
lastweather.temperature, eol, lastweather.humidity, eol, lastweather.rainfall, eol,
|
||||
lastweather.tmeasure, eol
|
||||
@@ -117,6 +114,7 @@ static int send_data(int sock, int webquery, format_t format){
|
||||
PRSTAT(tmeasure, "Time");
|
||||
Len += snprintf(ptr, l, "%s", eol);
|
||||
#undef PRSTAT
|
||||
#undef COMMA
|
||||
}else{
|
||||
Len = snprintf(databuf, BUFSIZ, "Error!");
|
||||
}
|
||||
@@ -247,6 +245,7 @@ static int handle_socket(int sock){
|
||||
|
||||
// main socket server
|
||||
static void *server(void *asock){
|
||||
FNAME();
|
||||
LOGMSG("server()");
|
||||
int sock = *((int*)asock);
|
||||
if(listen(sock, BACKLOG) == -1){
|
||||
@@ -307,6 +306,7 @@ static void *server(void *asock){
|
||||
|
||||
// poll last weather data
|
||||
static void *weatherpolling(_U_ void *notused){
|
||||
FNAME();
|
||||
while(1){
|
||||
weather_t w;
|
||||
if(getlastweather(&w) && 0 == pthread_mutex_lock(&mutex)){
|
||||
@@ -321,6 +321,7 @@ static void *weatherpolling(_U_ void *notused){
|
||||
|
||||
// data gathering & socket management
|
||||
static void daemon_(int sock){
|
||||
DBG("sock=%d", sock);
|
||||
if(sock < 0) return;
|
||||
pthread_t sock_thread, parser_thread;
|
||||
if(pthread_create(&sock_thread, NULL, server, (void*) &sock)){
|
||||
|
||||
Reference in New Issue
Block a user