8 Oct 2004 (updated 8 Oct 2004 at 06:19 UTC)
»
I post today in here for a trouble I have in my devellopement in
my project Caps www.caps-project.com.
If someone has an idee and can help me thanks to write me a mail.
miconof@yahoo.fr
I do a function that will upload a file to a server.
This function "void send_file(t_thread_data *transfert)" is call in a
thread wich in first open the connection and then will upload the file.
The "send_file" function take in parameters the file descriptor of the
open fd of the new connection.
All seems to work normaly, but not. The first "buffer" is sent normaly,
but when it will go to start uploading the second buffer I obtain an
error that said : "mmap:invalid argument; mmap:illegal seek". Then
the thread exit and my upload file had received only is first 5 octets.
Here is my debug starting just when "send_file" is call:
[...]
openning [notes.txt]...
function:send_file_in
boucle fdd:13 offset:0
apres mmap
sending [notes.txt] on fd 12 ... 1/1269
[notes.txt]: sent 5 of 6340 bytes on fd 12, 5 allocated
boucle fdd:13 offset:5
mmap: Invalid argument
mmap:[Illegal seek]
after send_file
fin de main_create_download
[Thread 65541 (LWP 16794) exited]
[...]
Here is my function ("send_file" is at the bottom).
#define MY_READ_SIZE 5
int send_file_in(int fd, int ffd, char *file)
{
int part, of, mappedsize, s, t;
struct stat st;
char *file_ptr;
off_t offset;
if (gl_redcap->debug->functions)
printf("function:send_file_in\n");
offset = 0;
mappedsize = 0;
fstat(ffd, &st);
fflush(stdout);
part = 1;
of = (st.st_size / MY_READ_SIZE) +1;
offset = lseek(ffd, 0, SEEK_SET);
t = st.st_size;
while (mappedsize < t)
{
printf("boucle fdd:%d offset:%d\n", ffd, (int)offset);
if ((file_ptr = mmap(0, MY_READ_SIZE, PROT_READ, MAP_PRIVATE, ffd, offset)) == MAP_FAILED)
{
perror ("mmap");
printf("mmap:[%s]\n", strerror(errno));
return (0);
}
printf("apres mmap\n");
printf("sending [%s] on fd %d ... %d/%d\n", file, fd, part++, of);
if ((s = write(fd, file_ptr, MY_READ_SIZE)) == -1)
{
perror("send");
printf("[%s]\n", strerror(errno));
return (0);
}
if (munmap(file_ptr, MY_READ_SIZE) == -1)
{
perror ("munmap");
printf("[%s]\n", strerror(errno));
}
mappedsize += MY_READ_SIZE;
printf("[%s]: sent %d of %d bytes on fd %d, %d allocated\n",
file, s, t, fd, mappedsize);
if ((offset = lseek(ffd, MY_READ_SIZE, SEEK_CUR)) == -1)
{
perror ("lseek");
printf("lseek:[%s]\n", strerror(errno));
return (0);
}
}
offset = lseek(ffd, 0, SEEK_SET);
return(0);
}
void send_file(t_thread_data *transfert)
{
int ffd;
printf("openning [%s]...\n", transfert->info->name);
if ((ffd = open(transfert->info->name, O_RDONLY, 0)) < 0)
{
perror("open");
}
send_file_in(transfert->fd, ffd, transfert->info->name);
printf("after send_file\n");
/* if (close(ffd) == -1) */
/* { */
/* perror("close"); */
/* printf("[%s]\n", strerror(errno)); */
/* } */
}