|
From: Marcus M. <ma...@je...> - 2022-01-17 12:26:55
|
Hi,
If this is the same device, multithreading does not work.
MTP/PTP devices have only 1 session over USB, accessing
it from 2 threads will only desync the protocol.
If its 2 devices it might work ... :/
Ciao, Marcus
On Sun, Jan 16, 2022 at 10:19:55PM +0000, James John wrote:
> Apologies, my code was messed up:
>
> int LIBMTP__Copy_Object(LIBMTP_mtpdevice_t *src_device,
> uint32_t const src_id,
> LIBMTP_mtpdevice_t *dest_device,
> LIBMTP_file_t *dest_file,
> LIBMTP_progressfunc_t const callback,
> void const * const data)
> {
> int fildes[2];
>
> if (pipe(fildes) == -1) {
> add_error_to_errorstack(src_device, LIBMTP_ERROR_GENERAL,
> "_LIBMTP_Copy_Object(): Could not create pipe.");
> return -1;
> }
>
> if (fork() == 0) {
> uint16_t ret = LIBMTP_Send_File_From_File_Descriptor(dest_device,
> fildes[0], dest_file, callback, data);
> close(fildes[0]);
> if (ret == -1) {
> add_ptp_error_to_errorstack(dest_device, ret, "_LIBMTP_Copy_Object():
> could not write to destination object.");
> return -1;
> }
> } else {
> uint16_t ret = LIBMTP_Get_File_To_File_Descriptor(src_device, src_id,
> fildes[1], callback, data);
> close(fildes[1]);
> if (ret == -1) {
> add_ptp_error_to_errorstack(src_device, ret, "_LIBMTP_Copy_Object():
> could not copy object.");
> return -1;
> }
> }
>
> return 0;
> }
>
> On 16/01/2022 21:48, James John wrote:
> > Hello,
> >
> > I am trying to implement object copy into this library using Linux pipes.
> >
> > Since objects cannot be copied to except downloaded to a file and read
> > back into an MTP file, which will take a lot of time. I played around
> > pipes instead by concurrently writing to pipe and reading from pipe back
> > to another MTP file. But I read that MTP is not multiplexed, so
> > operations cannot be performed concurrently.
> >
> > I have tried to implement this but I am getting some weird error.
> > Because I assumed each transaction waits for the current to finish. This
> > is what I have:
> >
> > > int LIBMTP__Copy_Object(LIBMTP_mtpdevice_t *src_device, > uint32_t
> > const src_id, > LIBMTP_mtpdevice_t *dest_device, > LIBMTP_file_t
> > *dest_file, > LIBMTP_progressfunc_t const callback, > void const * const
> > data) > { > int fildes[2]; > > if (pipe(fildes) == -1) { >
> > add_error_to_errorstack(src_device, LIBMTP_ERROR_GENERAL,
> > "_LIBMTP_Copy_Object(): Could not create pipe."); > return -1; > } > >
> > if (fork() == 0) { > uint16_t ret =
> > LIBMTP_Send_File_From_File_Descriptor(dest_device, fildes[0], dest_file,
> > callback, data); > close(fildes[0]); > if (ret == -1) { >
> > add_ptp_error_to_errorstack(dest_device, ret, "_LIBMTP_Copy_Object():
> > could not write to destination object."); > return -1; > } > } else { >
> > uint16_t ret = LIBMTP_Get_File_To_File_Descriptor(src_device, src_id,
> > fildes[1], callback, data); > close(fildes[1]); > if (ret == -1) { >
> > add_ptp_error_to_errorstack(src_device, ret, "_LIBMTP_Copy_Object():
> > could not copy object."); > return -1; > } > } > > return 0; > }
> >
> >
> > I need a help in finding why it LIBMTP_Send_File_From_File_Descriptoris
> > not working. Or it can't work because it is not multiplexed?
> >
> > A bit of a newbie here, still getting familiar with this library and the
> > whole low-level thing. It's for the passion :)
> >
> >
> > Thank you
> >
> > James
> >
> >
> >
> > _______________________________________________
> > Libmtp-discuss mailing list
> > Lib...@li...
> > https://lists.sourceforge.net/lists/listinfo/libmtp-discuss
> _______________________________________________
> Libmtp-discuss mailing list
> Lib...@li...
> https://lists.sourceforge.net/lists/listinfo/libmtp-discuss
|