update: more debug messages for send functions
This commit is contained in:
@ -27,15 +27,13 @@ bool lm_mptp_sendfile(int sock, char *path, lm_mptp_transfer_callback_t callback
|
||||
if(NULL == file){
|
||||
pdebug(__func__, "failed to open file: %s", path);
|
||||
lm_error_set(LM_ERR_SendOpenFail);
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
|
||||
goto end;
|
||||
goto end_1;
|
||||
}
|
||||
|
||||
if(fstat(fileno(file), &st)<0){
|
||||
pdebug(__func__, "failed to stat file: %s", path);
|
||||
lm_error_set(LM_ERR_SendStatFail);
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
|
||||
goto end;
|
||||
goto end_1;
|
||||
}
|
||||
|
||||
total = st.st_size;
|
||||
@ -44,32 +42,31 @@ bool lm_mptp_sendfile(int sock, char *path, lm_mptp_transfer_callback_t callback
|
||||
if((size = snprintf(packet.data, MPTP_DATA_MAX, "%lu", st.st_size)) <= 0){
|
||||
pdebug(__func__, "snprintf for stat size failed: %s", path);
|
||||
lm_error_set(LM_ERR_SendSnprintfFail);
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
|
||||
goto end;
|
||||
goto end_1;
|
||||
}
|
||||
|
||||
packet.header.data_size = size;
|
||||
lm_mptp_server_send(sock, &packet);
|
||||
|
||||
if(NULL != callback)
|
||||
if(!callback(path, current, total, data))
|
||||
goto end;
|
||||
if(NULL != callback && !callback(path, current, total, data))
|
||||
goto end_1;
|
||||
|
||||
// clear the packet
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_COOL, false);
|
||||
|
||||
while ((read = fread(packet.data, 1, MPTP_DATA_MAX, file)) > 0) {
|
||||
packet.header.data_size = read;
|
||||
pdebug(__func__, "sending the %lu/%lu of %s", current+read, total, path);
|
||||
|
||||
if(!lm_mptp_server_send(sock, &packet)){
|
||||
pdebug(__func__, "failed to send packet for %s (left at %lu/%lu): %s", path, current, total, lm_strerror());
|
||||
goto end;
|
||||
goto end_2;
|
||||
}
|
||||
|
||||
current += read;
|
||||
|
||||
if(NULL != callback)
|
||||
if(!callback(path, current, st.st_size, data))
|
||||
goto end;
|
||||
if(NULL != callback && !callback(path, current, st.st_size, data))
|
||||
goto end_1;
|
||||
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_COOL, false);
|
||||
}
|
||||
@ -77,19 +74,21 @@ bool lm_mptp_sendfile(int sock, char *path, lm_mptp_transfer_callback_t callback
|
||||
if(current != total){
|
||||
pdebug(__func__, "failed read the entire file (left at %lu/%lu): %s", current, total, path);
|
||||
lm_error_set(LM_ERR_SendReadFail);
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
|
||||
goto end;
|
||||
goto end_1;
|
||||
}
|
||||
|
||||
pdebug(__func__, "completed sending %s, sending last packet", path);
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_COOL, true);
|
||||
lm_mptp_server_send(sock, &packet);
|
||||
ret = true;
|
||||
goto end_2;
|
||||
|
||||
end:
|
||||
end_1:
|
||||
lm_mptp_init(&packet, false, MPTP_S2C_BRUH, true);
|
||||
lm_mptp_server_send(sock, &packet);
|
||||
end_2:
|
||||
if(NULL != file)
|
||||
fclose(file);
|
||||
|
||||
lm_mptp_server_send(sock, &packet);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user