@@ -153,22 +153,17 @@ UIPClient::operator bool()
153
153
size_t
154
154
UIPClient::write (uint8_t c)
155
155
{
156
- return _write (data, &c, 1 );
156
+ return write ( &c, 1 );
157
157
}
158
158
159
159
size_t
160
160
UIPClient::write (const uint8_t *buf, size_t size)
161
161
{
162
- return _write (data, buf, size);
163
- }
164
-
165
- size_t
166
- UIPClient::_write (uip_userdata_t * u, const uint8_t *buf, size_t size)
167
- {
162
+ uip_userdata_t * u = data;
168
163
int remain = size;
169
164
uint16_t written;
170
- #if UIP_ATTEMPTS_ON_WRITE > 0
171
- uint16_t attempts = UIP_ATTEMPTS_ON_WRITE ;
165
+ #if UIP_WRITE_TIMEOUT > 0
166
+ uint32_t timeout_start = millis () ;
172
167
#endif
173
168
repeat:
174
169
UIPEthernetClass::tick ();
@@ -181,13 +176,14 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
181
176
u->packets_out [p] = Enc28J60Network::allocBlock (UIP_SOCKET_DATALEN);
182
177
if (u->packets_out [p] == NOBLOCK)
183
178
{
184
- #if UIP_ATTEMPTS_ON_WRITE > 0
185
- if ((--attempts)>0 )
186
- #endif
187
- #if UIP_ATTEMPTS_ON_WRITE != 0
188
- goto repeat;
179
+ #if UIP_WRITE_TIMEOUT > 0
180
+ if (millis () - timeout_start > UIP_WRITE_TIMEOUT)
181
+ {
182
+ setWriteError ();
183
+ goto ready;
184
+ }
189
185
#endif
190
- goto ready ;
186
+ goto repeat ;
191
187
}
192
188
u->out_pos = 0 ;
193
189
}
@@ -211,13 +207,14 @@ UIPClient::_write(uip_userdata_t* u, const uint8_t *buf, size_t size)
211
207
{
212
208
if (p == UIP_SOCKET_NUMPACKETS-1 )
213
209
{
214
- #if UIP_ATTEMPTS_ON_WRITE > 0
215
- if ((--attempts)>0 )
216
- #endif
217
- #if UIP_ATTEMPTS_ON_WRITE != 0
218
- goto repeat;
210
+ #if UIP_WRITE_TIMEOUT > 0
211
+ if (millis () - timeout_start > UIP_WRITE_TIMEOUT)
212
+ {
213
+ setWriteError ();
214
+ goto ready;
215
+ }
219
216
#endif
220
- goto ready ;
217
+ goto repeat ;
221
218
}
222
219
p++;
223
220
goto newpacket;
@@ -253,22 +250,15 @@ UIPClient::available()
253
250
if (!(*this ))
254
251
return 0 ;
255
252
256
- int len = _available (data);
257
-
258
- // if sketch checks for incoming data and there are unsent data, flush the transmit buffer
259
- if (!len)
260
- flush ();
261
- return len;
262
- }
263
-
264
- int
265
- UIPClient::_available (uip_userdata_t *u)
266
- {
267
253
int len = 0 ;
268
254
for (uint8_t i = 0 ; i < UIP_SOCKET_NUMPACKETS; i++)
269
255
{
270
- len += Enc28J60Network::blockSize (u ->packets_in [i]);
256
+ len += Enc28J60Network::blockSize (data ->packets_in [i]);
271
257
}
258
+
259
+ // if sketch checks for incoming data and there are unsent data, flush the transmit buffer
260
+ if (!len)
261
+ flush ();
272
262
return len;
273
263
}
274
264
0 commit comments