update: migrating MPTP to TCP

This commit is contained in:
ngn
2024-08-07 04:49:33 +03:00
parent 865141177a
commit 75fa38f1d7
8 changed files with 138 additions and 109 deletions

View File

@ -9,8 +9,8 @@
#include <stdlib.h>
#include <unistd.h>
bool lm_mptp_sendfile(int sock, struct sockaddr *addr, char *path, lm_mptp_transfer_callback_t callback, void *data){
if (NULL == path || NULL == addr){
bool lm_mptp_sendfile(int sock, char *path, lm_mptp_transfer_callback_t callback, void *data){
if (NULL == path){
lm_error_set(LM_ERR_ArgNULL);
return false;
}
@ -49,7 +49,7 @@ bool lm_mptp_sendfile(int sock, struct sockaddr *addr, char *path, lm_mptp_trans
}
packet.header.data_size = size;
lm_mptp_server_send(sock, &packet, addr);
lm_mptp_server_send(sock, &packet);
if(NULL != callback)
if(!callback(path, current, total, data))
@ -60,7 +60,7 @@ bool lm_mptp_sendfile(int sock, struct sockaddr *addr, char *path, lm_mptp_trans
while ((read = fread(packet.data, 1, MPTP_DATA_MAX, file)) > 0) {
packet.header.data_size = read;
if(!lm_mptp_server_send(sock, &packet, addr))
if(!lm_mptp_server_send(sock, &packet))
goto end;
current += read;
@ -68,7 +68,7 @@ bool lm_mptp_sendfile(int sock, struct sockaddr *addr, char *path, lm_mptp_trans
if(NULL != callback)
if(!callback(path, current, st.st_size, data))
goto end;
lm_mptp_init(&packet, false, MPTP_S2C_COOL, false);
}
@ -85,7 +85,7 @@ bool lm_mptp_sendfile(int sock, struct sockaddr *addr, char *path, lm_mptp_trans
end:
if(NULL != file)
fclose(file);
lm_mptp_server_send(sock, &packet, addr);
lm_mptp_server_send(sock, &packet);
return ret;
}
@ -127,7 +127,7 @@ bool lm_mptp_recvfile(int sock, char *path, lm_mptp_transfer_callback_t callback
lm_error_set(LM_ERR_RecvBadSize);
goto end;
}
if(NULL != callback)
if(!callback(path, current, total, data))
goto end;
@ -140,7 +140,7 @@ bool lm_mptp_recvfile(int sock, char *path, lm_mptp_transfer_callback_t callback
lm_error_set(LM_ERR_RecvBadCode);
goto end;
}
if(MPTP_IS_LAST(&packet))
break;