Skip to content

Commit

Permalink
Fixes for outgoing data handling
Browse files Browse the repository at this point in the history
- Reset out_pos and packets_out on data allocation
- Increase total_written bytes before comparing against size to write
- Re-order write repeat cycle to ensure disconnection as required
  • Loading branch information
TMRh20 committed Mar 12, 2015
1 parent e185890 commit e852e1d
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions RF24Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,17 +150,16 @@ size_t RF24Client::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) {

size_t total_written = 0;
size_t payloadSize = rf24_min(size,UIP_TCP_MSS);

RF24EthernetClass::tick();

test2:
if( u->out_pos + payloadSize > UIP_TCP_MSS || u->hold){
RF24EthernetClass::tick();
goto test2;
}

test2:
RF24EthernetClass::tick();

if (u && !(u->state & (UIP_CLIENT_CLOSE | UIP_CLIENT_REMOTECLOSED ) )) {

if( u->out_pos + payloadSize > UIP_TCP_MSS || u->hold){
goto test2;
}

IF_RF24ETHERNET_DEBUG_CLIENT( Serial.println(); Serial.print(F("UIPClient.write: writePacket(")); Serial.print(u->packets_out); Serial.print(F(") pos: ")); Serial.print(u->out_pos); Serial.print(F(", buf[")); Serial.print(size-total_written); Serial.print(F("]: '")); Serial.write((uint8_t*)buf+total_written,payloadSize); Serial.println(F("'")); );

memcpy(u->myData+u->out_pos,buf+total_written,payloadSize);
Expand All @@ -172,8 +171,9 @@ size_t RF24Client::_write(uip_userdata_t* u, const uint8_t *buf, size_t size) {
return -1;
}

if( size != total_written ){
total_written += payloadSize;
total_written += payloadSize;

if( total_written < size ){
size_t remain = size-total_written;
payloadSize = rf24_min(remain,UIP_TCP_MSS);

Expand Down Expand Up @@ -235,7 +235,6 @@ void serialip_appcall(void) {
}
goto finish;
}
}

/*******Closed/Timed-out/Aborted**********/
// If the connection has been closed, save received but unread data.
Expand Down Expand Up @@ -342,6 +341,7 @@ void serialip_appcall(void) {
u->restartTime = u->connAbortTime = millis();
}
}
}

finish:;

Expand All @@ -356,8 +356,10 @@ uip_userdata_t *RF24Client::_allocateData() {
if (!data->state) {
data->state = sock | UIP_CLIENT_CONNECTED;
data->packets_in=0;
data->packets_out=0;
data->dataCnt = 0;
data->dataPos=0;
data->out_pos = 0;
return data;
}
}
Expand Down

0 comments on commit e852e1d

Please sign in to comment.