Opened 11 years ago

Closed 11 years ago

#3927 closed Bug (fixed)

Use of libevent2 evbuffer_write on files...

Reported by: rb07 Owned by: jordan
Priority: Normal Milestone:
Component: libtransmission Version: 2.13+
Severity: Normal Keywords:
Cc:

Description

In file libtransmission/bencode.c:1693 (rev 11734) evbuffer_write() is used to write to files...

that doesn't work, on Windows I get a "An operation was attempted on something that is not a socket", I haven't tested on Linux but the documentation of libevent2's include/event2/buffer.h says:

"Functions for buffering data for network sending or receiving."

No mention of disk files, or the generic "file descriptor" (other than the name of the parameter, but not the type of the parameter).

Attachments (1)

evbuffer_write.diff (2.1 KB) - added by jordan 11 years ago.

Download all attachments as: .zip

Change History (10)

comment:1 follow-up: Changed 11 years ago by jordan

rb07, please report this upstream to the libevent people and let's see what they think.

If all else fails we can replace the evbuffer_write() calls in libtransmission, but I think they'd be interested in fixing this for win32.

comment:2 in reply to: ↑ 1 Changed 11 years ago by rb07

Replying to jordan:

rb07, please report this upstream to the libevent people and let's see what they think.

If all else fails we can replace the evbuffer_write() calls in libtransmission, but I think they'd be interested in fixing this for win32.

You mean it works on Linux?

I went through 4 months of their list to see if anything similar was reported, found nothing.

comment:3 follow-up: Changed 11 years ago by jordan

Yes, it works fine on Linux...

comment:4 in reply to: ↑ 3 Changed 11 years ago by rb07

Replying to jordan:

Yes, it works fine on Linux...

I reported the problem https://sourceforge.net/tracker/?func=detail&atid=461322&aid=3163136&group_id=50884 and the first response says the contrary:

"> Comment By: Nick Mathewson (nickm)

Message: evbuffer_write does indeed only work on sockets. It would be neat to support more transport mechanisms in a later version of libevent, if somebody wants to write the code and can do it cleanly."

I can patch libevent, it looks easy, but... are you sure its working for you, the only signs you get is that many files are not saved: settings.json, all the .torrent files, but the downloaded files are saved fine, their torrent just disappear when its finished downloading.

If it works on Linux (and the principal maintainer of libevent is wrong -- hey, we're human, we're wrong sometimes... and if its using a simple write() on Linux, then it works with sockets and files), then this ticket is invalid, and I have no problem patching that specific function for Windows... one more compatibility wrapper on Transmission perhaps?

Last edited 11 years ago by rb07 (previous) (diff)

comment:5 Changed 11 years ago by rb07

Had a quick look at the libevent code, the relevant part is:

        if (howmuch > 0) {
#ifdef USE_SENDFILE
                struct evbuffer_chain *chain = buffer->first;
                if (chain != NULL && (chain->flags & EVBUFFER_SENDFILE))
                        n = evbuffer_write_sendfile(buffer, fd, howmuch);
                else {
#endif
#ifdef USE_IOVEC_IMPL
                n = evbuffer_write_iovec(buffer, fd, howmuch);
#elif defined(WIN32)
                /* XXX(nickm) Don't disable this code until we know if
                 * the WSARecv code above works. */
                void *p = evbuffer_pullup(buffer, howmuch);
                n = send(fd, p, howmuch, 0);
#else
                void *p = evbuffer_pullup(buffer, howmuch);
                n = write(fd, p, howmuch);
#endif
#ifdef USE_SENDFILE
                }
#endif

It obviously will work on files on Linux (but I'm not 100% positive about sendfile), but Windows is special cased to only work on sockets.

I don't think a wrapper is good for this case, for the time being I will also special case WIN32 to use the old code with plain write().

Is it OK to keep this ticket open, in case a better solution and a real patch comes up?

Changed 11 years ago by jordan

comment:6 follow-up: Changed 11 years ago by jordan

rb07, does this patch fix things on Windows?

comment:7 in reply to: ↑ 6 Changed 11 years ago by rb07

Replying to jordan:

rb07, does this patch fix things on Windows?

Yes.

comment:8 Changed 11 years ago by jordan

  • Component changed from Transmission to libtransmission
  • Milestone None Set deleted
  • Owner set to jordan
  • Status changed from new to assigned

comment:9 Changed 11 years ago by jordan

  • Resolution set to fixed
  • Status changed from assigned to closed

r11748 libtransmission/ (bencode.c peer-msgs.c utils.c):

(trunk libT) #3927 "Use of libevent2 evbuffer_write on files..." -- fixed.

evbuffer_write() is intended for sockets. It works for files on Unix, but not on Windows, so we can't portably use it on files. Instead, use evbuffer_pullup() + write().

Note: See TracTickets for help on using tickets.