Skip to content
Snippets Groups Projects
Commit a32c2a51 authored by rswindell's avatar rswindell
Browse files

Fix sendfilesocket() and recvfilesocket() for files of size >= 2G on systems

that support large file offsets (e.g. 64-bit Linux).
Considered returning ssize_t (like sendfile does), but opted for off_t. Could
be convinced otherwise.
parent 06b189d5
No related branches found
No related tags found
No related merge requests found
...@@ -170,14 +170,14 @@ socket_option_t* getSocketOptionList(void) ...@@ -170,14 +170,14 @@ socket_option_t* getSocketOptionList(void)
return(socket_options); return(socket_options);
} }
int sendfilesocket(int sock, int file, off_t *offset, off_t count) off_t sendfilesocket(int sock, int file, off_t *offset, off_t count)
{ {
char buf[1024*16]; char buf[1024*16];
off_t len; off_t len;
int rd; ssize_t rd;
int wr=0; ssize_t wr=0;
int total=0; off_t total=0;
int i; ssize_t i;
/* sendfile() on Linux may or may not work with non-blocking sockets ToDo */ /* sendfile() on Linux may or may not work with non-blocking sockets ToDo */
len=filelength(file); len=filelength(file);
...@@ -196,7 +196,7 @@ int sendfilesocket(int sock, int file, off_t *offset, off_t count) ...@@ -196,7 +196,7 @@ int sendfilesocket(int sock, int file, off_t *offset, off_t count)
SLEEP(1); SLEEP(1);
} }
if(i==0) if(i==0)
return((int)count); return(count);
#endif #endif
if(count<0) { if(count<0) {
...@@ -232,7 +232,7 @@ int sendfilesocket(int sock, int file, off_t *offset, off_t count) ...@@ -232,7 +232,7 @@ int sendfilesocket(int sock, int file, off_t *offset, off_t count)
return(total); return(total);
} }
int recvfilesocket(int sock, int file, off_t *offset, off_t count) off_t recvfilesocket(int sock, int file, off_t *offset, off_t count)
{ {
/* Writes a file from a socket - /* Writes a file from a socket -
* *
...@@ -250,8 +250,8 @@ int recvfilesocket(int sock, int file, off_t *offset, off_t count) ...@@ -250,8 +250,8 @@ int recvfilesocket(int sock, int file, off_t *offset, off_t count)
*/ */
char* buf; char* buf;
int rd; ssize_t rd;
int wr; ssize_t wr;
if(count<1) { if(count<1) {
errno=ERANGE; errno=ERANGE;
......
...@@ -228,8 +228,8 @@ extern "C" { ...@@ -228,8 +228,8 @@ extern "C" {
DLLEXPORT socket_option_t* getSocketOptionList(void); DLLEXPORT socket_option_t* getSocketOptionList(void);
DLLEXPORT int getSocketOptionByName(const char* name, int* level); DLLEXPORT int getSocketOptionByName(const char* name, int* level);
DLLEXPORT int sendfilesocket(int sock, int file, off_t* offset, off_t count); DLLEXPORT off_t sendfilesocket(int sock, int file, off_t* offset, off_t count);
DLLEXPORT int recvfilesocket(int sock, int file, off_t* offset, off_t count); DLLEXPORT off_t recvfilesocket(int sock, int file, off_t* offset, off_t count);
DLLEXPORT BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout); DLLEXPORT BOOL socket_check(SOCKET sock, BOOL* rd_p, BOOL* wr_p, DWORD timeout);
DLLEXPORT int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen DLLEXPORT int retry_bind(SOCKET s, const struct sockaddr *addr, socklen_t addrlen
,uint retries, uint wait_secs, const char* prot ,uint retries, uint wait_secs, const char* prot
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment