Include .h instead of .cpp when possible
* Move implementation code from Arduino.h
This commit is contained in:
@@ -1,24 +1,25 @@
|
||||
/*
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Marcelo Aquino <marceloaqno@gmail.org>
|
||||
* Copyright (C) 2016 Marcelo Aquino
|
||||
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
||||
*/
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Marcelo Aquino <marceloaqno@gmail.org>
|
||||
* Copyright (C) 2016 Marcelo Aquino
|
||||
* Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* Based on Arduino ethernet library, Copyright (c) 2010 Arduino LLC. All right reserved.
|
||||
*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <sys/socket.h>
|
||||
#include <cstring>
|
||||
#include <sys/socket.h>
|
||||
@@ -33,6 +34,7 @@ struct server_vars {
|
||||
struct IPAddress address;
|
||||
std::list<int> *new_clients;
|
||||
std::vector<int> *clients;
|
||||
uint16_t max_clients;
|
||||
};
|
||||
|
||||
static pthread_mutex_t new_clients_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
@@ -40,9 +42,9 @@ static pthread_mutex_t clients_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void *incoming_connections(void *);
|
||||
|
||||
EthernetServer::EthernetServer(uint16_t port) : port(port)
|
||||
EthernetServer::EthernetServer(uint16_t port, uint16_t max_clients) : port(port), max_clients(max_clients)
|
||||
{
|
||||
clients.reserve(MY_GATEWAY_MAX_CLIENTS);
|
||||
clients.reserve(max_clients);
|
||||
}
|
||||
|
||||
void EthernetServer::begin()
|
||||
@@ -60,6 +62,7 @@ void EthernetServer::begin(IPAddress address)
|
||||
vars->address = address;
|
||||
vars->new_clients = &new_clients;
|
||||
vars->clients = &clients;
|
||||
vars->max_clients = max_clients;
|
||||
|
||||
pthread_attr_init(&detached_attr);
|
||||
pthread_attr_setdetachstate(&detached_attr, PTHREAD_CREATE_DETACHED);
|
||||
@@ -137,6 +140,7 @@ size_t EthernetServer::write(const char *str) {
|
||||
if (str == NULL) return 0;
|
||||
return write((const uint8_t *)str, strlen(str));
|
||||
}
|
||||
|
||||
size_t EthernetServer::write(const char *buffer, size_t size) {
|
||||
return write((const uint8_t *)buffer, size);
|
||||
}
|
||||
@@ -221,7 +225,7 @@ void *incoming_connections(void* thread_arg)
|
||||
pthread_mutex_lock(&clients_mutex);
|
||||
int connected_clients = vars->new_clients->size() + vars->clients->size();
|
||||
|
||||
if (connected_clients == MY_GATEWAY_MAX_CLIENTS) {
|
||||
if (connected_clients == vars->max_clients) {
|
||||
pthread_mutex_unlock(&clients_mutex);
|
||||
pthread_mutex_unlock(&new_clients_mutex);
|
||||
ETHERNETSERVER_DEBUG("Max number of ethernet clients reached.");
|
||||
|
||||
Reference in New Issue
Block a user