Skip to content

Commit 9c26b48

Browse files
committed
Merge branch 'master' into Arduino_1.5.5
Conflicts: UIPEthernet/src/utility/uip-neighbor.c UIPEthernet/src/utility/uip-neighbor.h
2 parents 3e11bbb + 160df53 commit 9c26b48

File tree

13 files changed

+180
-445
lines changed

13 files changed

+180
-445
lines changed

UIPEthernet/src/UIPClient.cpp

Lines changed: 57 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ UIPClient::connect(IPAddress ip, uint16_t port)
5757
{
5858
while((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
5959
{
60-
UIPEthernet.tick();
60+
UIPEthernetClass::tick();
6161
if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
6262
{
6363
data = (uip_userdata_t*) conn->appstate;
@@ -83,7 +83,7 @@ UIPClient::connect(const char *host, uint16_t port)
8383
DNSClient dns;
8484
IPAddress remote_addr;
8585

86-
dns.begin(UIPEthernet.dnsServerIP());
86+
dns.begin(UIPEthernetClass::_dnsServerAddress);
8787
ret = dns.getHostByName(host, remote_addr);
8888
if (ret == 1) {
8989
return connect(remote_addr, port);
@@ -122,7 +122,7 @@ UIPClient::stop()
122122
}
123123
#endif
124124
data = NULL;
125-
UIPEthernet.tick();
125+
UIPEthernetClass::tick();
126126
}
127127

128128
uint8_t
@@ -139,7 +139,7 @@ UIPClient::operator==(const UIPClient& rhs)
139139

140140
UIPClient::operator bool()
141141
{
142-
UIPEthernet.tick();
142+
UIPEthernetClass::tick();
143143
return data && (!(data->state & UIP_CLIENT_REMOTECLOSED) || data->packets_in[0] != NOBLOCK);
144144
}
145145

@@ -164,15 +164,15 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
164164
uint16_t attempts = UIP_ATTEMPTS_ON_WRITE;
165165
#endif
166166
repeat:
167-
UIPEthernet.tick();
167+
UIPEthernetClass::tick();
168168
if (u && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
169169
{
170-
memhandle* p = _currentBlock(&u->packets_out[0]);
171-
if (*p == NOBLOCK)
170+
uint8_t p = _currentBlock(&u->packets_out[0]);
171+
if (u->packets_out[p] == NOBLOCK)
172172
{
173173
newpacket:
174-
*p = UIPEthernet.network.allocBlock(UIP_SOCKET_DATALEN);
175-
if (*p == NOBLOCK)
174+
u->packets_out[p] = UIPEthernetClass::network.allocBlock(UIP_SOCKET_DATALEN);
175+
if (u->packets_out[p] == NOBLOCK)
176176
{
177177
#if UIP_ATTEMPTS_ON_WRITE > 0
178178
if ((--attempts)>0)
@@ -186,7 +186,7 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
186186
}
187187
#ifdef UIPETHERNET_DEBUG_CLIENT
188188
Serial.print(F("UIPClient.write: writePacket("));
189-
Serial.print(*p);
189+
Serial.print(u->packets_out[p]);
190190
Serial.print(F(") pos: "));
191191
Serial.print(u->out_pos);
192192
Serial.print(F(", buf["));
@@ -197,12 +197,12 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
197197
Serial.write((uint8_t*)buf+size-remain,remain);
198198
Serial.println(F("'"));
199199
#endif
200-
written = UIPEthernet.network.writePacket(*p,u->out_pos,(uint8_t*)buf+size-remain,remain);
200+
written = UIPEthernetClass::network.writePacket(u->packets_out[p],u->out_pos,(uint8_t*)buf+size-remain,remain);
201201
remain -= written;
202202
u->out_pos+=written;
203203
if (remain > 0)
204204
{
205-
if (p==&u->packets_out[UIP_SOCKET_NUMPACKETS-1])
205+
if (p == UIP_SOCKET_NUMPACKETS-1)
206206
{
207207
#if UIP_ATTEMPTS_ON_WRITE > 0
208208
if ((--attempts)>0)
@@ -232,15 +232,10 @@ UIPClient::available()
232232
int
233233
UIPClient::_available(uip_userdata_t *u)
234234
{
235-
memhandle* p = &u->packets_in[0];
236-
if (*p == NOBLOCK)
237-
return 0;
238235
int len = 0;
239-
for(memhandle* end = p+UIP_SOCKET_NUMPACKETS; p < end; p++)
236+
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
240237
{
241-
if(*p == NOBLOCK)
242-
break;
243-
len += UIPEthernet.network.blockSize(*p);
238+
len += UIPEthernetClass::network.blockSize(u->packets_in[i]);
244239
}
245240
return len;
246241
}
@@ -250,21 +245,20 @@ UIPClient::read(uint8_t *buf, size_t size)
250245
{
251246
if (*this)
252247
{
253-
int remain = size;
254-
memhandle* p = &data->packets_in[0];
255-
if (*p == NOBLOCK)
248+
uint16_t remain = size;
249+
if (data->packets_in[0] == NOBLOCK)
256250
return 0;
257-
int read;
251+
uint16_t read;
258252
do
259253
{
260-
read = UIPEthernet.network.readPacket(*p,0,buf+size-remain,remain);
261-
if (read == UIPEthernet.network.blockSize(*p))
254+
read = UIPEthernetClass::network.readPacket(data->packets_in[0],0,buf+size-remain,remain);
255+
if (read == UIPEthernetClass::network.blockSize(data->packets_in[0]))
262256
{
263257
remain -= read;
264-
_eatBlock(p);
258+
_eatBlock(&data->packets_in[0]);
265259
if (uip_stopped(&uip_conns[data->state & UIP_CLIENT_SOCKETS]) && !(data->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
266260
data->state |= UIP_CLIENT_RESTART;
267-
if (*p == NOBLOCK)
261+
if (data->packets_in[0] == NOBLOCK)
268262
{
269263
if (data->state & UIP_CLIENT_REMOTECLOSED)
270264
{
@@ -276,7 +270,7 @@ UIPClient::read(uint8_t *buf, size_t size)
276270
}
277271
else
278272
{
279-
UIPEthernet.network.resizeBlock(*p,read);
273+
UIPEthernetClass::network.resizeBlock(data->packets_in[0],read);
280274
break;
281275
}
282276
}
@@ -300,11 +294,10 @@ UIPClient::peek()
300294
{
301295
if (*this)
302296
{
303-
memhandle p = data->packets_in[0];
304-
if (p != NOBLOCK)
297+
if (data->packets_in[0] != NOBLOCK)
305298
{
306299
uint8_t c;
307-
UIPEthernet.network.readPacket(p,0,&c,1);
300+
UIPEthernetClass::network.readPacket(data->packets_in[0],0,&c,1);
308301
return c;
309302
}
310303
}
@@ -360,31 +353,22 @@ UIPClient::uip_callback()
360353
#endif
361354
if (uip_len && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED)))
362355
{
363-
memhandle newPacket = UIPEthernet.network.allocBlock(uip_len);
356+
memhandle newPacket = UIPEthernetClass::network.allocBlock(uip_len);
364357
if (newPacket != NOBLOCK)
365358
{
366-
memhandle* p = _currentBlock(&u->packets_in[0]);
367-
//if it's not the first packet
368-
if (*p != NOBLOCK)
359+
for (uint8_t i=0; i < UIP_SOCKET_NUMPACKETS; i++)
369360
{
370-
uint8_t slot = p - &u->packets_in[0];
371-
if (slot < UIP_SOCKET_NUMPACKETS-1)
372-
p++;
373-
//if this is the last slot stop this connection
374-
if (slot >= UIP_SOCKET_NUMPACKETS-2)
361+
if (u->packets_in[i] == NOBLOCK)
375362
{
376-
uip_stop();
377-
//if there's no free slot left omit loosing this packet and (again) stop this connection
378-
if (slot == UIP_SOCKET_NUMPACKETS-1)
379-
goto reject_newdata;
363+
if (i == UIP_SOCKET_NUMPACKETS-1)
364+
uip_stop();
365+
UIPEthernetClass::network.copyPacket(newPacket,0,UIPEthernetClass::in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len);
366+
u->packets_in[i] = newPacket;
367+
goto finish_newdata;
380368
}
381369
}
382-
UIPEthernet.network.copyPacket(newPacket,0,UIPEthernet.in_packet,((uint8_t*)uip_appdata)-uip_buf,uip_len);
383-
*p = newPacket;
384-
goto finish_newdata;
385370
}
386-
reject_newdata:
387-
UIPEthernet.packetstate &= ~UIPETHERNET_FREEPACKET;
371+
UIPEthernetClass::packetstate &= ~UIPETHERNET_FREEPACKET;
388372
uip_stop();
389373
}
390374
}
@@ -430,27 +414,26 @@ UIPClient::uip_callback()
430414
#ifdef UIPETHERNET_DEBUG_CLIENT
431415
//Serial.println(F("UIPClient uip_poll"));
432416
#endif
433-
memhandle p = u->packets_out[0];
434-
if (p != NOBLOCK)
417+
if (u->packets_out[0] != NOBLOCK)
435418
{
436419
if (u->packets_out[1] == NOBLOCK)
437420
{
438421
uip_len = u->out_pos;
439422
if (uip_len > 0)
440423
{
441-
UIPEthernet.network.resizeBlock(p,0,uip_len);
424+
UIPEthernetClass::network.resizeBlock(u->packets_out[0],0,uip_len);
442425
}
443426
}
444427
else
445-
uip_len = UIPEthernet.network.blockSize(p);
428+
uip_len = UIPEthernetClass::network.blockSize(u->packets_out[0]);
446429
if (uip_len > 0)
447430
{
448-
UIPEthernet.uip_hdrlen = ((uint8_t*)uip_appdata)-uip_buf;
449-
UIPEthernet.uip_packet = UIPEthernet.network.allocBlock(UIPEthernet.uip_hdrlen+uip_len);
450-
if (UIPEthernet.uip_packet != NOBLOCK)
431+
UIPEthernetClass::uip_hdrlen = ((uint8_t*)uip_appdata)-uip_buf;
432+
UIPEthernetClass::uip_packet = UIPEthernetClass::network.allocBlock(UIPEthernetClass::uip_hdrlen+uip_len);
433+
if (UIPEthernetClass::uip_packet != NOBLOCK)
451434
{
452-
UIPEthernet.network.copyPacket(UIPEthernet.uip_packet,UIPEthernet.uip_hdrlen,p,0,uip_len);
453-
UIPEthernet.packetstate |= UIPETHERNET_SENDPACKET;
435+
UIPEthernetClass::network.copyPacket(UIPEthernetClass::uip_packet,UIPEthernetClass::uip_hdrlen,u->packets_out[0],0,uip_len);
436+
UIPEthernetClass::packetstate |= UIPETHERNET_SENDPACKET;
454437
uip_send(uip_appdata,uip_len);
455438
}
456439
return;
@@ -484,7 +467,7 @@ UIPClient::uip_callback()
484467
}
485468
}
486469
nodata:
487-
UIPEthernet.uip_packet = NOBLOCK;
470+
UIPEthernetClass::uip_packet = NOBLOCK;
488471
uip_len=0;
489472
}
490473

@@ -504,13 +487,15 @@ UIPClient::_allocateData()
504487
return NULL;
505488
}
506489

507-
memhandle*
490+
uint8_t
508491
UIPClient::_currentBlock(memhandle* block)
509492
{
510-
for(memhandle* end = block+UIP_SOCKET_NUMPACKETS-1; block < end; block++)
511-
if(*(block+1) == NOBLOCK)
512-
break;
513-
return block;
493+
for (uint8_t i = 1; i < UIP_SOCKET_NUMPACKETS; i++)
494+
{
495+
if (block[i] == NOBLOCK)
496+
return i-1;
497+
}
498+
return UIP_SOCKET_NUMPACKETS-1;
514499
}
515500

516501
void
@@ -528,11 +513,12 @@ UIPClient::_eatBlock(memhandle* block)
528513
}
529514
Serial.print(F("-> "));
530515
#endif
531-
memhandle* end = block+(UIP_SOCKET_NUMPACKETS-1);
532-
UIPEthernet.network.freeBlock(*block);
533-
while(block < end)
534-
*block = *((block++)+1);
535-
*end = NOBLOCK;
516+
UIPEthernetClass::network.freeBlock(block[0]);
517+
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS-1; i++)
518+
{
519+
block[i] = block[i+1];
520+
}
521+
block[UIP_SOCKET_NUMPACKETS-1] = NOBLOCK;
536522
#ifdef UIPETHERNET_DEBUG_CLIENT
537523
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
538524
{
@@ -546,15 +532,9 @@ UIPClient::_eatBlock(memhandle* block)
546532
void
547533
UIPClient::_flushBlocks(memhandle* block)
548534
{
549-
for(memhandle* end = block+UIP_SOCKET_NUMPACKETS; block < end; block++)
535+
for (uint8_t i = 0; i < UIP_SOCKET_NUMPACKETS; i++)
550536
{
551-
if(*block != NOBLOCK)
552-
{
553-
UIPEthernet.network.freeBlock(*block);
554-
*block = NOBLOCK;
555-
}
556-
else
557-
break;
537+
UIPEthernetClass::network.freeBlock(block[i]);
558538
}
559539
}
560540

UIPEthernet/src/UIPClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class UIPClient : public Client {
8888
static size_t _write(uip_userdata_t *,const uint8_t *buf, size_t size);
8989
static int _available(uip_userdata_t *);
9090

91-
static memhandle * _currentBlock(memhandle* blocks);
91+
static uint8_t _currentBlock(memhandle* blocks);
9292
static void _eatBlock(memhandle* blocks);
9393
static void _flushBlocks(memhandle* blocks);
9494

0 commit comments

Comments
 (0)