15 #include <avr/pgmspace.h>
17 #define MTU 1500 //<! размер Maximum Transfer Unit
22 uint32_t htonl(
const uint32_t);
27 uint16_t htons(
const uint16_t);
36 for(
size_t i=0;i<
sizeof(a8);i++)
37 this->a8[i] = other.a8[i];
49 sscanf_P(str,PSTR(
"%02X:%02X:%02X:%02X:%02X:%02X"),&a8[0],&a8[1],&a8[2],&a8[3],&a8[4],&a8[5]);
53 return this->a16[0] == other.a16[0] && this->a16[1] == other.a16[1] && this->a16[2] == other.a16[2];
56 return this->a16[0] != other.a16[0] || this->a16[1] != other.a16[1] || this->a16[2] != other.a16[2];
67 this->a32 = other.a32;
79 sscanf_P(astr,PSTR(
"%hhu.%hhu.%hhu.%hhu"),&a8[0],&a8[1],&a8[2],&a8[3]);
82 const bool operator == (
const union IP4Address_ &v2) {
83 return this->a32 == v2.a32;
85 const bool operator != (
const union IP4Address_ &v2) {
86 return this->a32 != v2.a32;
105 this->addr = addr.addr;
160 virtual size_t _send(
const void *,
size_t,
161 void *(copier)(
void *,
const void *,
size_t)) = 0;
167 size_t send(
const void *buffer,
size_t size) {
168 return _send(buffer,size,&memcpy);
173 size_t send_P(
const void *buffer,
size_t size) {
174 return _send(buffer,size,&memcpy_P);
179 virtual bool flush() = 0;
180 Socket &operator << (
const char *str) {
182 send(str,strlen(str));
185 virtual Socket &operator << (
const char) = 0;
189 virtual size_t recv() = 0;
193 virtual void close() = 0;
210 uint8_t *
RX() {
return _RX; }
215 uint8_t *
RX(
size_t offset) {
216 if(offset >
_RXSize)
return NULL;
222 extern const IP4Address BROADCAST_IP4_ADDRESS;
229 virtual size_t write(
const void *,
size_t) = 0;
230 virtual size_t read(
void *,
size_t) = 0;
265 if(_registred)
return;
275 const uint16_t
port() {
return _port; }
331 virtual void serve() = 0;
332 virtual ~SocketServer() { }
size_t send(const void *buffer, size_t size)
Definition: net.h:167
const uint16_t port()
Definition: net.h:275
void attach(void *data)
Definition: net.h:202
uint32_t packetsOut
пакетов отправлено
Definition: net.h:141
const uint8_t protocol()
Definition: net.h:271
virtual bool establishConnection()=0
virtual void configure(const bool dhcp, const IP4Address address, const IP4Address mask)=0
union IP4Address_ & operator<<(const char *astr)
Definition: net.h:78
virtual void removeSocketListener(SocketListener *server)=0
uint32_t packetsDropped
пакетов проигнорировано
Definition: net.h:143
uint8_t * RX()
Definition: net.h:210
uint32_t bytesIn
байт принято
Definition: net.h:140
Inet4Address dest
Адрес соединения
Definition: net.h:163
size_t connections
Количество соединений
Definition: net.h:138
virtual void registerSocketListener(SocketListener *server)=0
virtual void release(Socket *socket)=0
uint8_t * RX(size_t offset)
Definition: net.h:215
virtual void onRegister()
Definition: net.h:293
uint16_t getPort()
Definition: net.h:112
size_t _RXSize
размер входящего буфера
Definition: net.h:158
void * _attachment
пользовательские данные
Definition: net.h:159
virtual uint32_t timeout()
Definition: net.h:279
size_t send_P(const void *buffer, size_t size)
Definition: net.h:173
void * attachment()
Definition: net.h:198
void setPort(uint16_t port)
Definition: net.h:264
SocketListener(const uint8_t protocol, const uint16_t port)
Definition: net.h:259
virtual void onIdle()
Definition: net.h:297
virtual void handle(Socket *socket)=0
virtual bool isLinkUp()=0
uint32_t packetsIn
пакетов принято
Definition: net.h:139
uint32_t bytesOut
байт отправлено
Definition: net.h:142
size_t RXSize()
Definition: net.h:206