Skip to content

Commit 05f707a

Browse files
author
fpr
committed
Move *udp_pcb inside udp struct
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
1 parent d0b5d20 commit 05f707a

File tree

2 files changed

+34
-34
lines changed

2 files changed

+34
-34
lines changed

libraries/Ethernet/src/EthernetUdp.cpp

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,35 @@
2626
* bjoern@cs.stanford.edu 12/30/2008
2727
*/
2828

29-
#include "utility/socket.h"
3029
#include "Ethernet.h"
3130
#include "Udp.h"
3231
#include "Dns.h"
3332

3433
/* Constructor */
35-
EthernetUDP::EthernetUDP() : _sock(MAX_SOCK_NUM) {}
34+
EthernetUDP::EthernetUDP() {}
3635

3736
/* Start EthernetUDP socket, listening at local port PORT */
3837
uint8_t EthernetUDP::begin(uint16_t port) {
3938
// Can create a single udp connection per socket
40-
if(_udp_pcb != NULL) {
39+
if(_udp.pcb != NULL) {
4140
return 0;
4241
}
4342

44-
_udp_pcb = udp_new();
43+
_udp.pcb = udp_new();
4544

46-
if(_udp_pcb == NULL) {
45+
if(_udp.pcb == NULL) {
4746
return 0;
4847
}
4948

5049
IPAddress ip = Ethernet.localIP();
5150
ip_addr_t ipaddr;
5251

53-
if(ERR_OK != udp_bind(_udp_pcb, u8_to_ip_addr(rawIPAddress(ip), &ipaddr), port)) {
52+
if(ERR_OK != udp_bind(_udp.pcb, u8_to_ip_addr(rawIPAddress(ip), &ipaddr), port)) {
53+
stop();
5454
return 0;
5555
}
5656

57-
udp_recv(_udp_pcb, &udp_receive_callback, &_arg);
57+
udp_recv(_udp.pcb, &udp_receive_callback, &_udp);
5858

5959
_port = port;
6060
_remaining = 0;
@@ -73,10 +73,10 @@ int EthernetUDP::available() {
7373
/* Release any resources being used by this EthernetUDP instance */
7474
void EthernetUDP::stop()
7575
{
76-
if(_udp_pcb != NULL) {
77-
udp_disconnect(_udp_pcb);
78-
udp_remove(_udp_pcb);
79-
_udp_pcb = NULL;
76+
if(_udp.pcb != NULL) {
77+
udp_disconnect(_udp.pcb);
78+
udp_remove(_udp.pcb);
79+
_udp.pcb = NULL;
8080
}
8181

8282
stm32_eth_scheduler();
@@ -100,34 +100,34 @@ int EthernetUDP::beginPacket(const char *host, uint16_t port)
100100

101101
int EthernetUDP::beginPacket(IPAddress ip, uint16_t port)
102102
{
103-
if(_udp_pcb == NULL) {
103+
if(_udp.pcb == NULL) {
104104
return 0;
105105
}
106106

107107
ip_addr_t ipaddr;
108108

109-
if(ERR_OK != udp_connect( _udp_pcb, u8_to_ip_addr(rawIPAddress(ip), &ipaddr), port)) {
109+
if(ERR_OK != udp_connect( _udp.pcb, u8_to_ip_addr(rawIPAddress(ip), &ipaddr), port)) {
110110
return 0;
111111
}
112112

113-
udp_recv(_udp_pcb, &udp_receive_callback, &_arg);
113+
udp_recv(_udp.pcb, &udp_receive_callback, &_udp);
114114
stm32_eth_scheduler();
115115

116116
return 1;
117117
}
118118

119119
int EthernetUDP::endPacket()
120120
{
121-
if((_udp_pcb == NULL) || (_data == NULL)) {
121+
if((_udp.pcb == NULL) || (_data == NULL)) {
122122
return 0;
123123
}
124124

125125
// A remote IP & port must be connected to udp pcb. Call ::beginPacket before.
126-
if((udp_flags(_udp_pcb) & UDP_FLAGS_CONNECTED) != UDP_FLAGS_CONNECTED) {
126+
if((udp_flags(_udp.pcb) & UDP_FLAGS_CONNECTED) != UDP_FLAGS_CONNECTED) {
127127
return 0;
128128
}
129129

130-
if(ERR_OK != udp_send(_udp_pcb, _data)) {
130+
if(ERR_OK != udp_send(_udp.pcb, _data)) {
131131
_data = stm32_free_data(_data);
132132
return 0;
133133
}
@@ -165,11 +165,11 @@ int EthernetUDP::parsePacket()
165165

166166
stm32_eth_scheduler();
167167

168-
if (_arg.available > 0)
168+
if (_udp.available > 0)
169169
{
170-
_remoteIP = IPAddress(ip_addr_to_u32(&(_arg.ip)));
171-
_remotePort = _arg.port;
172-
_remaining = _arg.available;
170+
_remoteIP = IPAddress(ip_addr_to_u32(&(_udp.ip)));
171+
_remotePort = _udp.port;
172+
_remaining = _udp.available;
173173

174174
return _remaining;
175175
}
@@ -181,7 +181,7 @@ int EthernetUDP::read()
181181
{
182182
uint8_t byte;
183183

184-
if(_arg.p == NULL) {
184+
if(_udp.p == NULL) {
185185
return -1;
186186
}
187187

@@ -191,8 +191,8 @@ int EthernetUDP::read()
191191
_remaining--;
192192

193193
if(_remaining == 0) {
194-
_arg.available = 0;
195-
_arg.p = stm32_free_data(_arg.p);
194+
_udp.available = 0;
195+
_udp.p = stm32_free_data(_udp.p);
196196
}
197197

198198
return byte;
@@ -204,7 +204,7 @@ int EthernetUDP::read()
204204

205205
int EthernetUDP::read(unsigned char* buffer, size_t len)
206206
{
207-
if(_arg.p == NULL) {
207+
if(_udp.p == NULL) {
208208
return -1;
209209
}
210210

@@ -215,22 +215,22 @@ int EthernetUDP::read(unsigned char* buffer, size_t len)
215215
if (_remaining <= len)
216216
{
217217
// data should fit in the buffer
218-
got = (int)stm32_get_data(_arg.p, (uint8_t *)buffer, _remaining, _remaining);
218+
got = (int)stm32_get_data(_udp.p, (uint8_t *)buffer, _remaining, _remaining);
219219
}
220220
else
221221
{
222222
// too much data for the buffer,
223223
// grab as much as will fit
224-
got = (int)stm32_get_data(_arg.p, (uint8_t *)buffer, len, _remaining);
224+
got = (int)stm32_get_data(_udp.p, (uint8_t *)buffer, len, _remaining);
225225
}
226226

227227
if (got > 0)
228228
{
229229
_remaining -= got;
230230

231231
if(_remaining == 0) {
232-
_arg.available = 0;
233-
_arg.p = stm32_free_data(_arg.p);
232+
_udp.available = 0;
233+
_udp.p = stm32_free_data(_udp.p);
234234
}
235235

236236
return got;
@@ -251,8 +251,7 @@ int EthernetUDP::peek()
251251
// may get the UDP header
252252
if (!_remaining)
253253
return -1;
254-
// ::peek(_sock, &b);
255-
stm32_get_data(_arg.p, &b, 1, _remaining);
254+
stm32_get_data(_udp.p, &b, 1, _remaining);
256255
return b;
257256
}
258257

libraries/Ethernet/src/EthernetUdp.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@
3838
#define ethernetudp_h
3939

4040
#include <Udp.h>
41+
42+
extern "C" {
4143
#include "utility/stm32_eth.h"
44+
}
4245

4346
#define UDP_TX_PACKET_MAX_SIZE 24
4447

@@ -48,12 +51,10 @@ class EthernetUDP : public UDP {
4851
IPAddress _remoteIP; // remote IP address for the incoming packet whilst it's being processed
4952
uint16_t _remotePort; // remote port for the incoming packet whilst it's being processed
5053

51-
struct udp_pcb *_udp_pcb;
5254
struct pbuf *_data;
53-
struct udp_rcv_arg _arg;
55+
struct udp_struct _udp;
5456

5557
protected:
56-
uint8_t _sock; // socket ID for Wiz5100
5758
uint16_t _remaining; // remaining bytes of incoming packet yet to be processed
5859

5960
public:

0 commit comments

Comments
 (0)